[<<]Message[>>]    [<<]Author[>>]    [<<]Subject[>>]    [<<]Thread[>>]

Number : 4493 Date : 2003-05-01 Author : Garry Deane Subject : Re: Date Macro Size(KB) : 3
--- In xxcopy@yahoogroups.com, Kan Yabumoto wrote: > Thanks Garry and Chuck for your pointers. But, I was > busy coding my own. As to Garry's comments on the mess > with the partial week problem, it does not apply to XXCOPY's > situation. That is, at this point, the macro always > converts from the date value (which originates yyyy-mm-dd) > to kk value. Therefore, for the date 2003-01-01, > /$yyyy-wkk-k$ will always be expanded to 2003-W01-2 even > though it could be also written as 2002-W53-2, we need not > give the option. No, this is incorrect. 2003-W01-2 (2003-12-31) is not equivalent to or an alternate form of 2002-W53-2. Every calendar day has a unique ISO designation. > Here's my code: > > I often use the unix timevalue as a convenient standard even in > the Microsoft environment. So, the current time is already > available as unix-time and unix-date was obtained by (unix_time > / 86400L). > I don't normally put this many comments but this function really > needs extra comments for me to ever go back to it. I used to > code in much more convoluted way for efficiency and "cleverness". > But, lately, as I age, I tend to use more straightforward coding > with ample intermediate values which make it easier to follow for > later revisions. > > -------------------------------------------------------------- > > ushort udate2wkno( // Iso week number of the year (1st wk = 01) > ulong udate) // unix date (relative to 1970-01-01) > { > ulong ydate; // date index of the year (Jan 1st is always 0) > ulong jan1; // day of the week of Jan1 of the year > > // this scheme uses a 4-yr cycle which puts a leap year as the 4th yr of > // the 4-yr cycle. The first 4-yr cycle therefore is 1969-1972 > // note that the ISO 8601 std defines that a week starts on Mon, ends Sat. This fails to take account of some years having 52 weeks and others having 53 weeks (because a calendar year is not exactly 52 weeks). A 4 year cycle takes account of leap years but not 53 week years. Since each year has an average of 365.25 days (ignoring non-leap years at the turn of the century) with 52.1786 weeks, the cycle needs to be 28 years. > > udate += 365; // date index relative to 1969-01-01 > ydate = udate % 1461; // 1461 = 365 * 4 + 1; > ydate = (ydate == 1460) ? 365 : (ydate % 365); > jan1 = (udate - ydate + 2) % 7; / day of the week of jan1 > return((ushort)(((ydate + jan1) / 7) + 1)); // week number of the year > } > ---------------------------------------------------------------- > > This ISO-8601 thing was added just as an individual who strongly > supports the standard. However, I don't expect this feature to > be used widely. It's there for the sake of completeness; not more > than anything else. For the same reason, I decided to retain the > original /$W$ definition as it was. > > The revised macro feature is posted at XXTB #24 > > http://www.xxcopy.com/betatest/xxcopy24.htm > > It is now posted at > > http://www.xxcopy.com/betatest/ (v.2.84.1) > > See if anyone can find a bug in the new macros.... The ISO week number macro gives the wrong week no for all weeks of the year when Jan 1 is in the last week of the previous year. It also gives the wrong week for Dec 29, 30, 31 when they are in week 1 of next year e.g. date ISO date Xxcopy \$yyyy-wkk-k$ 2000-01-01 1999-W52-6 2000-W01-6 2000-01-08 2000-W01-6 2000-W02-6 2001-12-31 2002-W01-1 2001-W53-1 Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.