opendate 0.1.1__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 +109 -0
- date/business.py +42 -0
- date/date.py +1702 -0
- opendate-0.1.1.dist-info/LICENSE +23 -0
- opendate-0.1.1.dist-info/METADATA +61 -0
- opendate-0.1.1.dist-info/RECORD +7 -0
- opendate-0.1.1.dist-info/WHEEL +4 -0
date/__init__.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
__version__ = '0.1.1'
|
|
2
|
+
|
|
3
|
+
import datetime as _datetime
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import pendulum as _pendulum
|
|
8
|
+
import zoneinfo as _zoneinfo
|
|
9
|
+
|
|
10
|
+
from typing_extensions import Optional
|
|
11
|
+
from typing_extensions import Union
|
|
12
|
+
from typing_extensions import overload
|
|
13
|
+
|
|
14
|
+
from date.date import Date
|
|
15
|
+
from date.date import DateTime
|
|
16
|
+
from date.date import Entity
|
|
17
|
+
from date.date import Interval
|
|
18
|
+
from date.date import IntervalError
|
|
19
|
+
from date.date import LCL
|
|
20
|
+
from date.date import EST
|
|
21
|
+
from date.date import GMT
|
|
22
|
+
from date.date import UTC
|
|
23
|
+
from date.date import NYSE
|
|
24
|
+
from date.date import Time
|
|
25
|
+
from date.date import WeekDay
|
|
26
|
+
from date.date import WEEKDAY_SHORTNAME
|
|
27
|
+
from date.date import expect_date
|
|
28
|
+
from date.date import expect_datetime
|
|
29
|
+
from date.date import expect_native_timezone
|
|
30
|
+
from date.date import expect_utc_timezone
|
|
31
|
+
from date.date import prefer_native_timezone
|
|
32
|
+
from date.date import prefer_utc_timezone
|
|
33
|
+
from date.date import Timezone
|
|
34
|
+
from date.business import *
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
timezone = Timezone
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def date(*args, **kwargs):
|
|
41
|
+
return Date(*args, **kwargs)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def datetime(*args, **kwargs):
|
|
45
|
+
return DateTime(*args, **kwargs)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def time(*args, **kwargs):
|
|
49
|
+
return Time(*args, **kwargs)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def parse():
|
|
53
|
+
"""Generic parser that guesses type"""
|
|
54
|
+
raise NotImplementedError(
|
|
55
|
+
'Generic parser not implemented, use Date or DateTime parsers'
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def instance(obj: _datetime.date | _datetime.datetime | _datetime.time) -> DateTime | Date | Time:
|
|
60
|
+
"""
|
|
61
|
+
Create a DateTime/Date/Time instance from a datetime/date/time native one.
|
|
62
|
+
"""
|
|
63
|
+
if isinstance(obj, DateTime | Date | Time):
|
|
64
|
+
return obj
|
|
65
|
+
if isinstance(obj, _datetime.date) and not isinstance(obj, _datetime.datetime):
|
|
66
|
+
return Date.instance(obj)
|
|
67
|
+
if isinstance(obj, _datetime.time):
|
|
68
|
+
return Time.instance(obj)
|
|
69
|
+
if isinstance(obj, _datetime.datetime):
|
|
70
|
+
return DateTime.instance(obj)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def now(tz: str | _zoneinfo.ZoneInfo | None = None) -> DateTime:
|
|
74
|
+
"""Get current datetime
|
|
75
|
+
"""
|
|
76
|
+
return DateTime.now(tz)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def today(tz: str | _zoneinfo.ZoneInfo = None) -> DateTime:
|
|
80
|
+
"""Get current date
|
|
81
|
+
"""
|
|
82
|
+
return DateTime.today(tz)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
__all__ = [
|
|
86
|
+
'Date',
|
|
87
|
+
'DateTime',
|
|
88
|
+
'Interval',
|
|
89
|
+
'IntervalError',
|
|
90
|
+
'Time',
|
|
91
|
+
'WeekDay',
|
|
92
|
+
'now',
|
|
93
|
+
'today',
|
|
94
|
+
'parse',
|
|
95
|
+
'LCL',
|
|
96
|
+
'timezone',
|
|
97
|
+
'expect_native_timezone',
|
|
98
|
+
'expect_utc_timezone',
|
|
99
|
+
'prefer_native_timezone',
|
|
100
|
+
'prefer_utc_timezone',
|
|
101
|
+
'expect_date',
|
|
102
|
+
'expect_datetime',
|
|
103
|
+
'Entity',
|
|
104
|
+
'NYSE',
|
|
105
|
+
'date',
|
|
106
|
+
'datetime',
|
|
107
|
+
'time'
|
|
108
|
+
'within_business_hours'
|
|
109
|
+
]
|
date/business.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from date import NYSE, DateTime, Entity
|
|
2
|
+
|
|
3
|
+
__all__ = ['is_within_business_hours', 'is_business_day']
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def is_within_business_hours(entity: Entity = NYSE) -> bool:
|
|
7
|
+
"""Return whether the current native datetime is between
|
|
8
|
+
open and close of business hours.
|
|
9
|
+
|
|
10
|
+
>>> from unittest.mock import patch
|
|
11
|
+
>>> tz = NYSE.tz
|
|
12
|
+
|
|
13
|
+
>>> with patch('date.DateTime.now') as mock:
|
|
14
|
+
... mock.return_value = DateTime(2000, 5, 1, 12, 30, 0, 0, tzinfo=tz)
|
|
15
|
+
... is_within_business_hours()
|
|
16
|
+
True
|
|
17
|
+
|
|
18
|
+
>>> with patch('date.DateTime.now') as mock:
|
|
19
|
+
... mock.return_value = DateTime(2000, 7, 2, 12, 15, 0, 0, tzinfo=tz) # Sunday
|
|
20
|
+
... is_within_business_hours()
|
|
21
|
+
False
|
|
22
|
+
|
|
23
|
+
>>> with patch('date.DateTime.now') as mock:
|
|
24
|
+
... mock.return_value = DateTime(2000, 11, 1, 1, 15, 0, 0, tzinfo=tz)
|
|
25
|
+
... is_within_business_hours()
|
|
26
|
+
False
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
this = DateTime.now()
|
|
30
|
+
this_entity = DateTime.now(tz=entity.tz).entity(entity)
|
|
31
|
+
bounds = this_entity.business_hours()
|
|
32
|
+
return this_entity.business_open() and (bounds[0] <= this.astimezone(entity.tz) <= bounds[1])
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def is_business_day(entity: Entity = NYSE) -> bool:
|
|
36
|
+
"""Return whether the current native datetime is a business day.
|
|
37
|
+
"""
|
|
38
|
+
return DateTime.now(tz=entity.tz).entity(entity).is_business_day()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == '__main__':
|
|
42
|
+
__import__('doctest').testmod(optionflags=4 | 8 | 32)
|