JDManipulator.py
3.59 KB
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
from django.conf import settings
import datetime
import time
from decimal import *
JD_VALUE = 86400
TIMESTAMP_JD = 2440587.500000
DAILY_SECOND = 1 / 86400
SECOND_DIV = 86400
def getSimTime():
current_time = datetime.datetime.now()
if current_time.minute == 59:
current_time = current_time.replace(hour=(current_time.hour + 1), minute=0, second=10)
else:
if current_time.second >= 50:
current_time = current_time.replace(minute=current_time.minute + 1, second=10)
else:
current_time = current_time.replace(second=(current_time.second + 10))
return (time.mktime(current_time.timetuple()))
SIM_TIME_START = getSimTime()
def JulianSeconds(value):
return (Decimal(value) / SECOND_DIV)
def getPreciseCurrentTime():
return (Decimal(getCurrentTime()))
def getPreciseNightStart():
return (Decimal(getNightStart()))
def getPreciseNightEnd():
return (Decimal(getNightEnd()))
def secondsToJulianDate(time_seconds):
return (time_seconds / 86400 + TIMESTAMP_JD)
def secondsToPreciseJulianDate(time_seconds):
return (Decimal(time_seconds) / 86400 + Decimal(TIMESTAMP_JD))
def julianSecondsToSeconds(seconds_julian):
return seconds_julian * 86400
def julianDateToSeconds(time_julian):
return ((time_julian - TIMESTAMP_JD) * 86400)
def getCurrentTime():
current_time = datetime.datetime.now()
return (time.mktime(current_time.timetuple()))
def getNextDefaultNightStart():
current_time = datetime.datetime.now()
if (current_time.hour >= 18):
current_time += datetime.timedelta(days=1)
current_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0)
return (time.mktime(current_time.timetuple()))
def getNextDefaultNightEnd():
current_time = datetime.datetime.now()
if (current_time.hour >= 18):
current_time += datetime.timedelta(days=2)
else:
current_time += datetime.timedelta(days=1)
current_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0)
return (time.mktime(current_time.timetuple()))
def getDefaultNightStart():
current_time = datetime.datetime.now()
print("*********************")
print("*********************")
print("current time is", current_time)
print("SIM_TIME_START", SIM_TIME_START)
print("*********************")
print("*********************")
if settings.SIMULATOR:
if settings.SIMULATOR:
return SIM_TIME_START
if current_time.minute == 59:
current_time = current_time.replace(hour=(current_time.hour + 1), minute=0, second=10)
else:
if current_time.second > 50:
current_time = current_time.replace(minute=current_time.minute + 1, second=10)
else:
current_time = current_time.replace(second=(current_time.second + 10))
else:
current_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0)
return (time.mktime(current_time.timetuple()))
def getDefaultNightEnd():
current_time = datetime.datetime.now()
current_time += datetime.timedelta(days=1)
current_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0)
return (time.mktime(current_time.timetuple()))
def datetimeToJulianDate(current_time):
return (time.mktime(current_time.timetuple()) / JD_VALUE + TIMESTAMP_JD)
''' TODO '''
def getNightStart():
return (getDefaultNightStart())
''' TODO '''
def getNightEnd():
return (getDefaultNightEnd())
''' TODO '''
def getNextNightStart():
return (getNextDefaultNightStart())
''' TODO '''
def getNextNightEnd():
return (getNextNightEnd())