datetime_periods
This module aims to help you create time periods from timestamps.
Pass in a datetime.datetime() object and a period name and it’ll return the beginning and end of that period.
Documentation available on Read the Docs.
Installation:
You can install from PyPi!
pip install datetime_periods
period usage
Pass in a datetime.datetime() object and a period name and it’ll return the beginning and end of that period.
>>> from datetime_periods import period
>>> period(datetime(2012, 4, 2, second=12), 'minute')
[datetime(2012, 4, 2), datetime(2012, 4, 2, 0, 0, 59)]
>>> period(datetime(2012, 4, 2), 'hour')
[datetime(2012, 4, 2, 0), datetime(2012, 4, 2, 0, 59, 59)]
>>> period(datetime(2012, 4, 2), 'day')
[datetime(2012, 4, 2), datetime(2012, 4, 2, 23, 59, 59)]
>>> period(datetime(2012, 4, 2), 'week')
[datetime(2012, 4, 2), datetime(2012, 4, 8, 23, 59, 59)]
>>> period(datetime(2012, 4, 15), 'month')
[datetime(2012, 4, 1), datetime(2012, 4, 30, 23, 59, 59)]
>>> period(datetime(2012, 4, 2), 'quarter')
[datetime(2012, 4, 1), datetime(2012, 6, 30, 23, 59, 59)]
>>> period(datetime(2012, 9, 1), 'half_year')
[datetime(2012, 7, 1), datetime(2012, 12, 31, 23, 59, 59)]
>>> period(datetime(2012, 7, 1), 'year')
[datetime(2012, 1, 1), datetime(2012, 12, 31, 23, 59, 59)]
TimeRange usage
The TimeRange class takes two times, start and stop, and creates datetime objects from them that is smart about when a date should roll over to the following day.
This class can also act like a 2 length list where index 0=start, 1=stop time. This to allow the class to be used for argument expansion and as an iterator.
>>> from datetime_periods import TimeRange
>>> tr = TimeRange('17:00', '23:00', '2013-12-25')
>>> tr.start
datetime(2013, 12, 25, 17)
>>> tr.stop
datetime(2013, 12, 25, 23)
>>> tr = TimeRange('17:00', '04:00', '2013-12-25')
>>> tr.start
datetime(2013, 12, 25, 17)
>>> tr.stop
datetime(2013, 12, 26, 4)
>>> tr[0] == tr.start
True
>>> tr[1] == tr.stop
True
Sugar
The sugar module has sugar functions for all variants available.
Sugar functions for entire period:
period_second
period_minute
period_hour
period_day
period_week
period_month
period_quarter
period_half_year
period_year
Sugar functions for beginning of period:
period_beginning_second
period_beginning_minute
period_beginning_hour
period_beginning_day
period_beginning_week
period_beginning_month
period_beginning_quarter
period_beginning_half_year
period_beginning_year
Sugar functions for end of period:
period_end_second
period_end_minute
period_end_hour
period_end_day
period_end_week
period_end_month
period_end_quarter
period_end_half_year
period_end_year
Metadata
Release files for datetime_periods 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datetime_periods-1.1.1.tar.gz | 5.0 kB | Without provenance | Details for datetime_periods-1.1.1.tar.gz |
Release files / datetime_periods-1.1.1.tar.gz
| Download URL | datetime_periods-1.1.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e22beb8ea176f398cddd5f18520a907ff85cb161690f81c8c9d7839fcfbdf0e
|
|
BLAKE2b-256 checksum How to use checksums |
a32e873f967d231b74a0a2b88b4f0fd1d1e8d294e16c44790ccb7de412f75528
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for datetime_periods 1.1.1
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.