opendate 0.1.10__tar.gz → 0.1.12__tar.gz
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.
Potentially problematic release.
This version of opendate might be problematic. Click here for more details.
- {opendate-0.1.10 → opendate-0.1.12}/PKG-INFO +1 -1
- {opendate-0.1.10 → opendate-0.1.12}/pyproject.toml +1 -1
- {opendate-0.1.10 → opendate-0.1.12}/src/date/__init__.py +24 -19
- {opendate-0.1.10 → opendate-0.1.12}/src/date/date.py +26 -12
- {opendate-0.1.10 → opendate-0.1.12}/LICENSE +0 -0
- {opendate-0.1.10 → opendate-0.1.12}/README.md +0 -0
- {opendate-0.1.10 → opendate-0.1.12}/src/date/extras.py +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = '0.1.
|
|
1
|
+
__version__ = '0.1.12'
|
|
2
2
|
|
|
3
3
|
import datetime as _datetime
|
|
4
4
|
|
|
@@ -51,6 +51,10 @@ def time(*args, **kwargs):
|
|
|
51
51
|
return Time(*args, **kwargs)
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
def interval(*args, **kwargs):
|
|
55
|
+
return Interval(*args, **kwargs)
|
|
56
|
+
|
|
57
|
+
|
|
54
58
|
def parse(s: str | None, fmt: str = None, entity: Entity = NYSE, raise_err: bool = False) -> DateTime | None:
|
|
55
59
|
"""Parse using DateTime.parse
|
|
56
60
|
"""
|
|
@@ -60,14 +64,13 @@ def parse(s: str | None, fmt: str = None, entity: Entity = NYSE, raise_err: bool
|
|
|
60
64
|
def instance(obj: _datetime.date | _datetime.datetime | _datetime.time) -> DateTime | Date | Time:
|
|
61
65
|
"""Create a DateTime/Date/Time instance from a datetime/date/time native one.
|
|
62
66
|
"""
|
|
63
|
-
if isinstance(obj, DateTime | Date | Time):
|
|
64
|
-
return obj
|
|
65
67
|
if isinstance(obj, _datetime.date) and not isinstance(obj, _datetime.datetime):
|
|
66
68
|
return Date.instance(obj)
|
|
67
69
|
if isinstance(obj, _datetime.time):
|
|
68
70
|
return Time.instance(obj)
|
|
69
71
|
if isinstance(obj, _datetime.datetime):
|
|
70
72
|
return DateTime.instance(obj)
|
|
73
|
+
raise ValueError(f'opendate `instance` helper cannot parse type {type(obj)}')
|
|
71
74
|
|
|
72
75
|
|
|
73
76
|
def now(tz: str | _zoneinfo.ZoneInfo | None = None) -> DateTime:
|
|
@@ -84,28 +87,30 @@ def today(tz: str | _zoneinfo.ZoneInfo = None) -> DateTime:
|
|
|
84
87
|
|
|
85
88
|
__all__ = [
|
|
86
89
|
'Date',
|
|
90
|
+
'date',
|
|
87
91
|
'DateTime',
|
|
92
|
+
'datetime',
|
|
93
|
+
'Entity',
|
|
94
|
+
'expect_date',
|
|
95
|
+
'expect_datetime',
|
|
96
|
+
'expect_native_timezone',
|
|
97
|
+
'expect_utc_timezone',
|
|
98
|
+
'instance',
|
|
88
99
|
'Interval',
|
|
100
|
+
'interval',
|
|
89
101
|
'IntervalError',
|
|
90
|
-
'
|
|
91
|
-
'
|
|
102
|
+
'is_business_day',
|
|
103
|
+
'is_within_business_hours',
|
|
104
|
+
'LCL',
|
|
92
105
|
'now',
|
|
93
|
-
'
|
|
106
|
+
'NYSE',
|
|
107
|
+
'overlap_days',
|
|
94
108
|
'parse',
|
|
95
|
-
'LCL',
|
|
96
|
-
'timezone',
|
|
97
|
-
'expect_native_timezone',
|
|
98
|
-
'expect_utc_timezone',
|
|
99
109
|
'prefer_native_timezone',
|
|
100
110
|
'prefer_utc_timezone',
|
|
101
|
-
'
|
|
102
|
-
'expect_datetime',
|
|
103
|
-
'Entity',
|
|
104
|
-
'NYSE',
|
|
105
|
-
'date',
|
|
106
|
-
'datetime',
|
|
111
|
+
'Time',
|
|
107
112
|
'time',
|
|
108
|
-
'
|
|
109
|
-
'
|
|
110
|
-
'
|
|
113
|
+
'timezone',
|
|
114
|
+
'today',
|
|
115
|
+
'WeekDay',
|
|
111
116
|
]
|
|
@@ -787,8 +787,18 @@ class Date(DateExtrasMixin, DateBusinessMixin, _pendulum.Date):
|
|
|
787
787
|
raise TypeError(f'Invalid type for date parse: {s.__class__}')
|
|
788
788
|
|
|
789
789
|
if fmt:
|
|
790
|
-
|
|
790
|
+
try:
|
|
791
791
|
return cls(*time.strptime(s, fmt)[:3])
|
|
792
|
+
except:
|
|
793
|
+
if raise_err:
|
|
794
|
+
raise ValueError(f'Unable to parse {s} using fmt {fmt}')
|
|
795
|
+
return
|
|
796
|
+
|
|
797
|
+
with contextlib.suppress(ValueError):
|
|
798
|
+
if float(s) and not len(s) == 8: # 20000101
|
|
799
|
+
if raise_err:
|
|
800
|
+
raise ValueError('Invalid date: %s', s)
|
|
801
|
+
return
|
|
792
802
|
|
|
793
803
|
# special shortcode symbolic values: T, Y-2, P-1b
|
|
794
804
|
if m := DATEMATCH.match(s):
|
|
@@ -810,7 +820,7 @@ class Date(DateExtrasMixin, DateBusinessMixin, _pendulum.Date):
|
|
|
810
820
|
return cls.today().subtract(days=1)
|
|
811
821
|
|
|
812
822
|
with contextlib.suppress(TypeError, ValueError):
|
|
813
|
-
return cls.instance(_dateutil.parser.parse(s)
|
|
823
|
+
return cls.instance(_dateutil.parser.parse(s))
|
|
814
824
|
|
|
815
825
|
# Regex with Month Numbers
|
|
816
826
|
exps = (
|
|
@@ -892,7 +902,7 @@ class Date(DateExtrasMixin, DateBusinessMixin, _pendulum.Date):
|
|
|
892
902
|
|
|
893
903
|
@classmethod
|
|
894
904
|
def today(cls):
|
|
895
|
-
d = _datetime.
|
|
905
|
+
d = _datetime.datetime.now(LCL)
|
|
896
906
|
return cls(d.year, d.month, d.day)
|
|
897
907
|
|
|
898
908
|
def isoweek(self):
|
|
@@ -1010,7 +1020,12 @@ class Time(_pendulum.Time):
|
|
|
1010
1020
|
raise TypeError(f'Invalid type for time parse: {s.__class__}')
|
|
1011
1021
|
|
|
1012
1022
|
if fmt:
|
|
1013
|
-
|
|
1023
|
+
try:
|
|
1024
|
+
return cls(*time.strptime(s, fmt)[3:6])
|
|
1025
|
+
except:
|
|
1026
|
+
if raise_err:
|
|
1027
|
+
raise ValueError(f'Unable to parse {s} using fmt {fmt}')
|
|
1028
|
+
return
|
|
1014
1029
|
|
|
1015
1030
|
exps = (
|
|
1016
1031
|
r'^(?P<h>\d{1,2})[:.](?P<m>\d{2})([:.](?P<s>\d{2})([.,](?P<u>\d+))?)?( +(?P<ap>[aApP][mM]))?$',
|
|
@@ -1028,7 +1043,7 @@ class Time(_pendulum.Time):
|
|
|
1028
1043
|
return cls(hh, mm, ss, uu * 1000)
|
|
1029
1044
|
|
|
1030
1045
|
with contextlib.suppress(TypeError, ValueError):
|
|
1031
|
-
return cls.instance(_dateutil.parser.parse(s)
|
|
1046
|
+
return cls.instance(_dateutil.parser.parse(s))
|
|
1032
1047
|
|
|
1033
1048
|
if raise_err:
|
|
1034
1049
|
raise ValueError('Failed to parse time: %s', s)
|
|
@@ -1177,7 +1192,7 @@ class DateTime(DateBusinessMixin, _pendulum.DateTime):
|
|
|
1177
1192
|
UTC time technically equals GMT
|
|
1178
1193
|
>>> this_utc = DateTime.parse('Fri, 31 Oct 2014 18:55:00 GMT')
|
|
1179
1194
|
>>> this_utc
|
|
1180
|
-
DateTime(2014, 10, 31, 18, 55, 0, tzinfo=
|
|
1195
|
+
DateTime(2014, 10, 31, 18, 55, 0, tzinfo=tzutc())
|
|
1181
1196
|
|
|
1182
1197
|
We can freely compare time zones
|
|
1183
1198
|
>>> this_est1==this_est2==this_utc
|
|
@@ -1205,8 +1220,7 @@ class DateTime(DateBusinessMixin, _pendulum.DateTime):
|
|
|
1205
1220
|
return cls.parse(iso).replace(tzinfo=LCL)
|
|
1206
1221
|
|
|
1207
1222
|
with contextlib.suppress(ValueError, TypeError):
|
|
1208
|
-
|
|
1209
|
-
return cls.instance(_pendulum.instance(obj))
|
|
1223
|
+
return cls.instance(_dateutil.parser.parse(s))
|
|
1210
1224
|
|
|
1211
1225
|
for delim in (' ', ':'):
|
|
1212
1226
|
bits = s.split(delim, 1)
|
|
@@ -1505,13 +1519,13 @@ class Interval:
|
|
|
1505
1519
|
def days(self) -> int:
|
|
1506
1520
|
"""Return days between (begdate, enddate] or negative (enddate, begdate].
|
|
1507
1521
|
|
|
1508
|
-
>>> Interval(Date
|
|
1522
|
+
>>> Interval(Date(2018, 9, 6), Date(2018, 9, 10)).days()
|
|
1509
1523
|
4
|
|
1510
|
-
>>> Interval(Date
|
|
1524
|
+
>>> Interval(Date(2018, 9, 10), Date(2018, 9, 6)).days()
|
|
1511
1525
|
-4
|
|
1512
|
-
>>> Interval(Date
|
|
1526
|
+
>>> Interval(Date(2018, 9, 6), Date(2018, 9, 10)).b.days()
|
|
1513
1527
|
2
|
|
1514
|
-
>>> Interval(Date
|
|
1528
|
+
>>> Interval(Date(2018, 9, 10), Date(2018, 9, 6)).b.days()
|
|
1515
1529
|
-2
|
|
1516
1530
|
"""
|
|
1517
1531
|
assert self.begdate
|
|
File without changes
|
|
File without changes
|
|
File without changes
|