Go - Unix timestamp for first day of the week from ISO year week -


what's way of getting timestamp for, say, monday 00:00:00 fifth week of 2010? i'm looking inverse function isoweek in time package. can't seem find way achieve that. parse() doesn't read week, , counting how many "7 days" there have been since first day of year/month doesn't me need.

thanks lot in advance! bill

i don't see why

simply counting how many "7 days" there have been since first day of year/month doesn't me need

here attempt:

func firstdayofisoweek(year int, week int, timezone *time.location) time.time {     date := time.date(year, 0, 0, 0, 0, 0, 0, timezone)     isoyear, isoweek := date.isoweek()     date.weekday() != time.monday { // iterate monday         date = date.adddate(0, 0, -1)         isoyear, isoweek = date.isoweek()     }     isoyear < year { // iterate forward first day of first week         date = date.adddate(0, 0, 1)         isoyear, isoweek = date.isoweek()     }     isoweek < week { // iterate forward first day of given week         date = date.adddate(0, 0, 1)         isoyear, isoweek = date.isoweek()     }     return date } 

here working example sanity check: http://play.golang.org/p/uvfnfcpaoi

the code easy understand, there no year/month/day arithmetic, simple iteration. runtime complexity o(n), given n less 400 - it's not problem @ all.

it should not have problems daylight saving, leap years , other tricky date problems if golang date.adddate implemented correctly.

p.s. funny fact :) first day of week 1 of year 2008 2007-12-31. , correct, can check in calendar.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -