Skip to content

Instantly share code, notes, and snippets.

@shymonk
Last active April 24, 2017 08:28
Show Gist options
  • Save shymonk/bfd8a4299c15ef1307f8f2e4fd110444 to your computer and use it in GitHub Desktop.
Save shymonk/bfd8a4299c15ef1307f8f2e4fd110444 to your computer and use it in GitHub Desktop.
dayOfYear
#!/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