Jump to content

ISO8901: Week numbers and year

Recommended Posts

According to this document ISO 8601 - Wikipedia

Monday 29 December 2008 is written as "2009-W01-1" when a week number is used.


As you can see, instead of 2008, the value 2009 is shown. What date formatting function supports this in Delphi?



Share this post

Link to post

I can't help here. But I can offer a warning to inexperienced "week number" users (which you may NOT be, I realise) and that is to beware of the week number 53 that does occur from time to time. I spent a long time debugging someone elses code once that stored week data in an array size [52] and overflowed causing corruption when week 53 came along.

Share this post

Link to post

The functions in system.dateutils claim to be ISO8601 compliant.  Are you saying that they return the wrong results?  WeekOfTheYear has an overload which sets the year as well as returning the week

Share this post

Link to post

WeekOfTheYear is working. I was looking for something like DateTimeToString which supports displaying dates like above using week numbers (aka "2009-W01")

Edited by Keesver

Share this post

Link to post
28 minutes ago, Keesver said:

I was looking for something like DateTimeToString

There is no such thing in Delphi. You have to roll your own. Should not be that hard.

Edited by Attila Kovacs

Share this post

Link to post
7 hours ago, dummzeuch said:

I was about to point to my iso8601 unit in dzlib, but when I checked, I found the ToWeekDate method to be possibly faulty in exactly these cases. Should be easy to fix though.



Fixed it. Also added unit tests for this (I could have sworn I already had some. Another faulty thing: My memory.)

  • Like 2
  • Haha 2

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now