opendate 0.1.3__tar.gz → 0.1.5__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.

@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opendate
3
- Version: 0.1.3
4
- Summary:
3
+ Version: 0.1.5
4
+ Summary: Python business datetimes
5
5
  Home-page: https://github.com/bissli/opendate
6
6
  License: MIT
7
7
  Author: bissli
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "opendate"
3
- version = "0.1.3"
4
- description = ""
3
+ version = "0.1.5"
4
+ description = "Python business datetimes"
5
5
  authors = ["bissli <bissli.xyz@protonmail.com>"]
6
6
  readme = "README.md"
7
7
  license = "MIT"
@@ -1,4 +1,4 @@
1
- __version__ = '0.1.3'
1
+ __version__ = '0.1.5'
2
2
 
3
3
  import datetime as _datetime
4
4
 
@@ -51,11 +51,10 @@ def time(*args, **kwargs):
51
51
  return Time(*args, **kwargs)
52
52
 
53
53
 
54
- def parse():
55
- """Generic parser that guesses type"""
56
- raise NotImplementedError(
57
- 'Generic parser not implemented, use Date or DateTime parsers'
58
- )
54
+ def parse(s: str | None, fmt: str = None, entity: Entity = NYSE, raise_err: bool = False) -> DateTime | None:
55
+ """Parse using DateTime.parse
56
+ """
57
+ return DateTime.parse(s, entity=entity, raise_err=True)
59
58
 
60
59
 
61
60
  def instance(obj: _datetime.date | _datetime.datetime | _datetime.time) -> DateTime | Date | Time:
@@ -72,13 +71,13 @@ def instance(obj: _datetime.date | _datetime.datetime | _datetime.time) -> DateT
72
71
 
73
72
 
74
73
  def now(tz: str | _zoneinfo.ZoneInfo | None = None) -> DateTime:
75
- """Get current datetime
74
+ """Returns Datetime.now
76
75
  """
77
76
  return DateTime.now(tz)
78
77
 
79
78
 
80
79
  def today(tz: str | _zoneinfo.ZoneInfo = None) -> DateTime:
81
- """Get current date
80
+ """Returns DateTime.today
82
81
  """
83
82
  return DateTime.today(tz)
84
83
 
