Last active
April 24, 2017 08:28
-
-
Save shymonk/bfd8a4299c15ef1307f8f2e4fd110444 to your computer and use it in GitHub Desktop.
dayOfYear
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf-8 | |
import operator | |
def dayOfYear(year, month, day): | |
# we suppose input is always correct | |
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0): | |
monthDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
else: | |
monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
return reduce(operator.add, monthDays[:month - 1]) + day if month > 1 else day | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment