Skip to main content

A small helper package for working with time intervals.

This package provides a single class called Seconds (a subclass of int) that represents a time interval in seconds. It also provides a number of constants that represent common time intervals, such as ONE_SECOND and ONE_DAY.

The intended use of this package is to provide a more readable alternative to using raw numbers for time intervals. For example, instead of writing time.sleep(86400) to sleep for one day, you can write time.sleep(ONE_DAY). This makes the code more readable and easier to understand.

The Seconds class also provides attributes for accessing the interval in other units of time, such as minutes and hours.

Shoot me an email if you use it and find it useful, or if you have any suggestions!

Usage

>>> from times import THREE_MINUTES
>>> import time
>>> time.sleep(THREE_MINUTES)
>>> import times
>>> times.ONE_DAY
86400
>>> times.THREE_HOURS.years
0.00034223866072692215
>>> times.FIVE_MONTHS.minutes
219145.25
from times import Seconds, TEN_YEARS
>>> century = Seconds(TEN_YEARS * 10)
>>> century
3155692500
>>> century.hours
876581.25

Installation

pip install pytimes

Reference

The Seconds class is a subclass of int that represents a time interval in seconds. It usually won't be instantiated directly, but rather used via the constants defined in this module. It offers the following attributes:

  • seconds: The interval in seconds.
  • minutes: The interval in minutes.
  • hours: The interval in hours.
  • days: The interval in days.
  • weeks: The interval in weeks.
  • months: The interval in months. A month is defined as 1/12 of a year.
  • years: The interval in years. A year is defined as 365.242196 days.

The following constants are defined in this module:

  • ONE_SECOND
  • ONE_MINUTE
  • ONE_HOUR
  • ONE_DAY
  • ONE_WEEK
  • ONE_MONTH
  • ONE_YEAR
  • ... And many more, in variations like TWO_DAYS, THREE_WEEKS, FOUR_MONTHS, etc.

Requirements

Python 3.6+

License

MIT

Changelog

1.12.0

Added shorthand methods for all the time fractions, like times.ONE_DAY.m for times.ONE_DAY.minutes.

1.11.0

Now fully typed and compatible with mypy.

Release files for pytimes 1.13.0

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

Source distribution (sdist)

Source distribution for pytimes 1.13.0
File Size Uploaded
pytimes-1.13.0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytimes 1.13.0
File Interpreter ABI Platform
pytimes-1.13.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / pytimes-1.13.0.tar.gz

Download URL pytimes-1.13.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
28a592576059ac77d18ed2fc9f593181b2e0dcd71b3ce3e6610941735b3bc368
BLAKE2b-256 checksum
How to use checksums
04c5f72bcbb8a067fe0bab68bc97fba4566a81a5241306eaa7a2eab0d1085101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.7 Windows/10

Release files / pytimes-1.13.0-py3-none-any.whl

Download URL pytimes-1.13.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05b2b8cf08dc69f33525f2c457204cc7b87c381470608f74290c3b5c112da74b
BLAKE2b-256 checksum
How to use checksums
b5a574c4919b74e1915d1c60a0c1d8b18eaeb838495af97c18dbb77979483a8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.7 Windows/10

Release history Release notifications | RSS feed

This release

1.13.0 This release

2 release files

1.12.0

2 release files

1.11.3

2 release files

1.11.2

2 release files

1.11.1

2 release files

1.11.0

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

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