Skip to main content

time-int

Integer subclass for number of seconds since the epoch in UTC

The Idea

UNIX has a venerable tradition of representing time as seconds since the start of 1970. This has its limitations, but it is sometimes desirably simple. This package sub-classes int to give a little handy functionality to this simple approach.

More robust resources

For uses beyond this rather specific functionality, the standard python distribution includes powerful time related packages such as datetime, time and calendar. Also other packages installable time related packages such as pytz and timeutil.

Important Limitations of TimeInt objects.

  • Values are always treated as relative to UTC.
  • Values are rounded down to the second.
  • Supported range starts at Jan 1, 1970 (UTC): 0
  • Supported range ends at Jan 1, 3000 (UTC): 32,503,680,000
  • The supported range might need to be different on other systems, have only tested on windows.
  • This package is not far enough along in development to be safe from errors or major feature changes.

Quick Example

from time_int import TimeInt

start_time = TimeInt.utcnow()
some_slow_operation()
end_time = TimeInt.utcnow()

print(f"Operation started at {start_time.get_pretty()}")
print(f"Operation ended  at  {end_time.get_pretty()}")
print(f"Operation took {end_time - start_time} seconds")

The trunc_<unit> Methods

Some trunc_<unit> methods are available for rounding down times to the year, month, week, day, hour, or minute. One can also round down to units based on some number of these units. For example to round a time int to the fifteen minute period it falls in:

from time_int import TimeInt
from datetime import datetime

dt = datetime(year=2001, month=5, day=16, hour=10, minute=53)
time = TimeInt.from_datetime(dt)

quarter_hour_time = time.trunc_minute(num=15)

The quater_hour_time will round down 10:53am to 10:45am. Note that the 15 minute periods rounded to are based on when the hour started, as one might intuitively suspect. For numbers of hours the trunc_day method is based on start of the day. Such that if you round down to units of 6 hours, you will round down to ether midnight, 6am, noon, or 6pm. Weeks do not have this grouping feature because there is no obvious place I can see to start counting groups of weeks from. For days they are based on start of month. For months on start of year, and for years on a fictional year 0 (which technically does not exist). Sometimes there will be oddly sized groups with less than the number of units, for example if you choose to round to units of 7 hours, you will get either midnight, 7am, 2pm, or 9pm. With 9pm to midnight only being the left over 3 hours. When the time unit is groups of 2 or more days, this is bound to happen due to the way months vary from 28 to 31 days.

trunc method

There is a generic trunc method that wraps all the trunc_<unit> methods so one can specify the basic time unit as an argument. For example to find the start of the start of the current quarter year in UTC:

from time_int import TimeInt, TimeTruncUnit

current_time = TimeInt.utcnow()
start_of_quarter = current_time.trunc(TimeTruncUnit.MONTH, num=3)

Of course in this example one would probably just use trunc_month(num=3) which does the same thing.

Metadata

Release files for time-int 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for time-int 0.0.9
File Size Uploaded Provenance Actions
time-int-0.0.9.tar.gz 5.8 kB Without provenance Details for time-int-0.0.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for time-int 0.0.9
File Interpreter ABI Platform Actions
time_int-0.0.9-py3-none-any.whl Python 3 none any Details for time_int-0.0.9-py3-none-any.whl

Total release size: 11.3 kB

Release files / time-int-0.0.9.tar.gz

Download URL time-int-0.0.9.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c439bab4b7a01f8af1fb99ad622f2a6cdfe0dc1969c3eda63b2e2574245b13a7
BLAKE2b-256 checksum
How to use checksums
cebf0a9571e543ae5edbbc34a361a423d487fee16a8f48470d75efbf8b6fa22a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.8.2 Windows/10

Release files / time_int-0.0.9-py3-none-any.whl

Download URL time_int-0.0.9-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b30f3c0ece12f3b8204b281d8f85844934a1c8dacb0e594b33365cd7ac0fe13
BLAKE2b-256 checksum
How to use checksums
8d681fcbbf7dda902242d8eeda0db385831e29e73cabf67101007deeb713cede
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.8.2 Windows/10

Security for time-int 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page