I am working with an Arduino and a real time clock chip. The chip compensates for leap years and such, so it will always have the correct date, but it does not handle daylight s
If anyone is looking for this in python, there is a great article here: http://code.activestate.com/recipes/425607-findng-the-xth-day-in-a-month/
It contains the following code:
from calendar import monthrange
def dow_date_finder(which_weekday_in_month=FIRST,day=MONDAY,month=JANUARY,year=2000):
bom, days = monthrange(year, month)
firstmatch = (day - bom) % 7 + 1
return xrange(firstmatch, days+1, 7)[which_weekday_in_month]
Keep in mind that you need to have all of the variables present from the top of the page at the link above to make it more user-friendly.
The below is good for any year 2007 or later:
def find_dt_of_daylight_savings_time(yr=date.today().year):
dst = {}
spring = dow_date_finder(SECOND, SUNDAY, MARCH, yr)
spring_dt = datetime(int(yr), 3, spring, 3, 0)
dst['spring'] = spring_dt
fall = dow_date_finder(FIRST, SUNDAY, NOVEMBER, yr)
fall_dt = datetime(int(yr), 11, fall, 3, 0)
dst['fall'] = fall_dt
return dst