Details

    • Type: Bug Bug
    • Status: Resolved Resolved (View Workflow)
    • Priority: Major Major
    • Resolution: Done
    • Affects Version/s: 3.1 Final (3.1.1.000)
    • Fix Version/s: 3.1 Final (3.1.1.013)
    • Labels:
      None
    • Environment:
      Using Railo 3.1.1.0 server installation (on top of Resin) on WIndows
    • Similar Issues:
      Show 10 results 

      Description

      DateAdd() returns inconsistent results. When adding 1 month to a certain date, sometimes the result is not correct – instead it is short by 1 or two days. This only happens for some months, not all.

      Demonstrated with the following code

      <cfoutput>
      <table border="1">
      <tr>
      <td>Original</td>
      <td>Add 1 month</td>
      <td>Diff (months)</td>
      <td>Diff (days)</td>
      </tr>
      <cfloop index="i" from="1" to="12">
      <cfset date1 = CreateDate(2009, i, 1)>
      <cfset date2 = DateAdd('m', 1, date1)>
      <tr>
      <td>#date1#</td>
      <td>#date2#</td>
      <td>#DateDiff('m', date1, date2)#</td>
      <td>#DateDiff('d', date1, date2)#</td>
      </tr>
      </cfloop>
      </table>

      </cfoutput>

        Activity

        Hide
        Michael Offner
        added a comment -

        i have build testcases based on your inputs, but i can see no problem here and the testcases work exact the same way as adobeCF does
        you need the following custom tag to execute testcases (http://dev.railo.ch/valueEquals.cfm.zip)

        testcases;
        <cfset date1=CreateDate(2009, 1, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-01-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-02-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        <cfset date1=CreateDate(2009, 2, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-02-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-03-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="28x">

        <cfset date1=CreateDate(2009, 3, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-03-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-04-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        <cfset date1=CreateDate(2009, 4, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-04-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-05-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x">

        <cfset date1=CreateDate(2009, 5, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-05-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-06-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        <cfset date1=CreateDate(2009, 6, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-06-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-07-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x">

        <cfset date1=CreateDate(2009, 7, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-07-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-08-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        <cfset date1=CreateDate(2009, 8, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-08-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-09-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        <cfset date1=CreateDate(2009, 9, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-09-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-10-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x">

        <cfset date1=CreateDate(2009, 10, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-10-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-11-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        <cfset date1=CreateDate(2009, 11, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-11-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2009-12-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x">

        <cfset date1=CreateDate(2009, 12, 1)>
        <cfset date2=DateAdd('m', 1, date1)>
        <cf_valueEquals left="#date1#x" right="

        {ts '2009-12-01 00:00:00'}

        x">
        <cf_valueEquals left="#date2#x" right="

        {ts '2010-01-01 00:00:00'}

        x">
        <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x">
        <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">

        Show
        Michael Offner
        added a comment - i have build testcases based on your inputs, but i can see no problem here and the testcases work exact the same way as adobeCF does you need the following custom tag to execute testcases ( http://dev.railo.ch/valueEquals.cfm.zip ) testcases; <cfset date1=CreateDate(2009, 1, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-01-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-02-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x"> <cfset date1=CreateDate(2009, 2, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-02-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-03-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="28x"> <cfset date1=CreateDate(2009, 3, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-03-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-04-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x"> <cfset date1=CreateDate(2009, 4, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-04-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-05-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x"> <cfset date1=CreateDate(2009, 5, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-05-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-06-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x"> <cfset date1=CreateDate(2009, 6, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-06-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-07-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x"> <cfset date1=CreateDate(2009, 7, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-07-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-08-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x"> <cfset date1=CreateDate(2009, 8, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-08-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-09-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x"> <cfset date1=CreateDate(2009, 9, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-09-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-10-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x"> <cfset date1=CreateDate(2009, 10, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-10-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-11-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x"> <cfset date1=CreateDate(2009, 11, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-11-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2009-12-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="30x"> <cfset date1=CreateDate(2009, 12, 1)> <cfset date2=DateAdd('m', 1, date1)> <cf_valueEquals left="#date1#x" right=" {ts '2009-12-01 00:00:00'} x"> <cf_valueEquals left="#date2#x" right=" {ts '2010-01-01 00:00:00'} x"> <cf_valueEquals left="#DateDiff('m', date1, date2)#x" right="1x"> <cf_valueEquals left="#DateDiff('d', date1, date2)#x" right="31x">
        Hide
        Ben Pate
        added a comment -

        Hi Michael,

        I'm really impressed to see someone looking at this so quickly. Thanks!

        I ran your test cases, butuncovered the same errors that I reported before. I posted your code on my server so you can see: http://www.zenplanner.com/zenplanner/www/z-railo-dateAdd-test.cfm

        Date math is failing for March, May, July, August, October – all months with 31 days. This can't be a coincidence.

        Since it's happening on my machine and not yours, that suggests a difference in Resin, the JVM, or the minor update version of Railo itself. I know that may make it more trouble to find – and that you're very busy – but this seems like a critical issue to figure out, because it makes Railo unreliable for any calendaring, scheduling application (which is what I'm hosting).

        Thanks so much for your help. I'm going to continue digging in to this, and will do whatever you need to help find the solution.


        Ben

        Show
        Ben Pate
        added a comment - Hi Michael, I'm really impressed to see someone looking at this so quickly. Thanks! I ran your test cases, butuncovered the same errors that I reported before. I posted your code on my server so you can see: http://www.zenplanner.com/zenplanner/www/z-railo-dateAdd-test.cfm Date math is failing for March, May, July, August, October – all months with 31 days. This can't be a coincidence. Since it's happening on my machine and not yours, that suggests a difference in Resin, the JVM, or the minor update version of Railo itself. I know that may make it more trouble to find – and that you're very busy – but this seems like a critical issue to figure out, because it makes Railo unreliable for any calendaring, scheduling application (which is what I'm hosting). Thanks so much for your help. I'm going to continue digging in to this, and will do whatever you need to help find the solution. – Ben
        Hide
        Ben Pate
        added a comment -

        I found the problem.

        The server was set to a different time zone as the Railo app server. I'm not positive why this would cause the strange errors that I encountered, but fixing this (setting both to the same timezone) makes the error go away.

        Show
        Ben Pate
        added a comment - I found the problem. The server was set to a different time zone as the Railo app server. I'm not positive why this would cause the strange errors that I encountered, but fixing this (setting both to the same timezone) makes the error go away.
        Hide
        Michael Offner
        added a comment -

        we will test this behavior

        Show
        Michael Offner
        added a comment - we will test this behavior
        Hide
        Michael Offner
        added a comment -

        tnx for input

        Show
        Michael Offner
        added a comment - tnx for input

          People

          • Assignee:
            Michael Offner
            Reporter:
            Ben Pate
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: