-
Notifications
You must be signed in to change notification settings - Fork 0
/
W40KCalendarCalc.py
123 lines (98 loc) · 4.55 KB
/
W40KCalendarCalc.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#Jesse A. Jones
#Version: 2023-06-13.10
from tkinter import *
import leapDetect
import datetime
import metricTime
import dateHandling
#Calculates imperial date from input date and time.
class FortyKCalendarCalc(object):
""" THE EMPEROR PROTECTS """
def __init__(self, window = None):
self.window = window
#Holds quit button.
self.frameTop = Frame(self.window)
self.frameTop.pack(side = TOP)
#Quits program when clicked.
self.quitButton = Button(self.frameTop, text = "Quit",
font = "Ariel 20", command = self.quitButtonAction)
self.quitButton.pack()
#Holds input fields, conversion button, and calendar output.
self.frameBottom = Frame(self.window)
self.frameBottom.pack(side = BOTTOM)
FONT = "Ariel 20"
#Year input field.
self.messageI = Label(self.frameBottom, text = "Enter year:", font = FONT, anchor = "w")
self.messageI.grid(row = 0, column = 0)
self.year = Entry(self.frameBottom, font = FONT)
self.year.grid(row = 0, column = 1)
#Month input field.
self.messageII = Label(self.frameBottom, text = "Enter month:", font = FONT, anchor = "w")
self.messageII.grid(row = 2, column = 0)
self.month = Entry(self.frameBottom, font = FONT)
self.month.grid(row = 2, column = 1)
#Day input field.
self.messageIII = Label(self.frameBottom, text = "Enter day:", font = FONT, anchor = "w")
self.messageIII.grid(row = 3, column = 0)
self.day = Entry(self.frameBottom, font = FONT)
self.day.grid(row = 3, column = 1)
#Hour input field.
self.messageIV = Label(self.frameBottom, text = "Enter hour (UTC):", font = FONT, anchor = "w")
self.messageIV.grid(row = 4, column = 0)
self.hour = Entry(self.frameBottom, font = FONT)
self.hour.grid(row = 4, column = 1)
#Minute input field.
self.messageV = Label(self.frameBottom, text = "Enter minute (UTC):", font = FONT, anchor = "w")
self.messageV.grid(row = 5, column = 0)
self.minute = Entry(self.frameBottom, font = FONT)
self.minute.grid(row = 5, column = 1)
#Calculates imperial date stamp based
# on input date and time when pressed.
self.convButton = Button(self.frameBottom, text = "Convert",
font = FONT, command = self.displayCal)
self.convButton.grid(row = 6, column = 0)
#Displays imperial date output.
self.tOutput = Label(self.frameBottom, text = "",
font = "Ariel 30")
self.tOutput.grid(row = 6, column = 1)
#Used in detecting leap years, parsing input date
# and time, and finding day number of year.
self.leap = leapDetect.IsLeap()
self.dateHandle = dateHandling.GetDate()
self.metric = metricTime.MetricTime()
#Quits program when called.
def quitButtonAction(self):
self.window.destroy()
#Calculates and displays imperial calendar based on input date.
def displayCal(self):
#Fetches input date.
year = self.dateHandle.getYear(self.year.get())
month = self.dateHandle.getMonth(self.month.get())
day = self.dateHandle.getDay(self.day.get())
hour = self.dateHandle.getHour(self.hour.get())
minute = self.dateHandle.getMinOrSec(self.minute.get())
self.tOutput["text"] = self.calc40K(year, month, day, hour, minute, 0)
#Caclulates current imperial date stamp and displays it.
def calc40K(self, year, month, day, hour, minute, second):
isLeap = self.leap.isLeapYear(year)
#Finds number of days elapsed in decimal form.
dayNum = self.metric.findDayNumOfYear(year, month, day)
dayDec = ((hour * 3600) + (minute * 60) + second) / 86400
dayNumDec = (dayNum - 1) + dayDec
#Calculates year fraction based on input.
yearFrac = str(int((dayNumDec / (365 + isLeap)) * 1000)).zfill(3)
#Finds century portion of year, i.e. 2023 gives 023.
centuryStamp = (str((year % 1000)).zfill(3))
#Calculates current millennium in ordinal form
# so it's currently M03 becasue
# it's the 3rd millennium of the common era.
milleniumOrd = str(((year // 1000) + 1)).zfill(2)
#Returns Imperial time stamp.
return f"0 {yearFrac} {centuryStamp}.M{milleniumOrd}"
def main():
root = Tk()
root.title("Warhammer 40K Imerial Calendar Calculator")
metric = FortyKCalendarCalc(root)
root.mainloop()
if __name__ == "__main__":
main()