Skip to main content

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', ... )

# pass start and end dates as datetime objects
start_dt = datetime(2023, 3, 8, 12, 0, 0)
end_dt = datetime(2023, 3, 9, 12, 0, 0)
kronos = Kronos(start_dt, end_dt)
kronos.format_start('%Y-%m-%d %H:%M:%S')
# 2023-03-08 12:00:00
kronos.format_end('%Y-%m-%d %H:%M:%S')
# 2023-03-09 12:00:00

# bisect a daterange
kronos = Kronos('2023-03-01', '2023-03-09')
k1, k2 = kronos.splice('2023-03-04')
print(k1)
# Kronos(start_date='2023-03-01', end_date='2023-03-04', ...) 
print(k2)
# Kronos(start_date='2023-03-04', end_date='2023-03-09', ...)

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.

Metadata

Release files for kronos-daterange 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kronos-daterange 0.0.14
File Size Uploaded Provenance
kronos-daterange-0.0.14.tar.gz 12.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kronos-daterange 0.0.14
File Interpreter ABI Platform
kronos_daterange-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / kronos-daterange-0.0.14.tar.gz

Download URL kronos-daterange-0.0.14.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
539f7563eab6a930bd4506ecc0c64f487911d24af192a7c085f18bea45bbe6dc
BLAKE2b-256 checksum
How to use checksums
a12ebdd3ac156c235863c223bfbd0f96b3de1b32f0b12db043be7f4bae9bdbd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.15 Darwin/22.1.0

Release files / kronos_daterange-0.0.14-py3-none-any.whl

Download URL kronos_daterange-0.0.14-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fff921864c93b4f8f0372fb1c9d61f0ac5529b3c8d71cbb0867a40af7413ea0
BLAKE2b-256 checksum
How to use checksums
1a4cd932fcde8169cd6fd6a25c95935db2a38e22fb57545692b0beffd5393c4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.15 Darwin/22.1.0

Security for kronos-daterange 0.0.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page