Skip to main content

More Time! Time as a vector space, the way it was meant to be.

Project description

More Times!

Assume time forms an algebraic field over GMT. Finally!

PyPI Latest Release Build Status Coverage Status Downloads

Details

Date is a simplified class for time manipulation. This library is intended for personal and business applications where assuming every solar day has 24 * 60 * 60 seconds is considered accurate. See GMT vs UTC below.

Assumptions

  • All time is in GMT - Timezone math is left to be resolved at the human endpoints: Machines should only be dealing with one type of time; without holes, without overlap, and with minimal context.
  • Single time type - There is no distinction between dates, datetime and times; all measurements in the time dimension are handled by one type called Date. This is important for treating time as a vector space.
  • Standard range comparision - All time range comparisons have been standardized to min <= value < max. The minimum is inclusive (<=), and the maximum is exclusive (<).

Date class

The Date() method will convert unix timestamps, millisecond timestamps, various string formats and simple time formulas to create a GMT time

Date.now()

Return Date instance with millisecond resolution (in GMT).

Date.eod()

Return end-of-day: Smallest Date which is greater than all time points in today. Think of it as tomorrow. Same as now().ceiling(DAY)

Date.today()

The beginning of today. Same as now().floor(DAY)

Date.range(min, max, interval)

Return an explicit list of Dates starting with min, each interval more than the last, but now including max. Used in defining partitions in time domains.

floor(duration=None)

This method is usually used to perform date comparisons at the given resolution (aka duration). Round down to the nearest whole duration. duration as assumed to be DAY if not provided.

format(format="%Y-%m-%d %H:%M:%S")

Just like strftime

milli

Number of milliseconds since epoch

unix

Number of seconds since epoch

add(duration)

Add a duration to the time to get a new Date instance. The self is not modified.

addDay()

Convenience method for self.add(DAY)

Duration class

Represents the difference between two Dates. There are two scales:

  • DAY scale - includes seconds, minutes, hours, days and weeks.
  • YEAR scale - includes months, quarters, years, and centuries.

floor(interval=None)

Round down to nearest interval size.

seconds

return total number of seconds (including partial) in this duration (estimate given for YEAR scale)

total_seconds()

Same as the seconds property

round(interval, decimal=0)

Return number of given interval rounded to given decimal places

format(interval, decimal=0)

Return a string representing self using given interval and decimal rounding

Time as an algebraic field

The Date and Duration objects are the point and vectors in a one dimensional vector space. As such, the + and - operators are allowed. Comparisons with (>, >=, <=, <) are also supported.

GMT vs UTC

The solar day is he most popular timekeeping unit. This library chose GMT (UT1) for its base clock because of its consistent seconds in a solar day. UTC suffers from inconsistent leap seconds and makes time-math difficult, even while forcing us to make pedantic conclusions like some minutes do not have 60 seconds. Lucky for us Python's implementation of UTC (datetime.utcnow()) is wrong, and implements GMT: Which is what we use.

Error Analysis

Assuming we need a generous leap second each 6 months (the past decade saw only 4 leap seconds), then GMT deviates from UTC by up to 1 seconds over 181 days (December to June, 15,638,400 seconds) which is an error rate error = 1/15,638,400 = 0.000006395%. If we want to call the error "noise", we have a 70dB signal/noise ratio. All applications that can tolerate this level of error should use GMT as their time basis.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

mo-times-5.547.24058.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

mo_times-5.547.24058-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file mo-times-5.547.24058.tar.gz.

File metadata

  • Download URL: mo-times-5.547.24058.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.6

File hashes

Hashes for mo-times-5.547.24058.tar.gz
Algorithm Hash digest
SHA256 270769f7948f643276b7795143db5b7248ccc701b20e63588429baed2780dc01
MD5 e7030114389257432874c0dd563efdd3
BLAKE2b-256 fcbc881a6785e8591c03d023fa1577250ddbc020ac2ecb158f680d46a3869016

See more details on using hashes here.

File details

Details for the file mo_times-5.547.24058-py3-none-any.whl.

File metadata

  • Download URL: mo_times-5.547.24058-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.6

File hashes

Hashes for mo_times-5.547.24058-py3-none-any.whl
Algorithm Hash digest
SHA256 0e132c7a23a20a1b8708d290bdf56b6f9c66e4170e7b43aaebbc32ae94074823
MD5 349d40e80e73adcd03e6fe6139d09943
BLAKE2b-256 1d878b24187980c2700ae06e133daa6437c4cf181dc00f7bcae93989dc594752

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