Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

date-reclass-0.0.3.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

date_reclass-0.0.3-py3-none-any.whl (8.4 kB view hashes)

Uploaded Python 3

Supported by

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