DN = Day Number [Integer: between 1 and 365 or 366]
MY = Month of the Year [Integer: between 1 and 12]
DM = Day of the Month [Integer: between 1 and 31 depending on the Month of the Year and Leap Year]
DIM = Days in Months [Integer: between 1 and 31 depending on the Month of the Year and Leap Year]
Input | Output | Used in | |
---|---|---|---|
Month of Year 001 Day of Month 003 Leap Year 020 |
016 Day Number | Month of Year 030 Day of Month 004 Leap Year 045 |
[Day_Number.py]
def day_number(month_of_year, day_of_month, Leap_Year=False):
days_in_previous_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month_start_day = days_in_previous_month[0]
j = month_of_year
if Leap_Year == True:
days_in_previous_month[2]= 29
else:
None
if month_of_year < 1 or month_of_year > (len(days_in_previous_month)-1):
return "Error - month must be an integer between 1 and " \
+ str(len(days_in_previous_month)-1)
else:
if day < 1 or day > days_in_previous_month[j]:
return "Error - day in month " + str(j) \
+ " must be an integer between 1 and " \
+ str(days_in_previous_month[j])
else:
for k in range(0, j):
month_start_day = month_start_day + days_in_previous_month[k]
return month_start_day + day_of_month