Skip to main content

Useful business date ranges

Project description

What is DateRanger?

https://travis-ci.org/spitfire-sidra/DateRanger.svg?branch=0.2.7.dev

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

DateRange

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

Example Code:

from datetime import date
from DateRanger import DateRanger
from DateRanger.objects import DateRange

r = DateRange(date(2014, 11, 1), date(2014, 12, 1))
print r.months()
print r.days()

Other useful methods

r.days()
r.weeks()
r.months()
r.quarters()
r.years()

r.each_day()
r.each_week()
r.each_month()
r.each_quarter()
r.each_years()

r.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, 25) The week that contains base_date.

base_month => datetime.date(2015, 1, 1) ~ datetime.date(2015, 2, 1) The month that contains base_date.

base_quarter => datetime.date(2015, 1, 1) ~ datetime.date(2015, 4, 1) The quarter that contains base_date.

base_year => datetime.date(2015, 1, 1) ~ datetime.date(2016, 1, 1) The year that contains base_date.

prev_week => datetime.date(2015, 1, 11) ~ datetime.date(2015, 1, 18) Date range of previous week.

prev_month => datetime.date(2014, 12, 1) ~ datetime.date(2015, 1, 1) Date range of previous month.

next_week => datetime.date(2015, 1, 25) ~ datetime.date(2015, 2,1) Date range of next week.

next_month => datetime.date(2015, 2, 1) ~ datetime.date(2015, 3, 1) Date range of next month.

Example Code:

from datetime import date
from DateRanger import DateRanger
from DateRanger.objects import DateRange

dr = DateRanger()
test_range = dr.prev_month(2)
print test_range.get_range()

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(2)
dr.next_week(2)

dr.prev_month(2)
dr.next_month(2)

dr.prev_quarter(2)
dr.next_quarter(2)

dr.prev_year(2)
dr.next_year(2)

dr.from_date(date)
dr.to_date(date)

Contribute

test:

python -m unittest discover

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

Project details


Download files

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

Source Distribution

DateRanger-0.2.8.dev.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file DateRanger-0.2.8.dev.tar.gz.

File metadata

File hashes

Hashes for DateRanger-0.2.8.dev.tar.gz
Algorithm Hash digest
SHA256 a248440a8fdcc528617fa72891b0de134fe3d428f250670d8b45785218e50c06
MD5 d9a3a3aed18ba148f4c20172212139e2
BLAKE2b-256 14ba303b9100856a6e255aaf3d2481e4787fd05c77d02d04304b296bb89d57d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page