Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Useful business date ranges

Project Description

What is DateRanger?

DateRanger is a module that helps user to find date ranges.

Installation

Currently, DateRanger is still in development.

It can be installed via GitHub and pip.

Install via GitHub

pip install git+https://github.com/spitfire-sidra/DateRanger

Install via pip

pip install --pre DateRanger

Usage

DateFrame

DateFrame helps you to calculate number of days, weeks, quarters or years in date ranges.

It also can yeild each day, week, month, quarters in date ranges.

Example code:

To calculate number of days, weeks, months, quarters or years in date ranges.

>>> from datetime import date
>>> from DateRanger.objects import DateFrame
>>>
>>> df = DateFrame(date(2014, 11, 1), date(2014, 12, 20))
>>> df.days() # There are 49 days between date(2014, 11, 1) and date(2014, 12, 20)
49
>>> df.weeks() # There are 7 weeks between date(2014, 11, 1) and date(2014, 12, 20)
7
>>> df.months()
1
>>> df.quarters()
0
>>> df.years()
0

To yield each day, week, month, quarter or years in date ranges.

>>> from datetime import date
>>> from DateRanger.objects import DateFrame
>>>
>>> df = DateFrame(date(2014, 11, 30), date(2014, 12, 2))
>>> days = [day for day in df.each_day()]
>>> days
[datetime.date(2014, 11, 30), datetime.date(2014, 12, 1), datetime.date(2014, 12, 2)]
>>>
>>> weeks = [week for week in df.each_week()] # 2 weeks
>>> weeks # 2 tuples in a list
[(datetime.date(2014, 11, 23), datetime.date(2014, 11, 29)), (datetime.date(2014, 11, 30), datetime.date(2014, 12, 6))]

Other useful methods

>>> df.days()
>>> df.weeks()
>>> df.months()
>>> df.quarters()
>>> df.years()
>>>
>>> df.each_day()
>>> df.each_week()
>>> df.each_month()
>>> df.each_quarter()
>>> df.each_years()
>>> df.get_range()

DateRanger

To use this module, first we need to set the base_date. Base_date can be any date in the past, present and future. Default base_date is the present date which is TODAY (date.today()). Based on the date given, this module helps us to find in what week, quarter or year this date falls in.

For example:

If base_date is datetime.date(2015, 1, 19), then the relative date ranges would be:

base_week
=> datetime.date(2015, 1, 18) ~ datetime.date(2015, 1, 24)
The week that contains base_date.
base_month
=> datetime.date(2015, 1, 1) ~ datetime.date(2015, 1, 31)
The month that contains base_date.
base_quarter
=> datetime.date(2015, 1, 1) ~ datetime.date(2015, 3, 31)
The quarter that contains base_date.
base_year
=> datetime.date(2015, 1, 1) ~ datetime.date(2015, 12, 31)
The year that contains base_date.
prev_week
=> datetime.date(2015, 1, 11) ~ datetime.date(2015, 1, 17)
Date range of previous week.
prev_month
=> datetime.date(2014, 12, 1) ~ datetime.date(2012, 12, 31)
Date range of previous month.
next_week
=> datetime.date(2015, 1, 25) ~ datetime.date(2015, 1, 31)
Date range of next week.
next_month
=> datetime.date(2015, 2, 1) ~ datetime.date(2015, 2, 28)
Date range of next month.

Example code:

>>> from datetime import date
>>> from DateRanger import DateRanger
>>>
>>> dr = DateRanger(base_date=date(2015, 1, 1))
>>> date_frame = dr.prev_month(2)
>>> date_frame
<DateRanger.objects.DateFrame object ...>
>>> date_frame.weeks()
5
>>> date_frame.get_range()
(datetime.date(2014, 11, 1), datetime.date(2014, 11, 30))

Other useful methods

>>> dr.set_base_date(date)
>>> dr.get_base_day()
>>> dr.base_week()
>>> dr.base_month()
>>> dr.base_quarter()
>>> dr.base_year()
>>>
>>> dr.prev_week(...)
>>> dr.next_week(...)
>>>
>>> dr.prev_month(...)
>>> dr.next_month(...)
>>>
>>> dr.prev_quarter(...)
>>> dr.next_quarter(...)
>>>
>>> dr.prev_year(...)
>>> dr.next_year(...)
>>>
>>> dr.from_date(...)
>>> dr.to_date(...)

Contribute

test:

python -m unittest discover

This command executes all test cases under the directory DateRanger/test/.

Release History

Release History

This version
History Node

0.3.0.alpha

History Node

0.2.9.dev

History Node

0.2.8.dev

History Node

0.2.6.dev

History Node

0.2.5.dev

History Node

0.2.4.dev

History Node

0.2.3.dev

History Node

0.2.2.dev

History Node

0.2.1.dev

History Node

0.2.0.dev

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
DateRanger-0.3.0.alpha.tar.gz (5.7 kB) Copy SHA256 Checksum SHA256 Source Jan 22, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting