Thanks for pointing out that thread. I agree with your comment in the referenced post that it would be good to include a weeknumber verb in the dates script.
---R.E. Boss wrote: > See also > http://www.jsoftware.com/pipermail/general/2004-December/019725.html > > > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Namens Sherlock, Ric > I'm assuming that by day_number is the day of the year rather > than "day > number" as defined in the dates script. > > Here's a go at the simple one: > yearmonth=: [: 2&[EMAIL PROTECTED] todayno@(,&1 1)@{. + <:@{: > yearmonth 2008 31 > 2008 1 > yearmonth 2008 32 > 2008 2 > yearmonth 2008 60 > 2008 2 > yearmonth 2009 60 > 2009 3 > > >From http://en.wikipedia.org/wiki/Week#Week_number it seems > there are a > number of different ways of determining week number. > The following prototype of a yearweek verb follows the ISO > rules. I imagine > the logic could be simplified a bit though!! > > yearweek=: 3 : 0 > 'yr daynum'=. y > b=. 7| _1+yr+-/<.4 100 400%~<:yr > md=. 28+3,(~:/0=4 100 400|yr),10$5$3 2 > wks=. _7]\(-b)|. (7*53) {. >:i.+/md > wk=. I. daynum e."1 ] wks > if. (wk=52)*. 3 > 0 i:&1@:< {:wks do. > wk=. 1 > yr=. >:yr > else. > if. b>3 do. NB. adjust for first week > if. wk = 0 do. > 'yr wk'=. yearweek (<:yr),365 > end. > else. NB. > wk=. >:wk > end. > end. > yr,wk > ) > yearweek 2010 1 > 2009 53 > yearweek 2010 8 > 2010 1 > yearweek 2006 365 > 2006 52 > yearweek 2006 1 > 2005 52 > > ---david alis wrote: > > I need two conversion verbs: > > (year,day_number) into (year,week_number) > > for example - (2010,1) -> (2009,53) > > (1.Jan.2010 is in Week 53 of 2009) > > > > and the simpler: > > (year, day_number) into (year, month_number) ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
