Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shahriyardx/timetils
A easy to use time util library for python
https://github.com/shahriyardx/timetils
Last synced: 9 days ago
JSON representation
A easy to use time util library for python
- Host: GitHub
- URL: https://github.com/shahriyardx/timetils
- Owner: shahriyardx
- License: mit
- Created: 2020-07-12T14:34:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T11:14:51.000Z (about 4 years ago)
- Last Synced: 2024-10-31T14:53:19.779Z (14 days ago)
- Language: Python
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Timetils
A easy to use time util library for python### Installation
`python3 -m pip install timetils`### Usage
> For version 1.1.1
```python
import datetime
import timetilsformatter = timetils.Formatter()
# Make a timedelta object anyhow.
delta = datetime.timedelta(days=45, seconds=288)data = formatter.natural_delta(delta, as_dict=False)
# if you set as_dict = True data will be a dict of years, months, days, hours, minutes and seconds
# Output when as_dict = False -> '1 Months 15 Days 4 Minutes and 48 Seconds'
# Output when as_dict = True -> {'years': 0, 'months': 1, 'days': 15, 'hours': 0, 'minutes': 4, 'seconds': 48}
```> For version >= 2.0.0
```python
import datetime
import timetilsformatter = timetils.Formatter()
# Make a timedelta object anyhow.
delta = datetime.timedelta(days=45, seconds=288)data = formatter.natural_delta(delta, as_string=True)
# if you set as_string = False data will be a BetterDelta class
# Output when as_string = True -> '1 Months 15 Days 4 Minutes and 48 Seconds'
# Output when as_dict = False ->
```#### Available methods
```python
natural_delta(timedelta, as_string)
natural_date(date, as_string)
natural_time(time, as_string, format)
natural_datetime(datetime, as_string)
```