ISO8601 Week number

Posted by Jens Dahlin on 30-Jan-2020 09:35

Has anybody already implemented an ABL function for ISO 8601 week numbers and care to share? 

All Replies

Posted by magsoa on 30-Jan-2020 11:17

Try one of this:

www.progresstalk.com/.../

Posted by Jens Dahlin on 30-Jan-2020 12:00

The final version seems promising! Thanks.

Posted by Sanjeva Manchala on 30-Jan-2020 12:00

Hi Jens,
 
Below code should work.
 
DEFINE VARIABLE daysInYearSoFar AS INTEGER NO-UNDO.
DEFINE VARIABLE weekNumber AS INTEGER NO-UNDO.
DEFINE VARIABLE currentDate AS DATE NO-UNDO.
                     
currentDate = TODAY.
daysInYearSoFar = currentDate - DATE( 1, 1, YEAR( currentDate ) ) + 1.
IF (daysInYearSoFar MODULO 7 ) = 0 THEN
    weekNumber = daysInYearSoFar / 7 .
ELSE
    weekNumber = (daysInYearSoFar / 7 ) + 1.
   
Hope this helps,
Sanjeev

Posted by Jens Dahlin on 30-Jan-2020 12:05

It's not that simple. Im afraid. That's not how iso8601 week numbers work.

Posted by magsoa on 30-Jan-2020 12:24

ISO8601 week number It's a bit complicated...

en.wikipedia.org/.../ISO_week_date

Anyone can use this .NET function? docs.microsoft.com/.../system.globalization.isoweek

Posted by Jens Dahlin on 30-Jan-2020 12:49

Not me since I run this in a Linux environment. Some basic testing shows that the link you posted works so far....

Posted by Jens Dahlin on 30-Jan-2020 13:38

I posted a message but it disappeared? I'm running Linux so I cant use that .Net function. The last version of the week number function on the link you posted works, at least for those dates I've tested so far. It looks quite like the algorithms I've checked.

Posted by Lieven De Foor on 30-Jan-2020 14:00

The version on ProgressTalk is not 100% correct!

We have implemented a DateToIsoWeekDate() conversion method (sorry, can't share), and written unit tests for a lot of edge cases.

For 1 January 2006 the Iso Week Date is "2005-W52-7", but the code on ProgressTalk returns week 53...

Besides, it should return a full string like above instead of only a week, as it needs the year is essential information (it could be in the next or previous year)

As for the good news, that date seems to be the only for which my unit tests are failing for the ProgressTalk implementation...

I can share the test cases and results though:

MESSAGE ISOWeekNumber(1/1/2005) /* "2004-W53-6" */ SKIP

       ISOWeekNumber(1/2/2005) /* "2004-W53-7" */ SKIP

       ISOWeekNumber(12/31/2005) /* "2005-W52-6" */ SKIP

       ISOWeekNumber(1/1/2006) /* "2005-W52-7" */ SKIP

       ISOWeekNumber(1/2/2006) /* "2006-W01-1" */ SKIP

       ISOWeekNumber(12/31/2006) /* "2006-W52-7" */ SKIP

       ISOWeekNumber(01/01/2007) /* "2007-W01-1" */ SKIP

       ISOWeekNumber(12/30/2007) /* "2007-W52-7" */ SKIP

       ISOWeekNumber(12/31/2007) /* "2008-W01-1" */ SKIP

       ISOWeekNumber(01/01/2008) /* "2008-W01-2" */ SKIP

       ISOWeekNumber(12/28/2008) /* "2008-W52-7" */ SKIP

       ISOWeekNumber(12/29/2008) /* "2009-W01-1" */ SKIP

       ISOWeekNumber(12/30/2008) /* "2009-W01-2" */ SKIP

       ISOWeekNumber(12/31/2008) /* "2009-W01-3" */ SKIP

       ISOWeekNumber(01/01/2009) /* "2009-W01-4" */ SKIP

       ISOWeekNumber(12/31/2009) /* "2009-W53-4" */ SKIP

       ISOWeekNumber(01/01/2010) /*"2009-W53-5" */ SKIP

       ISOWeekNumber(01/02/2010) /* "2009-W53-6" */ SKIP

       ISOWeekNumber(01/03/2010) /* "2009-W53-7" */

   VIEW-AS ALERT-BOX.

en.wikipedia.org/.../ISO_week_date

This thread is closed