Skip to content

Instantly share code, notes, and snippets.

@takumiirie
Created March 8, 2018 09:36
Show Gist options
  • Save takumiirie/09a8903918d141318dfce0352581cb01 to your computer and use it in GitHub Desktop.
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
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