-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdst.py
More file actions
19 lines (14 loc) · 737 Bytes
/
dst.py
File metadata and controls
19 lines (14 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
""" dst.py : calculates time based on current dst """
import time
def dst_time():
year = time.localtime()[0] #get current year
hh_march = time.mktime((year, 3, (14-(int(5*year/4+1))%7), 1, 0, 0, 0, 0, 0)) #Time of March change to DST
hh_november = time.mktime((year, 10, (7-(int(5*year/4+1))%7), 1, 0, 0, 0, 0, 0)) #Time of October change to EST
now = time.time()
if now < hh_march: # we are before last sunday of march
dst = time.localtime(now-21600) # EST: UTC-5H
elif now < hh_november: # we are before last sunday of october
dst = time.localtime(now-18000) # DST: UTC-4H
else: # we are after last sunday of october
dst = time.localtime(now-21600) # EST: UTC-5H
return dst