ISO8601 Week number - Forum - OpenEdge Development - Progress Community
 Forum

ISO8601 Week number

This question is not answered

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

All Replies
  • Try one of this:

    www.progresstalk.com/.../

  • The final version seems promising! Thanks.

  • 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
  • It's not that simple. Im afraid. That's not how iso8601 week numbers work.

  • 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

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

  • 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.

  • 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