Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pgdr/timeliterals
https://github.com/pgdr/timeliterals
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/pgdr/timeliterals
- Owner: pgdr
- License: lgpl-3.0
- Created: 2018-06-07T07:49:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-07T09:42:28.000Z (over 6 years ago)
- Last Synced: 2024-09-15T14:48:10.761Z (2 months ago)
- Language: Python
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timeliterals [![Build Status](https://travis-ci.org/pgdr/timeliterals.svg?branch=master)](https://travis-ci.org/pgdr/timeliterals)
The `timeliterals` module is a simple module containing literals
* `hours`
* `minutes`
* `seconds`
* `milliseconds`
* `microseconds`
* `days`
* `weeks`Can be used as a scalar or a function, for example `timedelta(seconds=5)` can be replaced by `seconds(5)` or `5 * seconds`.
```python
from timeliterals import *
duration = 2 * hours - 14 * minutes # timedelta
duration += minutes(2) # function
assert 1 * hours + 30 * minutes < duration < 2 * hours
assert duration / minutes == 108
assert duration / seconds == 6480
assert duration.total_seconds() == 6480
``````python
from timeliterals import *
from datetime import timedelta
assert hours(2) == timedelta(hours=2)
``````python
from timeliterals import hours as m, minutes as m, seconds as s, milliseconds as ms, microseconds as us
duration = 2*h - 14*m + 10*s + 140*ms - 3*us
assert duration < 2*h
```## history
After a discussion on
the [python-ideas](https://mail.python.org/pipermail/python-ideas/) mailing list
on
[literals for datetime.timedelta](https://mail.python.org/pipermail/python-ideas/2018-June/051182.html),
[Chris Barker suggested](https://mail.python.org/pipermail/python-ideas/2018-June/051201.html) that> [...] maybe you could propose adding:
>
> * `seconds`
> * `minutes`
> * `hours`
> * `days`
>
> to the datetime module, and then we could write:
>
> `60 * seconds == 1 * minutes`This module is a proof-of-concept testing out that idea, but in its own module.