time - Python get summertime breakpoints -


i new in python, think easy problem. parsing through txt log file: timestamp value, timestamp value, , on...

i saving data in database utc time because otherwise there 1 hour each year have 2 values per timestamp (the hour when switch summer- wintertime).

my question is, how can timestamp last sunday in march? tried this:

x = 2014 ts_raw = x, 3, 31 - int(time.strftime("%w", (x, 3, 31, 0, 0, 0, 0, 0, 0))), 2, 0, 0, 0, 0, 0 ts = time.mktime(ts_raw) 

doesn't elegant , doesn't work too... because part:

time.strftime("%w", (x, 3, 31, 0, 0, 0, 0, 0, 0)) 

this returns 1...

i think there must better way this... please can post few lines of code?

this may not concise solution, citing zen of python: explicit better implicit.

from datetime import date, timedelta import calendar import time  last = date(2014, 3, 31) delta = (last.weekday() - calendar.sunday) % 7 lastsunday = last - timedelta(days=delta)            # 2014-03-30 print time.mktime(lastsunday.timetuple()) 

here calendar march 2014.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -