-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.py
80 lines (63 loc) · 2.01 KB
/
calendar.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import math
## Taken from Incursion
##"Reprise", "Icemelt", "Turnleaf", "Blossom" --spring/summer
## "Suntide", "Harvest", "Leafdry", "Softwind", --summer/fall
## "Thincold", "Deepcold", "Midwint", "Arvester", --fall/winter
calendar_data = [
(30, "Arvester"),
(1, "Midwinter"),
(30, "Reprise"),
(30, "Icemelt"),
(30, "Turnleaf"), # April
(1, "Greengrass"),
(30, "Blossom"), # May
(30, "Suntide"), # June
(30, "Harvest"),
(1, "Midsummer"),
(30, "Leafdry"), # August
(30, "Softwind"),
(1, "Highharvestide"),
(30, "Thincold"),
(30, "Deepcold"), # November
(1, "Year Feast"),
(30, "Midwint") #December
]
MINUTE = 60/10
HOUR = MINUTE*60
DAY = HOUR*24
YEAR = DAY*365
class obj_Calendar():
def __init__(self, year=1370, day=1, hour=8):
self.calendar = []
self.days = 0
for m in calendar_data:
self.days = self.days + m[0]
self.start_year = year
self.start_day = day
self.start_hour = hour
self.turn = 0
def get_time(self, turn):
turn = turn + self.start_hour * HOUR
minute = int(math.floor((turn % DAY) / MINUTE))
hour = int(math.floor(minute / 60))
minute = int(math.floor(minute % 60))
return hour, minute
def get_day(self, turn):
turn = turn + self.start_hour * HOUR
d = int(math.floor(turn / DAY) + (self.start_day))
y = int(math.floor(d / 365))
d = int(math.floor(d % 365))
return d, self.start_year + y
def get_month_num(self,day):
i = len(calendar_data)
while i > 0 and (day < self.days):
i -= 1
return i
def get_month_name(self, day):
month = self.get_month_num(day)
return calendar_data[month][1]
def get_time_date(self, turn):
date, year = self.get_day(turn)
month = self.get_month_name(date)
hour, minute = self.get_time(turn)
return "Today is %s %s of %s DR. The time is %d:%d" % (date, month, year, hour, minute)