opendate 0.1.10__py3-none-any.whl → 0.1.12__py3-none-any.whl

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.

date/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = '0.1.10'
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
- 'Time',
91
- 'WeekDay',
102
+ 'is_business_day',
103
+ 'is_within_business_hours',
104
+ 'LCL',
92
105
  'now',
93
- 'today',
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
- 'expect_date',
102
- 'expect_datetime',
103
- 'Entity',
104
- 'NYSE',
105
- 'date',
106
- 'datetime',
111
+ 'Time',
107
112
  'time',
108
- 'overlap_days',
109
- 'is_within_business_hours',
110
- 'is_business_day',
113
+ 'timezone',
114
+ 'today',
115
+ 'WeekDay',
111
116
  ]
date/date.py CHANGED
@@ -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
- with contextlib.suppress(ValueError):
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).date())
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.date.today()
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
- return cls(*time.strptime(s, fmt)[3:6])
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).time())
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=Timezone('UTC'))
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
- obj = _dateutil.parser.parse(s)
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.parse('2018/9/6'), Date.parse('2018/9/10')).days()
1522
+ >>> Interval(Date(2018, 9, 6), Date(2018, 9, 10)).days()
1509
1523
  4
1510
- >>> Interval(Date.parse('2018/9/10'), Date.parse('2018/9/6')).days()
1524
+ >>> Interval(Date(2018, 9, 10), Date(2018, 9, 6)).days()
1511
1525
  -4
1512
- >>> Interval(Date.parse('2018/9/6'), Date.parse('2018/9/10')).b.days()
1526
+ >>> Interval(Date(2018, 9, 6), Date(2018, 9, 10)).b.days()
1513
1527
  2
1514
- >>> Interval(Date.parse('2018/9/10'), Date.parse('2018/9/6')).b.days()
1528
+ >>> Interval(Date(2018, 9, 10), Date(2018, 9, 6)).b.days()
1515
1529
  -2
1516
1530
  """
1517
1531
  assert self.begdate
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opendate
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: Python business datetimes
5
5
  Home-page: https://github.com/bissli/opendate
6
6
  License: MIT
@@ -0,0 +1,7 @@
1
+ date/__init__.py,sha256=3fxOfehp0ICai0AF8pgpJPwJZKjR-CIDECPGNQMNhTM,2865
2
+ date/date.py,sha256=0GPnKNt9mdAvWmXC7ZUFDs6-_kTEY6sbqrKvP-fZFZg,57585
3
+ date/extras.py,sha256=7xsOsdhKrmGoyLl5W4Xhg9TfuytaaIH7uKWW9PvR5sE,2832
4
+ opendate-0.1.12.dist-info/LICENSE,sha256=V4Rx8WWy7v8Fim6PHcEBszpZkDLbCHeorz1e_gr0Cbk,1111
5
+ opendate-0.1.12.dist-info/METADATA,sha256=BRm-wE6c2-sF6e3cFgYoOnKd6SriRcPD78d4s79LbZc,1842
6
+ opendate-0.1.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
7
+ opendate-0.1.12.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- date/__init__.py,sha256=xOpRu8_JttvBQRvXYcOms5iy1ni5t10zuv0s2ISSFis,2748
2
- date/date.py,sha256=XnXYC86t3iyrINqph-dloY1YBaR3u1Tmy45ql6Vbuco,57188
3
- date/extras.py,sha256=7xsOsdhKrmGoyLl5W4Xhg9TfuytaaIH7uKWW9PvR5sE,2832
4
- opendate-0.1.10.dist-info/LICENSE,sha256=V4Rx8WWy7v8Fim6PHcEBszpZkDLbCHeorz1e_gr0Cbk,1111
5
- opendate-0.1.10.dist-info/METADATA,sha256=ZzkO_4pctn-stVwyiZFKxxuzYLqJB-SKkSkPYW4uTG4,1842
6
- opendate-0.1.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
7
- opendate-0.1.10.dist-info/RECORD,,