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

Number : 4468 Date : 2003-04-28 Author : Kan Yabumoto Subject : Re: Date Macro Size(KB) : 2
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. 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. 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.... Kan Yabumoto
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.