Talk:ISO week date

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Time (Rated C-class, Mid-importance)
WikiProject icon This article is within the scope of WikiProject Time, a collaborative effort to improve the coverage of Time on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
C-Class article C  This article has been rated as C-Class on the project's quality scale.
 Mid  This article has been rated as Mid-importance on the project's importance scale.
 

This article has comments here.

WikiProject Time assessment rating comment[edit]

Nearly a B.

Want to help write or improve articles about Time? Join WikiProject Time or visit the Time Portal for a list of articles that need improving.
Yamara 18:18, 14 February 2008 (UTC)

Discussion[edit]

Ok, I understand now "What if most years had a leap week?". What matters for the maximum change of corresponding equinoxes between two years is the largest deviation of a year from the average year.--Patrick 21:38, 30 May 2006 (UTC)

Lede[edit]

I would situate the following sentence at the beginning: The first week of a year is the week that contains the first Thursday of the year. It is also (equivalently) the week containing the 4th day of January.

Everybody looks for that information and has to read half a page to get to it.

Currently prior we talk about iso. Well, that´s scientific correct, but I think people look for a trivial explanation first and than for the scientific one. My opinion of course br hans.stangl@gmx.at --194.113.154.132 (talk) 08:15, 26 February 2014 (UTC)

Huh? It’s in the lede, after all, not buried in some section. Also, not every read of this article is primarily looking for that piece of information. Nevertheless, I rearranged and rephrased the introduction today and the Thursday rule moved up a bit. — Christoph Päper 20:10, 26 February 2014 (UTC) Yes check.svg Done

Use of term "Leap Week"[edit]

I have seen ISO 8601:2000 but not ISO 8601:2004. ISO 8601:2000 does not use the term "leap week"; I don't know whether ISO 8601:2004 does.

Unless the term is introduced in ISO 8601:2004, it seems to me unwise to introduce it elsewhere; "week 53" suffices. It leads to using "leap year" for 53-week years, which clashes with conventional use. It might be thought to mean a week containing February 29th.

Re section "Disadvantages" : The ISO Week Calendar could fully replace the Gregorian, because it is possible to calculate Day 1 of a given year directly - but the expression will be more complicated.

Re section "Advantages" : Although the date of Easter Sunday would be no easier to calculate, the number of possible dates would be less, since all are Day 7. Only a few Week Numbers would be possible. 82.163.24.100 13:45, 30 January 2007 (UTC)

Only six Week Numbers, 12-17 would be possible, 17 being rare. 82.163.24.100 22:19, 3 February 2007 (UTC)


ISO 8601:2004 does not use "leap week". It does use "leap year", but in the common sense of a year with 366 days; accordingly, "leap year" should not be used to refer to an ISO year of 53 weeks.

Library routines purporting to convert other forms of date into ISO week dates should be viewed with caution; errors are known to occur, for example with 2007-12-31.

There is only ONE definition of Week 01; it is in ISO 8601:2004 2.2.10, and uses 'first Thursday' (and see 3.2.2 note 3). The others are mere equivalent consequential descriptions.

82.163.24.100 10:52, 26 May 2007 (UTC)

Yes check.svg Done

The page now mostly uses long year to refer to years with 53 weeks. — Christoph Päper 18:22, 9 August 2010 (UTC)

Templates[edit]

* [[Template:ISOWEEKDATE]] - {{evd|ISOWEEKDATE|2010|01|03}} The opposite function of {{tl|ISOWEEKDATE2YMD}}
:* [[Template:ISOYEAR]] - {{evd|ISOYEAR|2010|01|03}}
:* [[Template:ISOWEEK]] - {{evd|ISOWEEK|2010|01|03}}
:* [[Template:ISOWEEKDAY]] - {{evd|ISOWEEKDAY|2010|01|03}}
* [[Template:ISOWEEKDATE2YMD]] - {{evd|ISOWEEKDATE2YMD|2009|53|7}} The opposite function of {{tl|ISOWEEKDATE}}
:* [[Template:ISOWEEKDATE2Y]] - {{evd|ISOWEEKDATE2Y|2009|53|7}}
:* [[Template:ISOWEEKDATE2M]] - {{evd|ISOWEEKDATE2M|2009|53|7}}
:* [[Template:ISOWEEKDATE2D]] - {{evd|ISOWEEKDATE2D|2009|53|7}}
(unsigned date unknown)

