-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstardate.py
119 lines (95 loc) · 3.64 KB
/
stardate.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
import math
from dateutil.parser import parse
from datetime import datetime
import sys
import argparse
import time
class StarDate:
verbose = False
date = None
stardate = None
def __init__(self, date=None, verbose=False):
if self.verbose:
print("---Initializing---")
self.date = date
self.verbose = verbose
def setDate(self, date):
self.date = date
def to_seconds(self, date):
return time.mktime(date.timetuple())
def getStardate(self):
if self.date != None:
stardateRequested = parse(self.date)
else:
stardateRequested = datetime.now()
stardateOrigin = parse("1987-07-15T00:00:00-00:00")
if self.verbose:
print("Start Date : " + stardateRequested.strftime("%Y-%m-%d %H:%M:%S"))
print("Origin Date : " + stardateOrigin.strftime("%Y-%m-%d %H:%M:%S"))
print("---------------------")
if self.verbose:
year = stardateRequested.strftime("%Y")
month = stardateRequested.strftime("%m")
day = stardateRequested.strftime("%d")
hour = stardateRequested.strftime("%H")
minutes = stardateRequested.strftime("%M")
seconds = stardateRequested.strftime("%S")
print("Year : " + year)
print("Month : " + month)
print("Day : " + day)
print("Hour : " + hour)
print("Minutes : " + minutes)
print("Seconds : " + seconds)
print("---------------------")
self.stardate = self.to_seconds(stardateRequested) - self.to_seconds(stardateOrigin)
self.stardate = self.stardate / (60.0 * 60.0 * 24.0 * 0.036525)
self.stardate = math.floor(self.stardate + 410000.0)
self.stardate = self.stardate / 10.0
if self.verbose:
print("Selection Date - Origin Date = " + str(self.stardate))
print("---------------------")
print("Previous Value / (60.0 * 60.0 * 24.0 * 0.036525) = " + str(self.stardate))
print("---------------------")
print("Floor(Previous Value + 410000.0) = " + str(self.stardate))
print("---------------------")
print("Previous Value / 10.0 = " + str(self.stardate))
print("---------------------")
if self.verbose:
print()
print("Stardate Final : " + str(self.stardate))
return self.stardate
def main(self):
try:
parser = argparse.ArgumentParser()
parser.add_argument(
"-v",
"--verbose",
help="if you want to see more variables and the calculation process",
action="store_true",
)
parser.add_argument(
"-d",
"--date",
help="Enter the date to convert to stardate, format YYYY-MM-DD",
metavar="D",
type=str,
default=None,
)
args = parser.parse_args()
self.verbose = args.verbose
self.date = args.date
if self.verbose:
print("Argument Verbose : " + str(self.verbose))
if self.date != None:
print("Argument Date : " + self.date)
else:
print("Argument Date : " + datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print()
self.getStardate()
except SystemExit:
e = sys.exc_info()[0]
# if(self.verbose):
print(e)
if __name__ == "__main__":
starDate = StarDate()
starDate.main()