@@ -47,6 +47,27 @@ __all__ = [
47
47
 
48
48
  def Timezone(name:str = 'US/Eastern') -> _zoneinfo.ZoneInfo:
49
49
  """Simple wrapper around Pendulum `Timezone`
50
+
51
+ Ex: sanity check US/Eastern == America/New_York
52
+
53
+ >>> winter1 = DateTime(2000, 1, 1, 12, tzinfo=Timezone('US/Eastern'))
54
+ >>> winter2 = DateTime(2000, 1, 1, 12, tzinfo=Timezone('America/New_York'))
55
+
56
+ >>> summer1 = DateTime(2000, 7, 1, 12, tzinfo=Timezone('US/Eastern'))
57
+ >>> summer2 = DateTime(2000, 7, 1, 12, tzinfo=Timezone('America/New_York'))
58
+
59
+ >>> winter = [winter1, winter2,
60
+ ... winter1.astimezone(Timezone('America/New_York')),
61
+ ... winter2.astimezone(Timezone('US/Eastern')),
62
+ ... ]
63
+ >>> assert all(x==winter[0] for x in winter)
64
+
65
+ >>> summer = [summer1, summer2,
66
+ ... summer1.astimezone(Timezone('America/New_York')),
67
+ ... summer2.astimezone(Timezone('US/Eastern')),
68
+ ... ]
69
+ >>> assert all(x==summer[0] for x in summer)
70
+
50
71
  """
51
72
  return _pendulum.tz.Timezone(name)
52
73
 
@@ -1115,7 +1136,11 @@ class DateTime(DateBusinessMixin, _pendulum.DateTime):
1115
1136
  return Time.instance(self)
1116
1137
 
1117
1138
  @classmethod
1118
- def parse(cls, s: str | int | None, raise_err: bool = False) -> Self | None:
1139
+ def parse(
1140
+ cls, s: str | int | None,
1141
+ entity: Entity = NYSE,
1142
+ raise_err: bool = False
1143
+ ) -> Self | None:
1119
1144
  """Thin layer on Date parser and our custom `Date.parse``
1120
1145
 
1121
1146
  >>> DateTime.parse('2022/1/1')
@@ -1173,7 +1198,7 @@ class DateTime(DateBusinessMixin, _pendulum.DateTime):
1173
1198
  if d is not None and t is not None:
1174
1199
  return DateTime.combine(d, t, LCL)
1175
1200
 
1176
- d = Date.parse(s)
1201
+ d = Date.parse(s, entity=entity)
1177
1202
  if d is not None:
1178
1203
  return cls(d.year, d.month, d.day, 0, 0, 0)
1179
1204
 
@@ -1413,18 +1438,35 @@ class Interval:
1413
1438
  yield thedate
1414
1439
  thedate = thedate.add(days=1)
1415
1440
 
1441
+ def start_of_series(self, unit='month') -> list[Date]:
1442
+ """Return a series between and inclusive of begdate and enddate.
1443
+
1444
+ >>> Interval(Date(2018, 1, 5), Date(2018, 4, 5)).start_of_series('month')
1445
+ [Date(2018, 1, 1), Date(2018, 2, 1), Date(2018, 3, 1), Date(2018, 4, 1)]
1446
+ >>> Interval(Date(2018, 4, 30), Date(2018, 7, 30)).start_of_series('month')
1447
+ [Date(2018, 4, 1), Date(2018, 5, 1), Date(2018, 6, 1), Date(2018, 7, 1)]
1448
+ >>> Interval(Date(2018, 1, 5), Date(2018, 4, 5)).start_of_series('week')
1449
+ [Date(2018, 1, 1), Date(2018, 1, 8), ..., Date(2018, 4, 2)]
1450
+ """
1451
+ begdate = self.begdate.start_of(unit)
1452
+ enddate = self.enddate.start_of(unit)
1453
+ interval = _pendulum.interval(begdate, enddate)
1454
+ return [Date.instance(d).start_of(unit) for d in interval.range(f'{unit}s')]
1455
+
1416
1456
  def end_of_series(self, unit='month') -> list[Date]:
1417
1457
  """Return a series between and inclusive of begdate and enddate.
1418
1458
 
1419
1459
  >>> Interval(Date(2018, 1, 5), Date(2018, 4, 5)).end_of_series('month')
1420
1460
  [Date(2018, 1, 31), Date(2018, 2, 28), Date(2018, 3, 31), Date(2018, 4, 30)]
1461
+ >>> Interval(Date(2018, 4, 30), Date(2018, 7, 30)).end_of_series('month')
1462
+ [Date(2018, 4, 30), Date(2018, 5, 31), Date(2018, 6, 30), Date(2018, 7, 31)]
1421
1463
  >>> Interval(Date(2018, 1, 5), Date(2018, 4, 5)).end_of_series('week')
1422
1464
  [Date(2018, 1, 7), Date(2018, 1, 14), ..., Date(2018, 4, 8)]
1423
1465
  """
1424
1466
  begdate = self.begdate.end_of(unit)
1425
1467
  enddate = self.enddate.end_of(unit)
1426
1468
  interval = _pendulum.interval(begdate, enddate)
1427
- return [Date.instance(d) for d in interval.range(f'{unit}s')]
1469
+ return [Date.instance(d).end_of(unit) for d in interval.range(f'{unit}s')]
1428
1470
 
1429
1471
  def days(self) -> int:
1430
1472
  """Return days between (begdate, enddate] or negative (enddate, begdate].
File without changes
File without changes
File without changes