mo-times 1.0.17039__zip
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mo-times-1.0.17039/PKG-INFO +171 -0
- mo-times-1.0.17039/README.txt +157 -0
- mo-times-1.0.17039/mo_times/__init__.py +17 -0
- mo-times-1.0.17039/mo_times/dates.py +489 -0
- mo-times-1.0.17039/mo_times/durations.py +422 -0
- mo-times-1.0.17039/mo_times/timer.py +66 -0
- mo-times-1.0.17039/mo_times/vendor/__init__.py +0 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/__init__.py +10 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/easter.py +91 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/parser.py +913 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/relativedelta.py +436 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/rrule.py +1112 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/tz.py +961 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/tzwin.py +179 -0
- mo-times-1.0.17039/mo_times/vendor/dateutil/zoneinfo/__init__.py +90 -0
- mo-times-1.0.17039/mo_times.egg-info/PKG-INFO +171 -0
- mo-times-1.0.17039/mo_times.egg-info/SOURCES.txt +20 -0
- mo-times-1.0.17039/mo_times.egg-info/dependency_links.txt +1 -0
- mo-times-1.0.17039/mo_times.egg-info/not-zip-safe +1 -0
- mo-times-1.0.17039/mo_times.egg-info/top_level.txt +1 -0
- mo-times-1.0.17039/setup.cfg +5 -0
- mo-times-1.0.17039/setup.py +64 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: mo-times
|
|
3
|
+
Version: 1.0.17039
|
|
4
|
+
Summary: More Time! Time as a vector space, the way it was meant to be.
|
|
5
|
+
Home-page: https://github.com/klahnakoski/mo-times
|
|
6
|
+
Author: Kyle Lahnakoski
|
|
7
|
+
Author-email: kyle@lahnakoski.com
|
|
8
|
+
License: MPL 2.0
|
|
9
|
+
Description: ``Date`` class
|
|
10
|
+
==============
|
|
11
|
+
|
|
12
|
+
A simplified date and time class for time manipulation. This library is
|
|
13
|
+
intended for personal and business applications where assuming every
|
|
14
|
+
solar day has 24 \* 60 \* 60 seconds is considered accurate. `See *GMT
|
|
15
|
+
vs UTC* below <#GMT%20vs%20UTC>`__.
|
|
16
|
+
|
|
17
|
+
Assumptions
|
|
18
|
+
-----------
|
|
19
|
+
|
|
20
|
+
- **All time is in GMT** - Timezone math is left to be resolved at the
|
|
21
|
+
human endpoints: Machines should only be dealing with one type of
|
|
22
|
+
time; without holes, without overlap, and with minimal context.
|
|
23
|
+
- **Single time type** - There is no distinction between dates,
|
|
24
|
+
datetime and times; all measurements in the time dimension are
|
|
25
|
+
handled by one type called ``Date``. This is important for treating
|
|
26
|
+
time as a vector space.
|
|
27
|
+
- **Exclusive ceiling time ranges** - All time comparisons have been
|
|
28
|
+
standardized to ``min <= value < max``. The minimum is inclusive, and
|
|
29
|
+
the maximum is excluded. (please word this better)
|
|
30
|
+
|
|
31
|
+
``Date`` properties
|
|
32
|
+
-------------------
|
|
33
|
+
|
|
34
|
+
``Date()`` constructor
|
|
35
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
36
|
+
|
|
37
|
+
The ``Date()`` method will convert unix timestamps, millisecond
|
|
38
|
+
timestamps, various string formats and simple time formulas to create a
|
|
39
|
+
GMT time
|
|
40
|
+
|
|
41
|
+
``now()`` staticmethod
|
|
42
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
43
|
+
|
|
44
|
+
Return ``Date`` instance with millisecond resolution (in GMT).
|
|
45
|
+
|
|
46
|
+
``eod()`` staticmethod
|
|
47
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
48
|
+
|
|
49
|
+
Return end-of-day: Smallest ``Date`` which is greater than all time
|
|
50
|
+
points in today. Think of it as tomorrow. Same as ``now().ceiling(DAY)``
|
|
51
|
+
|
|
52
|
+
``today()`` staticmethod
|
|
53
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
54
|
+
|
|
55
|
+
The beginning of today. Same as ``now().floor(DAY)``
|
|
56
|
+
|
|
57
|
+
range(min, max, interval) staticmethod
|
|
58
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
59
|
+
|
|
60
|
+
Return an explicit list of ``Dates`` starting with ``min``, each
|
|
61
|
+
``interval`` more than the last, but now including ``max``. Used in
|
|
62
|
+
defining partitions in time domains.
|
|
63
|
+
|
|
64
|
+
``floor(duration=None)`` method
|
|
65
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
66
|
+
|
|
67
|
+
This method is usually used to perform date comparisons at the given
|
|
68
|
+
resolution (aka ``duration``). Round down to the nearest whole duration.
|
|
69
|
+
``duration`` as assumed to be ``DAY`` if not provided.
|
|
70
|
+
|
|
71
|
+
``format(format="%Y-%m-%d %H:%M:%S")`` method
|
|
72
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
73
|
+
|
|
74
|
+
Just like ``strftime``
|
|
75
|
+
|
|
76
|
+
``milli`` property
|
|
77
|
+
~~~~~~~~~~~~~~~~~~
|
|
78
|
+
|
|
79
|
+
Number of milliseconds since epoch
|
|
80
|
+
|
|
81
|
+
``unix`` property
|
|
82
|
+
~~~~~~~~~~~~~~~~~
|
|
83
|
+
|
|
84
|
+
Number of seconds since epoch
|
|
85
|
+
|
|
86
|
+
``add(duration)`` method
|
|
87
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
88
|
+
|
|
89
|
+
Add a ``duration`` to the time to get a new ``Date`` instance. The
|
|
90
|
+
``self`` is not modified.
|
|
91
|
+
|
|
92
|
+
``addDay()`` method
|
|
93
|
+
~~~~~~~~~~~~~~~~~~~
|
|
94
|
+
|
|
95
|
+
Convenience method for ``self.add(DAY)``
|
|
96
|
+
|
|
97
|
+
``Duration`` class
|
|
98
|
+
==================
|
|
99
|
+
|
|
100
|
+
Represents the difference between two ``Dates``. There are two scales:
|
|
101
|
+
|
|
102
|
+
- **``DAY`` scale** - includes seconds, minutes, hours, days and weeks.
|
|
103
|
+
- **``YEAR`` scale** - includes months, quarters, years, and centuries.
|
|
104
|
+
|
|
105
|
+
``Duration()`` constructor
|
|
106
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
107
|
+
|
|
108
|
+
Create a new ``Duration`` by name, by formula, by ``timespan``, or (more
|
|
109
|
+
rarely) number of milliseconds.
|
|
110
|
+
|
|
111
|
+
``floor(interval=None)`` method
|
|
112
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
113
|
+
|
|
114
|
+
Round down to nearest ``interval`` size.
|
|
115
|
+
|
|
116
|
+
``seconds`` property
|
|
117
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
118
|
+
|
|
119
|
+
return total number of seconds (including partial) in this duration
|
|
120
|
+
(estimate given for ``YEAR`` scale)
|
|
121
|
+
|
|
122
|
+
``total_seconds()`` method
|
|
123
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
124
|
+
|
|
125
|
+
Same as the ``seconds`` property
|
|
126
|
+
|
|
127
|
+
``round(interval, decimal=0)`` method
|
|
128
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
129
|
+
|
|
130
|
+
Return number of given ``interval`` rounded to given ``decimal`` places
|
|
131
|
+
|
|
132
|
+
``format(interval, decimal=0)`` method
|
|
133
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
134
|
+
|
|
135
|
+
Return a string representing ``self`` using given ``interval`` and
|
|
136
|
+
``decimal`` rounding
|
|
137
|
+
|
|
138
|
+
Time Vector Space
|
|
139
|
+
=================
|
|
140
|
+
|
|
141
|
+
The ``Date`` and ``Duration`` objects are the point and vectors in a one
|
|
142
|
+
dimensional vector space respectively. As such, the ``+`` and ``-``
|
|
143
|
+
operators are allowed. Comparisons with (``>``, ``>=',``\ <=``,``\ <\`)
|
|
144
|
+
are also supported.
|
|
145
|
+
|
|
146
|
+
GMT vs UTC
|
|
147
|
+
----------
|
|
148
|
+
|
|
149
|
+
The solar day is he most popular timekeeping unit. This library chose
|
|
150
|
+
GMT (UT1) for its base clock because of its consistent seconds in a
|
|
151
|
+
solar day. UTC suffers from inconsistent leap seconds and makes
|
|
152
|
+
time-math difficult, even while forcing us to make pedantic conclusions
|
|
153
|
+
like some minutes do not have 60 seconds. Lucky for us Python's
|
|
154
|
+
implementation of UTC (``datetime.utcnow()``) is wrong, and implements
|
|
155
|
+
GMT: Which is what we use.
|
|
156
|
+
|
|
157
|
+
Error Analysis
|
|
158
|
+
--------------
|
|
159
|
+
|
|
160
|
+
Assuming we need a generous leap second each 6 months (the past decade
|
|
161
|
+
saw only 4 leap seconds), then GMT deviates from UTC by up to 1 seconds
|
|
162
|
+
over 181 days (December to June, 15,638,400 seconds) which is an error
|
|
163
|
+
rate ``error = 1/15,638,400 = 0.000006395%``. If we want to call the
|
|
164
|
+
error "noise", we have a 70dB signal/noise ratio. All applications that
|
|
165
|
+
can tolerate this level of error should use GMT as their time basis.
|
|
166
|
+
|
|
167
|
+
Platform: UNKNOWN
|
|
168
|
+
Classifier: Development Status :: 4 - Beta
|
|
169
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
170
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
171
|
+
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
``Date`` class
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
A simplified date and time class for time manipulation. This library is
|
|
5
|
+
intended for personal and business applications where assuming every
|
|
6
|
+
solar day has 24 \* 60 \* 60 seconds is considered accurate. `See *GMT
|
|
7
|
+
vs UTC* below <#GMT%20vs%20UTC>`__.
|
|
8
|
+
|
|
9
|
+
Assumptions
|
|
10
|
+
-----------
|
|
11
|
+
|
|
12
|
+
- **All time is in GMT** - Timezone math is left to be resolved at the
|
|
13
|
+
human endpoints: Machines should only be dealing with one type of
|
|
14
|
+
time; without holes, without overlap, and with minimal context.
|
|
15
|
+
- **Single time type** - There is no distinction between dates,
|
|
16
|
+
datetime and times; all measurements in the time dimension are
|
|
17
|
+
handled by one type called ``Date``. This is important for treating
|
|
18
|
+
time as a vector space.
|
|
19
|
+
- **Exclusive ceiling time ranges** - All time comparisons have been
|
|
20
|
+
standardized to ``min <= value < max``. The minimum is inclusive, and
|
|
21
|
+
the maximum is excluded. (please word this better)
|
|
22
|
+
|
|
23
|
+
``Date`` properties
|
|
24
|
+
-------------------
|
|
25
|
+
|
|
26
|
+
``Date()`` constructor
|
|
27
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
28
|
+
|
|
29
|
+
The ``Date()`` method will convert unix timestamps, millisecond
|
|
30
|
+
timestamps, various string formats and simple time formulas to create a
|
|
31
|
+
GMT time
|
|
32
|
+
|
|
33
|
+
``now()`` staticmethod
|
|
34
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
35
|
+
|
|
36
|
+
Return ``Date`` instance with millisecond resolution (in GMT).
|
|
37
|
+
|
|
38
|
+
``eod()`` staticmethod
|
|
39
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
40
|
+
|
|
41
|
+
Return end-of-day: Smallest ``Date`` which is greater than all time
|
|
42
|
+
points in today. Think of it as tomorrow. Same as ``now().ceiling(DAY)``
|
|
43
|
+
|
|
44
|
+
``today()`` staticmethod
|
|
45
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
46
|
+
|
|
47
|
+
The beginning of today. Same as ``now().floor(DAY)``
|
|
48
|
+
|
|
49
|
+
range(min, max, interval) staticmethod
|
|
50
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
51
|
+
|
|
52
|
+
Return an explicit list of ``Dates`` starting with ``min``, each
|
|
53
|
+
``interval`` more than the last, but now including ``max``. Used in
|
|
54
|
+
defining partitions in time domains.
|
|
55
|
+
|
|
56
|
+
``floor(duration=None)`` method
|
|
57
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
58
|
+
|
|
59
|
+
This method is usually used to perform date comparisons at the given
|
|
60
|
+
resolution (aka ``duration``). Round down to the nearest whole duration.
|
|
61
|
+
``duration`` as assumed to be ``DAY`` if not provided.
|
|
62
|
+
|
|
63
|
+
``format(format="%Y-%m-%d %H:%M:%S")`` method
|
|
64
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
65
|
+
|
|
66
|
+
Just like ``strftime``
|
|
67
|
+
|
|
68
|
+
``milli`` property
|
|
69
|
+
~~~~~~~~~~~~~~~~~~
|
|
70
|
+
|
|
71
|
+
Number of milliseconds since epoch
|
|
72
|
+
|
|
73
|
+
``unix`` property
|
|
74
|
+
~~~~~~~~~~~~~~~~~
|
|
75
|
+
|
|
76
|
+
Number of seconds since epoch
|
|
77
|
+
|
|
78
|
+
``add(duration)`` method
|
|
79
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
80
|
+
|
|
81
|
+
Add a ``duration`` to the time to get a new ``Date`` instance. The
|
|
82
|
+
``self`` is not modified.
|
|
83
|
+
|
|
84
|
+
``addDay()`` method
|
|
85
|
+
~~~~~~~~~~~~~~~~~~~
|
|
86
|
+
|
|
87
|
+
Convenience method for ``self.add(DAY)``
|
|
88
|
+
|
|
89
|
+
``Duration`` class
|
|
90
|
+
==================
|
|
91
|
+
|
|
92
|
+
Represents the difference between two ``Dates``. There are two scales:
|
|
93
|
+
|
|
94
|
+
- **``DAY`` scale** - includes seconds, minutes, hours, days and weeks.
|
|
95
|
+
- **``YEAR`` scale** - includes months, quarters, years, and centuries.
|
|
96
|
+
|
|
97
|
+
``Duration()`` constructor
|
|
98
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
99
|
+
|
|
100
|
+
Create a new ``Duration`` by name, by formula, by ``timespan``, or (more
|
|
101
|
+
rarely) number of milliseconds.
|
|
102
|
+
|
|
103
|
+
``floor(interval=None)`` method
|
|
104
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
105
|
+
|
|
106
|
+
Round down to nearest ``interval`` size.
|
|
107
|
+
|
|
108
|
+
``seconds`` property
|
|
109
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
110
|
+
|
|
111
|
+
return total number of seconds (including partial) in this duration
|
|
112
|
+
(estimate given for ``YEAR`` scale)
|
|
113
|
+
|
|
114
|
+
``total_seconds()`` method
|
|
115
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
116
|
+
|
|
117
|
+
Same as the ``seconds`` property
|
|
118
|
+
|
|
119
|
+
``round(interval, decimal=0)`` method
|
|
120
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
121
|
+
|
|
122
|
+
Return number of given ``interval`` rounded to given ``decimal`` places
|
|
123
|
+
|
|
124
|
+
``format(interval, decimal=0)`` method
|
|
125
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
126
|
+
|
|
127
|
+
Return a string representing ``self`` using given ``interval`` and
|
|
128
|
+
``decimal`` rounding
|
|
129
|
+
|
|
130
|
+
Time Vector Space
|
|
131
|
+
=================
|
|
132
|
+
|
|
133
|
+
The ``Date`` and ``Duration`` objects are the point and vectors in a one
|
|
134
|
+
dimensional vector space respectively. As such, the ``+`` and ``-``
|
|
135
|
+
operators are allowed. Comparisons with (``>``, ``>=',``\ <=``,``\ <\`)
|
|
136
|
+
are also supported.
|
|
137
|
+
|
|
138
|
+
GMT vs UTC
|
|
139
|
+
----------
|
|
140
|
+
|
|
141
|
+
The solar day is he most popular timekeeping unit. This library chose
|
|
142
|
+
GMT (UT1) for its base clock because of its consistent seconds in a
|
|
143
|
+
solar day. UTC suffers from inconsistent leap seconds and makes
|
|
144
|
+
time-math difficult, even while forcing us to make pedantic conclusions
|
|
145
|
+
like some minutes do not have 60 seconds. Lucky for us Python's
|
|
146
|
+
implementation of UTC (``datetime.utcnow()``) is wrong, and implements
|
|
147
|
+
GMT: Which is what we use.
|
|
148
|
+
|
|
149
|
+
Error Analysis
|
|
150
|
+
--------------
|
|
151
|
+
|
|
152
|
+
Assuming we need a generous leap second each 6 months (the past decade
|
|
153
|
+
saw only 4 leap seconds), then GMT deviates from UTC by up to 1 seconds
|
|
154
|
+
over 181 days (December to June, 15,638,400 seconds) which is an error
|
|
155
|
+
rate ``error = 1/15,638,400 = 0.000006395%``. If we want to call the
|
|
156
|
+
error "noise", we have a 70dB signal/noise ratio. All applications that
|
|
157
|
+
can tolerate this level of error should use GMT as their time basis.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
#
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
6
|
+
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
7
|
+
#
|
|
8
|
+
# Author: Kyle Lahnakoski (kyle@lahnakoski.com)
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
from __future__ import absolute_import
|
|
12
|
+
from __future__ import division
|
|
13
|
+
from __future__ import unicode_literals
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from mo_times.dates import Date
|
|
17
|
+
from mo_times.durations import Duration, MINUTE
|