Skip to main content

Kronos makes date ranges easier.

Project description

Kronos

PyPI - Version PyPI - Python Version Tests Codecov Read the Docs PyPI - License

Black pre-commit

Kronos makes dateranges easier.

Quickstart

Install from pip:

pip install kronos-daterange

Import & basic init:

from kronos import Kronos

kronos = Kronos(start_date='2022-01-01', end_date='2022-01-31')

Feature Demo

# import
from kronos import Kronos

# init --> defaults to range of <yesterday, today> unless otherwise specified by `KRONOS_DATERANGE` environment variable
kronos = Kronos()

# manually set dates
kronos = Kronos(start_date='2022-10-17', end_date='2022-10-23')

# set timezone
kronos = Kronos(timezone='America/New_York') 

# specify date format
kronos = Kronos(start_date='10/20/2022', end_date='10/31/2022', date_format='%m/%d/%Y')

# access start, end dates
kronos = Kronos()
kronos.start_date
# 2022-10-19
kronos.end_date
# 2022-10-20

# `date_format` carries over to properties:
kronos = Kronos(date_format='%m/%d/%Y')
kronos.start_date
# 10/19/2022
kronos.end_date
# 10/20/2022

# format start and end date with new format
kronos.format_start('%Y-%m-%d %H:%M:%S')
# 2022-10-20 00:00:00
kronos.format_end('%Y-%m-%d %H:%M:%S')
# 2022-10-21 23:59:59

# get the current date in specified timezone
kronos = Kronos('America/Los_Angeles')
kronos.current_date
# 2022-10-20
kronos = Kronos('America/Los_Angeles', date_format='%m/%d/%Y')
kronos.current_date
# 10/20/2022

# overwrite your object's timezone without altering the time
kronos = Kronos(timezone='UTC')
kronos.change_timezone(tz='America/New_York')

# relative shift forward/back
kronos = Kronos()
kronos.shift_range(weeks=-1)  # pipes kwargs into timedelta
# Kronos(start_date='2022-10-12', end_date='2022-10-13', ... )

Defaults/Environment Variables

Kronos is prepared to accept the following environment variables:

  • KRONOS_TIMEZONE, which defaults to UTC if not set. Can often be overridden at method-levels for one-off timezone conversions.
  • KRONOS_FORMAT, the strptime date format string for your dates.
  • KRONOS_DATERANGE (see below)

Note that both KRONOS_TIMEZONE and KRONOS_FORMAT can be set during init as timezone= and date_format= arguments, respectively.

KRONOS_TIMEZONE:

Can be any valid timezone name (find them at pytz.all_timezones)

KRONOS_DATERANGE:

List of accepted values:

  • LATEST: start/end dates of yesterady/today
  • YESTERDAY_TODAY: same as LATEST
  • LAST_MONTH: previous calendar month
  • MTD: month-to-date
  • LAST_{X}_DAYS: relative range where end_date is today, start date is set X days behind.
  • THIS_WEEK__{X}: week-to-date starting on previous day of week specified by X. Valid values for X: SUN, MON, TUES, WED, THURS, FRI, SAT

Credits

This package was created with Cookiecutter and the fedejaure/cookiecutter-modern-pypackage project template.

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

kronos-daterange-0.0.7.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

kronos_daterange-0.0.7-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file kronos-daterange-0.0.7.tar.gz.

File metadata

  • Download URL: kronos-daterange-0.0.7.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.7 Darwin/21.5.0

File hashes

Hashes for kronos-daterange-0.0.7.tar.gz
Algorithm Hash digest
SHA256 a8e41d3fba5dc8957edc967effa3d7af1ef25fd7cc5a87238bc0c2bfd7c6abdc
MD5 e881a25b3ea73070cff3d0d215f448d0
BLAKE2b-256 bedd0da1736f590b7ad04be85f0038b173eba6eb4bf6b8b4c2309e9e1ef8d95b

See more details on using hashes here.

File details

Details for the file kronos_daterange-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for kronos_daterange-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 58cc3eca1309e842f78a64e816d033b32720b3d8b880a72c283fe75e58570850
MD5 616b3643733fe5a8f958133900d91e9c
BLAKE2b-256 28b376bda675bd9d524388f3a46a6cd49d7f0f9068cb45ffd01a97e6bdaf9466

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