GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2008-02-21 06:15:51

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

date_get_week - ISO 8601 can mean unexpected results

This function appears to return week numbers according to the ISO 8601 standard, which may be unintuitive to the uninitiated. Specifically, dates on or before January 3rd may be considered the last week of the previous calendar year, and dates on or after December 29 may be considered the first week of the following calendar year.

Wikipedia entry on ISO 8601 wrote:

Mutually equivalent definitions for week 01 are:

  • the week with the year's first Thursday in it

  • the week with 4 January in it

  • the first week with the majority (four or more) of its days in the starting year

  • the week starting with the Monday in the period 29 December - 4 January

  • If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year.

The week number can be described by counting the Thursdays: week 12 contains the 12th Thursday of the year.

http://www.wikipedia.org/wiki/ISO_8601

I just wish I hadn't spent the last two hours debugging a function to calculate ISO 8601 week numbers when it already existed! Especially since the bugs were actually caused by Game Maker 6's notorious precision problems which wreak havoc on the built-in date functions -- but that's another story.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB