forked from geerlingguy/pi-timelapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
44 lines (35 loc) · 962 Bytes
/
test.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
from datetime import datetime
import os
import sys
d = datetime.now()
print ("Now: {}".format(d))
f = d.strftime('%Y%m%d%H%M%S')
print ("Format: {}".format(f))
t = d.timetz()
print ("Time: {}".format(t))
h = t.hour
print ("Hour: {}".format(h))
m = t.minute
print ("Minute: {}".format(m))
# Format must be 24 hrs
enableTimeframe = True
startHour = 6
startMinute = 30
endHour = 20
endMinute = 0
def isLapseTimeValid():
now = datetime.now().timetz()
def isStartTimeValid():
if startHour == now.hour:
return startMinute <= now.minute
else:
return startHour < now.hour
def isEndTimeValid():
if now.hour == endHour:
return now.minute <= endMinute
else:
return now.hour < endHour
return not enableTimeframe or (enableTimeframe and isStartTimeValid() and isEndTimeValid())
print ("isLapseTimeValid: {}".format(isLapseTimeValid()))
print (".", end = "")
print (".")