Randy Kramer wrote:
* (I guess this is the furthest off point): There seems to be an at least "semi-official" designation of the weeks in a year--you will find some calendars that number the weeks, and when I've checked, those numbers seem to be consistent between calendars, even made in different countries. (I think the ones I've noticed, some years ago, were calendars from England, Austria, and the US.)
You are probably looking for ISO 8601, which defines the algorithm for computing week numbers.
* Depending on the level of precision I wanted, I might calculate an interval in weeks, then consider 4 1/3 weeks ~= 1 month, 13 weeks ~= 1 quarter, and 52 weeks = 1 year. If I wanted to express some arbitrary number of weeks in months, (e.g., 62, I'd divide by 4.34 and round off to the nearest integer and call it that number of months.
If you want an interval to sufficient level of precision, the problem is insoluble.
Suppose you want 1 second precision. Well, unfortunately civil calendars have leap seconds, and the moments at which leap seconds will need to occur are not defined far in advance. So DateTime(2020-01-01) minus DateTime(2000-01-01) can't be calculated to an exact number of seconds.
This is one reason why epoch dates are a very bad idea--it means that when a leap second is declared, you either need to change the meaning of existing data, or ignore it and let your time scale drift.
If I wanted to express that in weeks, I guess my two choices would be to use the semi-official designation of weeks (first bullet above) and get the number of weeks by the difference in week numbers, and then depending on the days of the week, approximate it to the nearest 1/2 (or actual number of days).
I've a hunch that would lead to 'unexpected' results, because as per the standards some years have 53 weeks: the first week of 2004 started in 2003, and the last week of 2004 ended in 2005.
Or, calculate the actual difference in days, then divide by 7, call that weeks, and the remainder in days (or rounded off to, say, 1/2 week.
Well, the question is really what someone means when they say something will take an interval of a certain number of weeks. If it's Thursday 1st and I say something will take 2 weeks, I mean it'll take until Thursday 15th. I don't mean it'll take until Monday 19th (or Sunday 18th, depending on whether you think weeks begin on Sunday or Monday...)
I claim that most people who talk about durations in weeks mean "days divided by 7", without regard to whether the duration starts or ends on a week boundary.
(I've been writing calendar software for a sizeable chunk of my career. It's very hard to get right.)
mathew
···
--
<URL:http://www.pobox.com/~meta/>
WE HAVE TACOS