Created
March 8, 2018 09:36
-
-
Save takumiirie/09a8903918d141318dfce0352581cb01 to your computer and use it in GitHub Desktop.
dealing with str to date time when date time is over 24:00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def midnightConverter(*, year, month, day, hours, minutes): | |
totalMin = int(hours)*60 + int(minutes) | |
diff = divmod(totalMin,1440) | |
if diff[0] >= 0: | |
deltaMin = timedelta(minutes=totalMin) | |
baseDate = datetime( | |
year=int(year), | |
month=int(month), | |
day=int(day), | |
hour=0, | |
minute=0 | |
) | |
result = baseDate + deltaMin | |
return result | |
else: | |
result = datetime( | |
year=int(year), | |
month=int(month), | |
day=int(day), | |
hour=int(hours), | |
minute=int(minutes) | |
) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment