generated from uniswapfoundation/v4-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculate_dst.py
55 lines (43 loc) · 1.52 KB
/
calculate_dst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytz
from dateutil import rrule
from datetime import datetime
def generate_dst_dates(year):
tz = pytz.timezone("America/New_York")
dst_start_date = list(
rrule.rrule(
rrule.YEARLY,
dtstart=datetime(year, 3, 8, 2, 0, 0),
until=datetime(year, 12, 31),
bymonth=3,
byweekday=rrule.SU(2),
)
)[0]
dst_end_date = list(
rrule.rrule(
rrule.YEARLY,
dtstart=datetime(year, 11, 1, 2, 0, 0),
until=datetime(year, 12, 31),
bymonth=11,
byweekday=rrule.SU(1),
)
)[0]
dst_start_date = tz.localize(dst_start_date)
dst_end_date = tz.localize(dst_end_date)
return dst_start_date, dst_end_date
def get_dst_timestamps(year):
tz = pytz.timezone("UTC")
epoch = tz.localize(datetime(2023, 1, 1, 0, 0, 0))
dst_start_date, dst_end_date = generate_dst_dates(year)
dst_start_timestamp = int(dst_start_date.timestamp()) - int(epoch.timestamp())
dst_end_timestamp = int(dst_end_date.timestamp()) - int(epoch.timestamp())
return dst_start_timestamp, dst_end_timestamp
def get_hex_string_for_years(start_year, num_years):
result = []
for year in range(start_year, start_year + num_years):
start_timestamp, end_timestamp = get_dst_timestamps(year)
result.append(
hex(start_timestamp)[2:].zfill(8)
)
result.append(hex(end_timestamp)[2:].zfill(8))
return "".join(result)
print(get_hex_string_for_years(2023, 101))