Use the {{#time}} parser function instead. JIMp talk·cont 07:26, 1 June 2012 (UTC)

These are to be deleted. JIMp talk·cont 23:35, 4 June 2012 (UTC)

Disadvantage question[edit]

I don't get this part: "It cannot replace the Gregorian calendar, because it relies on it to define the new year day (Week 1 Day 1)."

Is what you want to say that if it coexists with the Gregorian Calendar then it has to be decided which one of them that tells when to celebrate new year's eve since the days for a new year differs?

I can see no logical reason to why new year couldn't be defined as Week 1 Day 1. I mean it's pretty much how it is now with the leap days, we don't celebrate the new year on different times on the day even if it supposedly moves approx 6 hours each year.

--Crouz 20:50, 4 November 2007 (UTC)

The Gregorian 400-year cycle is necessary to decide which week and year number the first and last days of a year belong to. That means there is no simple algorithms that decides whether a week-year has a 53rd week based solely on the year number. — Christoph Päper 18:22, 9 August 2010 (UTC)

Yes check.svg Done

Poor wording (in the article, not yours). It's intended to co-exist with the Gregorian calendar rather than replace it. To decide whether the year has 53 weeks you refer to the Gregorian calendar. If we wanted to replace the Gregorian calendar, a simpler algorithm would be preferable. JIMp talk·cont 07:34, 1 June 2012 (UTC)

Algorithms[edit]

Having seen the rubbishy code of two major software suppliers, and noting that the recent products of one have code which is not only bloated but wrong, I think that adding something on Algorithms would be justified.

To convert a Gregorian date into an ISO 8601 Week Numbering date Y W D, all that is necessary is to :-

 Determine its Day of Week, D
 Use that to move to the nearest Thursday (-3..+3 days)
 Note the year of that date, Y
 Obtain January 1 of that year
 Get the Ordinal Date of that Thursday, DDD of YYYY-DDD
 Then W is 1 + (DDD-1) div 7

or very similar.

Observe that there is no need to consider any special cases.

Here are well-tested Delphi routines for the comversions of a TDateTime (Local daycount from 1899-12-30 00:00:00 = 0.0) to and from Y W D form :-

procedure ISODTtoYWD(const DT : TDateTime ; out YN, WN, DN : word) ;
var X : word ; NThu, Jan1 : TDateTime ;
begin // The canonical version.
  DN := 1 + (DayOfWeek(DT)+5) mod 7 { DT : Mon=1 to Sun=7 } ;
  NThu := Trunc(DT) + 4 - DN { NThu is the Nearest Thursday } ;
  DecodeDate(NThu, YN, X, X) { get Year Number of NThu } ;
  Jan1 := EncodeDate(YN, 1, 1) { January 1 of YN } ;
  WN := 1 + Trunc(NThu-Jan1) div 7 { Count of Thursdays } ;
  end {ISODTtoYWD} ;
function ISOYWDtoDT(const YN, WN, DN : word) : TDateTime ;
var DT : TDateTime ; DW : integer ;
begin // The canonical version.
  DT := EncodeDate(YN, 1, 4) { YN Jan 4, which is in YN Week 1 } ;
  DW := 1 + (DayOfWeek(DT)+5) mod 7 { DT : Mon=1 to Sun=7 } ;
  DT := DT - DW { DT to day before Week 1 } ;
  Result := DT + (WN-1)*7 + DN { increment for Weeks and Days } ;
  end {ISOYWDtoDT} ;

A slight speed-up is possible, at the expense of clarity.

Javascript versions are in http://www.merlyn.demon.co.uk/weekcalc.htm .

82.163.24.100 (talk) 21:19, 19 March 2008 (UTC)

Here is a C# .NET implementation. I've tested it against all of the test cases, and it passes.

   public class ISO_Week {
       public int year;
       public int week;
       public int dayOfWeek;
       public ISO_Week(DateTime dt)
       {
           if (CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek != DayOfWeek.Monday) throw new NotImplementedException("This only works for cultures with Monday as the first day of the week.");  —Preceding unsigned comment added by 194.28.249.49 (talk) 06:29, 20 April 2011 (UTC) 
           dayOfWeek = 1 + ((int)dt.DayOfWeek + 1+5) % 7; // Mon=1 to Sun=7
           DateTime NearestThu = dt.AddDays(4 - dayOfWeek);
           year = NearestThu.Year;
           DateTime Jan1 = new DateTime(year, 1, 1);
           TimeSpan ts = NearestThu.Subtract(Jan1);
           week = 1 + ts.Days / 7; // Count of Thursdays 
       }
   }

--19:51, 24 February 2010 71.141.227.160

I'm not sure I understand this algorithm. Take today's date, Wednesday 18 May 2011. The nearest Thursday is 19 May 2011. 1 January 2011 was a Saturday, and the Thursday of that week was 30 December 2010, ordinal day 364. Then W = 1 + (363 div 7) equals 52. But that can't be right. What am I doing wrong? AD ASTRA SCIENTIA (talk) 02:25, 19 May 2011 (UTC)
The year of Thursday 19 May 2011 is 2011. In 2011, 19 May is ordinal day 139. The week is 1+(139-1)/7=20 . −Woodstone (talk) 03:40, 19 May 2011 (UTC)



Using calculations based on a linear scale like the Rata Die number can be more useful in programming. If we want to calculate the Rata Die of a ISO week date we can use the relation to the Gregorian calendar and write the following Python code:

   def isocal_date2rdn2(y,w,d):
       y -= 1
       ew = (y*365 + y//4 - y//100 + y//400 + 3) // 7
       return (ew + w - 1) * 7 + d

Here y, w, d are year, week and day-of-week of the ISO week calendar date. It is important to understand that Python's '//' operator implements floor division, which is important if one of the quantities involved leaves the nominal range and becomes negative.

The algorithm is rather simple: It uses the Gregorian calendar to get the number of days elapsed since the begin of the Christian Era (0001-01-01) and converts this number in a rounding manner to the number of elapsed weeks ('ew') for the begin of the year in the ISO week calendar. Then it adds the number of elapsed weeks in the year and uses the total number of elapsed weeks and the day-of-week to get the Rata Die of the ISO week date.

The reverse operation is a bit more tricky and is based on extensive exploration of the tabulated elapsed weeks for every year of a 400-year cycle. It can be shown that for every century it's possible to plot a cohort of straight lines through the tabulated data in such manner that every line of the cohort is always above the tabulated data and that the difference between the line and the data is always less than 1. Then the conversion from elapsed weeks since begin of a century to the number of elapsed years can be done with a linear transformation of the form

ey = floor(ew * a + b).

Since there is a cohort of possible slopes, one can find integer coefficients a, b and k where

ey = (ew * a + b) // k

'//' again denoting integer floor division. It can further be shown that there is a cohort of slopes common to all 4 centuries. This results in common values for a and k, but the additive constant b has to be chosen differently for every century.

Another observation is that the first, third and last century of a cycle have 5218 weeks, and the the second century has only 5217 weeks. If we apply the proper correction for weeks >= 10435, we can get the elapsed centuries and the weeks in the century through division by 5218.

Plumbing this all together, we yield the following Python code:

   # selected values: a=28 k=1461 b=[15,23,3,11]
   def isocal_rdn2date1(rdn):
       w,d = divmod(rdn-1, 7)
       n,w = divmod(w, 20871) # weeks in 400 years
       c,w = divmod(w + (w >= 10435), 5218) # get century and weeks in century
       y,w = divmod(w * 28 + (15,23,3,11)[c], 1461) # get years in century and scaled weeks in year
       return (n*400 + c*100 + y + 1, (w // 28) + 1, d + 1) # get y,w,d in ISO week calendar

There are of course many coefficient sets for a, k, b0..b3 that yield the desired result; a=157 k=8192 b=[85,131,17,62] has the advantage that the division and modulo operation can be carried out by shift and mask operations in languages like C.

j.perlinger (perlinger-at-ntp-dot-org) 217.81.188.179 (talk) 00:59, 9 December 2011 (UTC)

logic error found[edit]

The definition of the first week in the iso calendar mentions:

Mutually equivalent definitions for week 01 are:

the week with the year's first Thursday in it

the week with January 4 in it

However this cannot be true, for in 2009 they fall on different weeks:

  January 2009
 S  M Tu  W Th  F  S
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

—Preceding unsigned comment added by 192.65.45.20 (talkcontribs)

As mentioned, in this system weeks start with Monday.--Patrick (talk) 23:51, 6 June 2008 (UTC)

Yes check.svg Done

History[edit]

I would like to see a little bit about the calendar's history. When was it first used? And by whom? Who or what agency invented it? For example, the link to years-with-leap-weeks says that the "first" one is 2009. Do they mean the "next" one? Or is the calendar so recent that we haven't had one yet? —Preceding unsigned comment added by MiguelMunoz (talkcontribs) 01:59, 11 July 2008 (UTC)

It's actually fairly similar to some old Nordic/Icelandic calendar variants, which were designed so that each year would contain an integral number of weeks. However, its modern usage seems to have originated in large industrial corporations which planned their production schedules and payrolls around the work-week. AnonMoos (talk) 00:03, 15 December 2008 (UTC)

I would also like to know *specifically* who submitted the standard and also, for religious reasons, specifically why they chose Monday as the first day of the week when the first day of the week has been Sunday for centuries. Is the Catholic Church STILL trying to move Sun's Day to the 7th day of the week? Interesting for the scholastic theologians among us. WebTigers (talk) 17:08, 5 July 2011 (UTC)

Terminology[edit]

The article used Gregorian Year correctly, and used ISO year to mean the yyyy of yyyy-Www-d. But the yyyy of yyyy-mm-dd is also fully defined in ISO 8601, and has priority. Alas, ISO offers no convenient term for the week-numbering year. Therefore, I have changed "ISO year" to "ISO week-numbering year" except where the "week" context was strong enough already.

ISO 8601 says nothing about "leap week". I have changed the article accordingly. While the term is useful in classifying calendars in accordance with which unit they occasionally insert, there has been in the Article a source of possible confusion in using "leap year" to refer to a 53-week year, because its use to refer to a Jan..Dec containing a Feb 29 is so thouroghly established. That may need further attention.

For details, see the History page.

82.163.24.100 (talk) 12:49, 22 September 2008 (UTC)

Yes check.svg Done

Connecting weeks to months[edit]

The ISO standard does not connect weeks to months in any way. The recent addition working this out in great detail is not based on the standard and therefore does not belong in this article. Additionally, whenever for practical purposes (mostly financial) weeks are assigned to months, this is rarely done in the way described. The usual way is to have fixed 4-4-5 or 5-4-4 patterns. The section is not sourced and constitutes clear WP:OR. −Woodstone (talk) 03:37, 27 March 2010 (UTC)

I believe the table and accompanying text to be covered by the “routine calculations” exception to WP:OR, just like the equivalent formulations of the “first Thursday” rule. ISO 8601 doesn’t say anything about “Doomsday” or dominical letter and it doesn’t provide a list of dates with fixed week number, yet this article does.
I certainly won’t object if we included a reference to regular patterns for 13-week quarters, noting that this is the approach taken in practice. — Christoph Päper 11:49, 27 March 2010 (UTC)
It is not a routine calculation, because the formula is not applicable. You forget to mention the sequel in WP:OR "provided ... that the arithmetic and its application correctly reflect the information published by the sources". The ISO standard uses the formula only to define the first week in a year; it does not apply to months. Applying it to months has no base in the standard.
The question if Doomsday and dominical letter are OR as well has no bearing on this issue.
Woodstone (talk) 16:22, 27 March 2010 (UTC)

the first calendar week of a year is that one which includes the first Thursday of that year

—ISO 8601:2004, section 2.2.10
Yes, the text of the standard does not apply the rule to months since it only has to deal with weeks belonging to one year or another. It is, however, obvious that this is just an adapted, narrow formulation of the generic rule that a week belongs to the larger calendar entity (month, quarter, year, century, …) the majority of its 7 days lie within.
I already indicated in an edit summary that I didn’t add this section to promote (nor discourage) such usage, but merely to illustrate the fact that week date and month date don’t align well. I’m now convinced that this should be followed by the conclusion seen taken in real life, namely 13-week quarters with a regular pattern. (I don’t think anyone is actually using the alternative currently, which was 13 “months” of 4 weeks each.) — Christoph Päper 00:59, 28 March 2010 (UTC)
All true, but this article is about the "ISO week" as described in its standard. All else is speculation. You might want to find another article where you can vent those ideas. −Woodstone (talk) 03:41, 28 March 2010 (UTC)
We have ISO 8601 for strictly standard-related stuff. This article can be a bit more relaxed, in my humble opinion, and expand on the effects of (this kind of) week numbering. The table of week-fixed dates already does that. — Christoph Päper 13:17, 28 March 2010 (UTC)
But as far as I can see it is not fact, but speculation. Is there any evidence that organisations are using the shown association of weeks to months? −Woodstone (talk) 13:42, 28 March 2010 (UTC)
Well, that’s not what I’m saying. What I’m saying is, this is what you would get if you applied the same rule to months, but in practice people prefer to use more regular patterns, which are not or at least less related to the traditional months. I refrained from adding the But because we’re still discussing that section. — Christoph Päper 20:54, 28 March 2010 (UTC)

If, however, the rule for first week of the year was applied to Gregorian months the pattern would be irregular. The only 4 months (or 5 in a long year) that would have 5 weeks were those with at least 29 days starting on Thursday, those with 30 or 31 days starting on Wednesday, and those with 31 days starting on Tuesday.

Weeks per month depending on the weekday of 1 January; in leap years adjacent months may switch their week count (“4* 5*”)
1 Jan Mon Tue Wed Thu Fri Sat Sun
Jan 4 5 5 5 4 4 4
Feb 4* 4 4 4 4 4 4
Mar 5* 4 4 4 4* 5 5
Apr 4 4 4* 5 5* 4 4
May 5 5 5* 4 4 4 4*
Jun 4 4 4 4 4* 5 5*
Jul 4 4* 5 5 5* 4 4
Aug 5 5* 4 4 4 4* 5
Sep 4 4 4 4* 5 5* 4
Oct 4* 5 5 5* 4 4 4
Nov 5* 4 4 4 4 4* 5
Dec 4 4 4* 5 5 5* 4
Year 52 52 52* 53 52 52 52

I reverted (again) because you still have not given a reference to show that it is used in a significant real world environment. −Woodstone (talk) 14:30, 9 August 2010 (UTC)

Like I said back in March, I do not see the need to provide such an example. I just had other things to do at the time so forgot about this article.
Calendars (and date pickers) are often layed out in seven columns for the week days. It is common to split the rows at Gregorian month boundaries. There are (at least) three ways to do this:
  1. Only show the days belonging to the month; duplicate weeks as necessary.
  2. Also show the days from the previous or following month, but dimmed; duplicate weeks as necessary.
    1. Dynamically show four, five or six wees.
    2. Dynamically show five or six weeks, because only non-leap February can fit completely in four weeks.
    3. Always show six rows of weeks, because that is the maximum of weeks dates from a month can fall in (e.g. Outlook).
  3. Do not split week rows; label four or five consecutive rows with one month name.
August 2010
30 1
31 2 3 4 5 6 7 8
32 9 10 11 12 13 14 15
33 16 17 18 19 20 21 22
34 23 24 25 26 27 28 29
35 30 31
August 2010
30 25 26 27 28 29 30 1
31 2 3 4 5 6 7 8
32 9 10 11 12 13 14 15
33 16 17 18 19 20 21 22
34 23 24 25 26 27 28 29
35 30 31 1 2 3 4 5
August 2010
31 2 3 4 5 6 7 8
32 9 10 11 12 13 14 15
33 16 17 18 19 20 21 22
34 23 24 25 26 27 28 29
2010
30 27 28 29 30 31 1 Jul
31 2 3 4 5 6 7 8 Aug
32 9 10 11 12 13 14 15
33 16 17 18 19 20 21 22
34 23 24 25 26 27 28 29
35 30 31 1 2 3 4 5 Sep
36 6 7 8 9 10 11 12
37 13 14 15 16 17 18 19
38 20 21 22 23 24 25 26
39 27 28 29 30 1 2 3
40 4 5 6 7 8 9 Oct
September 2010
35 1 2 3 4 5
36 6 7 8 9 10 11 12
37 13 14 15 16 17 18 19
38 20 21 22 23 24 25 26
39 27 28 29 30
September 2010
35 30 31 1 2 3 4 5
36 6 7 8 9 10 11 12
37 13 14 15 16 17 18 19
38 20 21 22 23 24 25 26
39 27 28 29 30 1 2 3
September 2010
35 30 31 1 2 3 4 5
36 6 7 8 9 10 11 12
37 13 14 15 16 17 18 19
38 20 21 22 23 24 25 26
39 27 28 29 30 1 2 3
The last option is, oviously, the use case where you would apply the ISO week rule to months. This does not need to be visible as clearly, imagine continuously scrolling week rows with a month (and year) label which is not large enough to bear any two names at once.
Options one and two are prevalent in paper calendars focused on months. — Christoph Päper 18:10, 9 August 2010 (UTC)
As before, the status of validity is only your mind game, applying a rule to cases it is not meant for. It should only be put in the article if it can be shown that substantial and documented use of this in the real world. I don't think I have ever seen it. Also a single month calendar with missing days I've never seen. −Woodstone (talk) 12:07, 11 August 2010 (UTC)
Whether you believe it or not, in some applications it is necessary to decide which month a week shall belong to. I gave one example. ISO 8601 offers a straightforward for this, but does not explicitly say so, because it only needs to care for the Dec/Jan boundary. I have rephrased the paragraph to reflect this and will now put it back in, without the table. — Christoph Päper 10:55, 12 August 2010 (UTC)

Contradiction in section “Weeks per year”[edit]

I’ve moved the section Calendar cycle to section Weeks per year, after I had added some simple observations on the pattern there. These contradict! Could someone please check the list of years with 53 weeks on the one hand and the cycle calculations with doomsday and dominical letters on the other hand? — Christoph Päper 10:42, 23 March 2011 (UTC)

Perhaps see my talk post elsewhere: Talk:Seven-day week#Week numbering systems-- (talk) 20:55, 23 March 2011 (UTC)
No, sorry. It is possible that the calendar cycle section was written by someone using the Doomsday algorithm and I don’t know whether it’s valid outside the range 1900–2100. If I remember correctly I was the one that created the list of 53-week years in the Gregorian 400-year cycle, but I can’t find my notes on those calculations. — Christoph Päper 10:15, 24 March 2011 (UTC)
I fixed it, "unusual" things can only happen across 100, 200 and 300.--Patrick (talk) 13:22, 24 March 2011 (UTC)

Human readability[edit]

Why does the article not mention that dates in week-date format are basically incomprehensible to a human viewers? I definitely expected this to be listed in the disadvantages section... 203.206.239.111 (talk) 00:54, 12 May 2011 (UTC)

Many businesses work with weekly calendars. For the people working in them the week notation is completely familiar. −Woodstone (talk) 10:46, 12 May 2011 (UTC)
Indeed. E.g., in Danish schools, "Wednesday in week 40" may be a far more useful way of identifying a day than "October 5th". For one thing, in a school with a weekly schedule, includng the week-day is most useful, and for another, longer-term scheduling often involves entries like: "Week 38-40: Medieval History", say. In such a context, it is the standard way of giving dates that is nearly incomprehensible. Of course, one may list as a disadvantage of either system that they are mutually incomprehensible (or at least hard to convert mentally - a bit like feet and metres, just worse).-- (talk) 14:21, 12 May 2011 (UTC)