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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file date-reclass-0.0.3.tar.gz.

File metadata

  • Download URL: date-reclass-0.0.3.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

Hashes for date-reclass-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6fcd73db7d75c00a1891f9df54798d4d9ba894c71e4e0a1bcc7f7641aee992f6
MD5 fbe68501cd4def9ec3c38dd52f4b3914
BLAKE2b-256 0cb03424f312d16799d69095e0fda96c3c0d16de6f0834a7c3110f89f640f185

See more details on using hashes here.

File details

Details for the file date_reclass-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: date_reclass-0.0.3-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

Hashes for date_reclass-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f6898ea5a065b12550ef8f1a248a7614b15a893ec60d4009fa16c489d6b0edc7
MD5 52789219d96f2a1a39432aeeb02a1262
BLAKE2b-256 cef769384bb19bac10d972ae631240ea3a47773612c40297cbea8950cbb04da0

See more details on using hashes here.

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