Skip to content

Commit

Permalink
Merge pull request #49 from physprop/main
Browse files Browse the repository at this point in the history
Added a function to detect and correct for leap years
  • Loading branch information
physprop authored Jun 26, 2024
2 parents 2f7c2ef + 7dcfe25 commit 095791a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion asmara.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
# Standard Library
from datetime import datetime as DT
from datetime import timezone as TZ
from datetime import timedelta as timedelta
from json import dump, load
from multiprocessing import Process, active_children
from os import getcwd, path, remove, walk
Expand Down Expand Up @@ -32,6 +34,7 @@
from pydub.generators import Sine
from pydub.utils import make_chunks, mediainfo
from requests import get, exceptions
from calendar import isleap

# First-Party
from utilities import utilities, severity
Expand Down Expand Up @@ -321,7 +324,20 @@ def __decoder__(self):
x = DT.strptime(
decode.split("-")[-3], "%j%H%M"
)
expiryOffset = 0
timeStamp = decode.split("-")[-4].split("+")[1]
currDate = DT.now(TZ.utc)
currYear = currDate.today().year
leapDate = f"2/29/{currYear}"
if isleap(currYear):
if DT.now(TZ.utc).strftime('%Y-%m-%d') > DT.strptime(leapDate,"%m/%d/%Y").strftime('%Y-%m-%d'):
expiryOffset = 86400
elif DT.now(TZ.utc).strftime('%Y-%m-%d') == DT.strptime(leapDate,"%m/%d/%Y").strftime('%Y-%m-%d'):
midnight = (DT.now(TZ.utc) + timedelta(days=1)).replace(hour=0, minute=0, microsecond=0, second=0)
expiryOffset = 86400 - (DT.now(TZ.utc) - midnight).seconds
print(expiryOffset)
else:
expiryOffset = 0
startTime = mktime(
DT(
DT.utcnow().year,
Expand All @@ -335,7 +351,7 @@ def __decoder__(self):
(int(timeStamp[:2]) * 60) * 60
+ int(timeStamp[2:]) * 60
)
now = mktime(DT.utcnow().timetuple())
now = mktime(DT.utcnow().timetuple()) + expiryOffset
filt = self.__FilterManager__(
headerTranslation.org,
headerTranslation.evnt,
Expand Down

0 comments on commit 095791a

Please sign in to comment.