Skip to main content

Robust date-time formatter with implicit time-zone conversion, wraps datetime and pytz

Project description

date-time-handler

Robust date-time formatter with implicit time-zone conversion, wraps datetime and pytz

Out of the box solution for quick and easy proto-type building

  • Uses Python3 standard library time and datetime
  • Requires pytz and dateutil to be installed:
    $ pip3 install pytz
    $ pip3 install python-dateutil
  • date_time_handler package contains class DateTimeHandler with methods that convert timestamp format and time-zone
  • By default, DateTimeHandler performs timezone-naive timestamp format conversion (handy for quick display formatting)
  • For implicit timezone conversion:
    • set destination tz with kwarg time_zone = 'region/local' at instantiation
    • then kwarg start_tz = 'region/local' when converting timestamp format
  • All methods take 'timestamp' in any format: int/float, tuple/struct, formatted_string, and even datetime obj

examples

for time-zone agnostic format conversion

>>> dt_format = DateTimeHandler(date_format = "%Y/%m/%d", clock_format = "%H:%M:%S")
>>> timestring = dt_format.timestring(timestamp)
>>> timetuple = dt_format.timetuple(timestamp)
>>> datestamp = dt_format.datestamp(timestamp)

for time-zone conversion, set destination tz at instantiation

>>> dt_format = DateTimeHandler(time_zone = 'US/Pacific')

    # specify starting timezone when converting timestamp #
>>> local_timestring = dt_format.timestring(utc_timestamp, start_tz = 'UTC')
>>> local_timetuple = dt_format.timetuple(utc_timestamp, start_tz = 'UTC')

so-called 'date' methods return the given timestamp's date @ 00:00:00

>>> local_datestring = dt_format.datestring(utc_timestamp, start_tz = 'UTC')
>>> local_datetuple = dt_format.datetuple(utc_timestamp, start_tz = 'UTC')

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_time_handler-0.0.0.21.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

date_time_handler-0.0.0.21-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file date_time_handler-0.0.0.21.tar.gz.

File metadata

  • Download URL: date_time_handler-0.0.0.21.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.4

File hashes

Hashes for date_time_handler-0.0.0.21.tar.gz
Algorithm Hash digest
SHA256 1ab6376025b364afc340370fa65a6c85e26bbbab014f29990a3c93b80c4bcee0
MD5 c14be5c97f093cf3e0cb5e3f011b30f8
BLAKE2b-256 cb5a41f4109287c6120b7c1de0e1ca3c83c1c157637a6bcc98acd489ad99f56b

See more details on using hashes here.

File details

Details for the file date_time_handler-0.0.0.21-py3-none-any.whl.

File metadata

File hashes

Hashes for date_time_handler-0.0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 344c0cde4dd4b347d3b435f4d0eb5d83d0673d55184821df0ebe506d318a0d2c
MD5 859ad9d00b30c5b16fe8fc4f396b48de
BLAKE2b-256 b40d223467b415baa4771b1c4560f8d96dbc287f77b32548be35b61f00c212ad

See more details on using hashes here.

Supported by

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