Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    [BUG] isc.DateUtil.getStartOf not returning the correct date

    Hi,
    i'm facing a bug with isc.DateUtil.getStartOf (despite is not documented is used in some example) which seems to not return the correct StartOf a week.
    In this case i'm working with 13/09/2015 (Sunday) and first day of week on monday. The function return 14/09/2015 instead of 07/09/2015 which is pretty wrong.

    1. ISC_VERSION:
    1. SNAPSHOT_v10.1d_2015-09-15/EVAL Development Only
    2. v10.0p_2015-09-15/Enterprise Development Only
    2. OS and Browser: Chrome 45 x64 on Windows 8.1 Pro x64
    6. Code snippet to be used HERE or in any example page
    Code:
    var endOfWeekDate = new Date(1442144591000);
    isc.VStack.create({members:[
    isc.Label.create({
        height: 30,
        padding: 10,
        align: "center",
        valign: "center",
        wrap: false,
        showEdges: true,
        contents: "<b>MY DATE: </b>"+isc.DateUtil.format(endOfWeekDate,"dd/MM/yyyy")
    }),
    isc.Label.create({
        height: 30,
        padding: 10,
        align: "center",
        valign: "center",
        wrap: false,
        icon: "icons/16/approved.png",
        showEdges: true,
        contents: "<b>Week Start(first day is sunday): </b>"+isc.DateUtil.format(isc.DateUtil.getStartOf(endOfWeekDate,"W"),"dd/MM/yyyy")
    }),
    isc.Label.create({
        height: 30,
        padding: 10,
        align: "center",
        valign: "center",
        wrap: false,
        icon: "icons/16/approved.png",
        showEdges: true,
        contents: "<b>Week End(first day is sunday): </b>"+isc.DateUtil.format(isc.DateUtil.getEndOf(endOfWeekDate,"W"),"dd/MM/yyyy")
    }),
    isc.Label.create({
        height: 30,
        padding: 10,
        align: "center",
        valign: "center",
        wrap: false,
        icon: "icons/16/close.png",
        showEdges: true,
        contents: "<b>Week Start(first day is monday): </b>"+isc.DateUtil.format(isc.DateUtil.getStartOf(endOfWeekDate,"W",null,1),"dd/MM/yyyy")+ "</br><strong>This should be 07/09/2015</strong>"
    }),
    isc.Label.create({
        height: 30,
        padding: 10,
        align: "center",
        valign: "center",
        wrap: false,
        icon: "icons/16/approved.png",
        showEdges: true,
        contents: "<b>Week End(first day is monday): </b>"+isc.DateUtil.format(isc.DateUtil.getEndOf(endOfWeekDate,"W",null,1),"dd/MM/yyyy")
    })
    ]});

    By further inspection in debug-modules i noticed that there seems to be a missing control on "delta" compared to the isc.DateUtil.getEndOf function.
    • isc.DateUtil.getStartOf relevant code portion
      Code:
      	var newDate;
      	 if (logicalDate) {
      	 newDate = Date.createLogicalDate(year, month, dateVal);
      	 } else {
      	 newDate = Date.createDatetime(year, month, dateVal, 0, 0, 0, 0);
      	 }
      	 var delta = firstDayOfWeek - dayOfWeek;
      	 newDate.setDate(newDate.getDate()+delta);
      	 return newDate;
      	[B][/B]
    • isc.DateUtil.getEndOf relevant code portion
      Code:
      	case "w":
      	 // end of week
      	 var delta = (6-(dayOfWeek-firstDayOfWeek));
      	 if (delta >= 7) delta -= 7;
      	 var endDate = dateVal + delta;
      	 if (logicalDate) {
      	 return Date.createLogicalDate(year, month, endDate);
      	 } else {
      	 return Date.createDatetime(year, month, endDate, 23, 59, 59, 999);
      	 }
      	[B][/B]
    Thank you in advance

    #2
    Thanks for pointing this out - we've fixed that logic and exposed both getStartOf() and getEndOf() in the docs.

    You can test these changes in builds dated September 18 and later.

    Comment


      #3
      Hi isomoprhic, i'm facing the same bug with recent versions.

      Today, i've tried to execute the "getStartOf" function to retrieve the start of this week.

      So, i executed this:
      Code:
      isc.DateUtil.getStartOf(new Date(), "W", false, 1);
      newDate() = 2016/03/30

      What i expect is that the returned date is equal to 2016/03/28.
      Instead, the function returns 2016/03/27.

      1. ISC_VERSION:
      v10.1p_2016-03-30/EVAL Development Only
      v11.0p_2016-03-29/EVAL Development Only
      2. OS and Browser: Chrome 49.0.2623.110 x64 on Windows 8.1 Pro x64


      I also tried the equivalent server method (pkg: com.isomorphic.util.DateUtil) retrieving the same bug.

      Comment


        #4
        In different locales, Sunday or Monday may be considered the beginning of the week. Most likely, you are running this test in a locale where Sunday is considered the first day of the week, so the result is correct.

        Comment


          #5
          Originally posted by Isomorphic View Post
          In different locales, Sunday or Monday may be considered the beginning of the week. Most likely, you are running this test in a locale where Sunday is considered the first day of the week, so the result is correct.

          Yes, but i'm not working with locale default. The signature of getStartOf function permit a parameter that overrides the locale default.

          as you can see... Click image for larger version

Name:	isc_core_getStartOf_signature.png
Views:	137
Size:	19.7 KB
ID:	236376



          And in my case i executed:

          Code:
          isc.DateUtil.getStartOf(new Date(), "W", false, 1);
          Where firstDayOfWeek = 1 (Monday).

          Moreover if i execute:

          Code:
          isc.DateChooser.getInstanceProperty("firstDayOfWeek")
          that retrieve the locale defautl, the result is 1.

          So, is not a problem of a locale default, but of the getStartOf() function.


          Anyway, i compared the code of the version (v10.1p_2016-03-30/EVAL Development Only) with an older version (v10.1p_2016-02-02/EVAL Development Only) , where i was sure it was working fine, to see the differences between the functions, and i noticed a new "else if" in the newer version. Click image for larger version

Name:	isc_core_diff_on_getStartOf.png
Views:	138
Size:	15.8 KB
ID:	236377





          i'm not sure what this new condition do, but if i remove it, the problem disappears.

          Comment


            #6
            This has been fixed and a bunch of autotests added - please retest with a build dated April 6 or later.

            Comment


              #7
              Hi isomorphic, is still not working.

              i tried on:

              1) "v10.1p_2016-04-08/Enterprise Development Only"

              2)"v11.0p_2016-04-07/Enterprise Development Only"

              Comment


                #8
                Please confirm your client and server timezones/locales (if the prototype attribiute firstDayOfWeek is 1, you must be loading a locale).

                Comment

                Working...
                X