Convert data from str to datetime or datetime to str.
Project description
Json-Datetime-util
Convert data from str to datetime or datetime to str. Can also get all dict or list values to convert all to requested type.
How to Install
pip install date-reclass
How to Use
Json-datetime-util will allow the user to simply convert entire lists or dicts of data.
All datetimes inside of the list or dict will be converted from str to datetime or vice-versa.
When you have a str and need a datetime:
from date_reclass import cast
date = '17/05/2020'
result = cast(date, '%d/%m/%Y').todatetime()
>>> '2020-05-17 00:00:00'
If you have a list or dict the same code can be used:
# dict example
from date_reclass import cast
date = {'date1':'17/05/2020','date2':'17/05/2021'}
result = cast(date, '%d/%m/%Y').todatetime()
>>> {'date1': datetime.datetime(2020, 5, 17, 0, 0), 'date2':{'date2': datetime.datetime(2021, 5, 17, 0, 0)}
# list example
from date_reclass import cast
date = ['17/05/2020','17/05/2021']
result = cast(date, '%d/%m/%Y').todatetime()
>>> [datetime.datetime(2020, 5, 17, 0, 0), datetime.datetime(2021, 5, 17, 0, 0)]
When you have a datetime and need a string:
from date_reclass import cast
import datetime
date = datetime.datetime(2020, 5, 17)
result = cast(date).tostr()
>>> '2020-05-17 00:00:00'
For list or dict:
# dict
from date_reclass import cast
import datetime
date = {'date1':'17/05/2020','date2':'17/05/2021'}
result = cast(date, '%d/%m/%Y').todatetime()
>>> {'date1': datetime.datetime(2020, 5, 17, 0, 0), 'date2': datetime(2021, 5, 17, 0, 0)}
# list
from date_reclass import cast
import datetime
date = ['17/05/2020', '17/05/2021']
result = cast(date, '%d/%m/%Y').todatetime()
>>> [datetime.datetime(2020, 5, 17, 0, 0), datetime(2021, 5, 17, 0, 0)]
Run Tests
Run tests by running
python3 -m unittest app/tests/*/**.py
You can also check coverage and generate a coverage report
coverage run -m unittest tests/*.py && coverage report
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file date-reclass-0.0.4.tar.gz
.
File metadata
- Download URL: date-reclass-0.0.4.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7528abbe2dc7d2a223ac8678cad454b70209b02b3f1c5222a532406a1b6a89dc |
|
MD5 | 1a60ea3c22ea24caa3579aadd6357a7d |
|
BLAKE2b-256 | d351a26f847bb588248976248a5d0562be0838d991a4bda64dc326bb41571e50 |
File details
Details for the file date_reclass-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: date_reclass-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ade83a756c6e4d212db9edf4581df38f384abf7fcaef853a78025c025efd3ba5 |
|
MD5 | 115cd06c8086fd1eb88b8e7319aa1d38 |
|
BLAKE2b-256 | e145a0456b2b4dd5e2d9d17d35cf8b5e439e4f642e199c77e751fdd8adc5f51b |