Skip to main content

TimeStam eXtensions for Python

Project description

tsx

Time Stamp eXtensions for Python

This library was created as a response to the known Python datetime standard library flaw that violates ISO 8601. ( Example )

Under the hood, it uses external dateparser library that's fully compatible with ISO 8601, and it simplifies working with date & time stamps.

It also handles properly the Daylight Saving Time (summer time).

Installation

pip pinstall tsx

Usage:

The library is pretty simple, its central class is TS, which inhertis Python builtin float, so every timestamp in fact is a float representing number of seconds since Epoch.

The TSMsec is the same TS with only difference that it's constructor by default expects msec precision, i.e. number of msecs since epoch, but internally it will store the same float as number of seconds since Epoch.

TS(ts: Union[int, float, str], prec: Literal["s", "ms"] = "s")`

TSMsec(ts: Union[int, float, str], prec: Literal["s", "ms"] = "ms")
  • prec - is precision of the ts argument.
    • If prec=="s" - the ts argument will be interpreted as nr of seconds since epoch,
    • If prec=="ms" - the ts argument will be interpreted as nr of milliseconds since epoch

Example:

ts = TS(ts="1519855200.123856", prec="s")

ts==1519855200.123856
ts.as_iso == '2018-02-28T22:00:00.123856Z'
ts.as_iso_tz(pytz.timezone("Europe/Bucharest"))=='2018-03-01T00:00:00.123856+02:00'

TS("2018-02-28T22:00:00.123Z")
TS("2018-02-28T22:00:00.123")

TS("2018-02-28T22:00:00.123+00:00")
ts = TS.now()

ts.as_sec == 1234567890.123
ts.as_ms == 1234567890123
ts.as_file_date == '20090213'
ts.as_file_ts == '20090213-233130'

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tsx-0.0.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tsx-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/None CPython/3.6.13

File hashes

Hashes for tsx-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44da04e86c034a0eb3152c3ac332c4389f2cc36ca53fda29dae5d7915e6df01d
MD5 7fcd81eccae2d52ae7cb6cd5a7fe5f6f
BLAKE2b-256 c0698a9e1ab17bceddab243f71fb3a2346a1a7034e3bd93f094337dd227fded7

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