https://github.com/shahriyardx/timetils
A easy to use time util library for python
https://github.com/shahriyardx/timetils
Last synced: 3 months 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 (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T11:14:51.000Z (almost 5 years ago)
- Last Synced: 2025-04-04T07:46:59.086Z (3 months 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)
```