more time fixes

This commit is contained in:
Richard Ferguson
2020-05-15 10:51:00 +00:00
parent 8fb5215df2
commit bf2d101d63
2 changed files with 21 additions and 6 deletions

View File

@@ -26,7 +26,8 @@ import threading
class arElement(): class arElement():
def __init__(self): def __init__(self):
self._arName = "%s" % (self.__class__.__name__) self._arName = "%s" % (self.__class__.__name__)
self._arTz = get_localzone() self._arLtz = get_localzone()
self._arTz = self._arLtz
self._arPrintLock = threading.Lock() self._arPrintLock = threading.Lock()
@property @property
@@ -46,12 +47,24 @@ class arElement():
self._arTz = v self._arTz = v
def arGetLocalTime(self): def arGetLocalTime(self):
return self._arTz.localize(dt.datetime.now()) ldt = self._arLtz.localize(dt.datetime.now())
return ldt.astimezone(self._arTz)
def arGetUTCTime(self): def arGetUTCTime(self):
return pytz.utc.localize(dt.datetime.utcnow()) ldt = self._arLtz.localize(dt.datetime.now())
return ldt.astimezone(pytz.utc)
def arPrint(self, message): def arPrint(self, message):
self._arPrintLock.acquire() self._arPrintLock.acquire()
print("[%s] %s" % (self._arName, message)) print("[%s] %s" % (self._arName, message))
self._arPrintLock.release() self._arPrintLock.release()
if __name__ == "__main__":
e = arElement()
print(e.arGetLocalTime().strftime("%c"))
print(e.arGetUTCTime().strftime("%c"))
e.arTz = pytz.timezone("US/Eastern")
print(e.arGetLocalTime().strftime("%c"))
print(e.arGetUTCTime().strftime("%c"))

View File

@@ -41,7 +41,7 @@ def td2min(td):
return round(res) return round(res)
class arNet(arElement, threading.Thread): class arNet(arElement, threading.Thread):
def __init__(self, call, txCB): def __init__(self, call, txCB, tz = None):
arElement.__init__(self) arElement.__init__(self)
self._day = 0 # sunday self._day = 0 # sunday
@@ -58,6 +58,8 @@ class arNet(arElement, threading.Thread):
self._lon = "00000.00W" # longitude self._lon = "00000.00W" # longitude
self._comment = "" # comment self._comment = "" # comment
if tz is not None:
self.arTz = tz
self._dt = self.arGetLocalTime() self._dt = self.arGetLocalTime()
self._stopped = threading.Event() self._stopped = threading.Event()
@@ -283,6 +285,7 @@ class arNet(arElement, threading.Thread):
# initialize _dt to next future net time # initialize _dt to next future net time
# unless net is currently active # unless net is currently active
self._dt = self.arGetLocalTime()
dayshift = self._day - self._dt.weekday() dayshift = self._day - self._dt.weekday()
if dayshift < 0: if dayshift < 0:
dayshift += 7 dayshift += 7
@@ -522,7 +525,7 @@ class arNetSked(arElement):
# print (line) # print (line)
line = line.ljust(75) line = line.ljust(75)
objn = arNet(self.call, self.tranPacketCB) objn = arNet(self.call, self.tranPacketCB, self.arTz)
opts = line.split() opts = line.split()
try: try:
objn.day = opts[0] objn.day = opts[0]
@@ -547,7 +550,6 @@ class arNetSked(arElement):
break break
self._objlist.append(objn) self._objlist.append(objn)
objn.arTz = self.arTz
objn.initTime() objn.initTime()
objn.start() objn.start()