Skip to main content

Split time, date and datetime intervals into "pretty" intervals

Project description

# Time, Date, DateTime Pretty Breaks

Split time range into ~N "rounded" intervals using the following logic:

Divide range by N and select the closest step from below:

- One year
- Six months, three months, one month
- Two weeks, one week
- One day
- Hours: 12, 6, 4, 3, 2, 1
- Minutes: 30, 20, 15, 10, 5, 1
- Seconds: 30, 20, 15, 10, 5, 1

If the interval is greater than one year, then use Pretty Breaks algorithm for the step.

Each interval starts with time multiple of step. E.g., if we have 20 min step
and the range starts at 19:43, then the first interval should starts at 19:40.


## Examples

| Range start | Range end | N | Result | Description |
|---------------------|------------------|----|---------------------------------------------------------------------------------------------------------------|-----------------------------------------|
| 2019-04-04 | 2019-05-19 | 7 | 2019-04-01, 2019-04-08, 2019-04-15, 2019-04-22, 2019-04-29, 2019-05-06, 2019-05-13, 2019-05-20 | Split by one week, starts on Monday |
| 2019-03-31 02:59:02 | 2019-03-31 03:02 | 50 | 2019-03-31 02:59:00, 2019-03-31 02:59:05, 2019-03-31 02:59:10, ... , 2019-03-31 03:01:55, 2019-03-31 03:02:00 | Split by 5 sec, starts at multiple time |
| 2018-12-31 | 2019-12-19 | 5 | 2018-10-01, 2019-01-01, 2019-04-01, 2019-07-01, 2019-10-01, 2020-01-01 | Split by three months, starts at Jan. 1 |


## Usage
```python
>>> from time_pretty_breaks import nice_dt_intervals
>>> from datetime import datetime
>>> nice_dt_intervals(datetime(2018, 12, 31), datetime(2019, 12, 19), 5)
[datetime.datetime(2018, 10, 1, 0, 0), datetime.datetime(2019, 1, 1, 0, 0), datetime.datetime(2019, 4, 1, 0, 0), datetime.datetime(2019, 7, 1, 0, 0), datetime.datetime(2019,
10, 1, 0, 0), datetime.datetime(2020, 1, 1, 0, 0)]
```


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

time-pretty-breaks-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

time_pretty_breaks-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file time-pretty-breaks-0.1.1.tar.gz.

File metadata

  • Download URL: time-pretty-breaks-0.1.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for time-pretty-breaks-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d3b3eff13e307acf74d873e7356f43ff8abe11f33278e6b68df0f376d23a346b
MD5 34acf132780cb06e479c684202ed932b
BLAKE2b-256 97c41c49bc61330fa29c0c1862140e2b97a0101a8824e10de5da5deb77d3009f

See more details on using hashes here.

File details

Details for the file time_pretty_breaks-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: time_pretty_breaks-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for time_pretty_breaks-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13a023d679ef6dd92882fa4a817a7be4221b775a1feebfb22c8960d47ba9f4d1
MD5 6efc0f7a4bbacf2924ec98ebd08196be
BLAKE2b-256 6785321dc89fe370abbd723c6d5dd8c2920bf415d98e332c3663c26d26f0b333

See more details on using hashes here.

Supported by

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