-3

I'm trying to calculate the number of days between two specific pairs of dates but the assert is failing on the second test, which is only a week further apart from the first test.

The code is below.

Is there a bug in my code? Or is this a weird java/groovy bug?

use(groovy.time.TimeCategory) {
    def duration = Date.parse("yyyy-MM-dd", "2013-03-10") - Date.parse("yyyy-MM-dd", "2012-12-30")
    assert duration.days == 70

    def duration2 = Date.parse("yyyy-MM-dd", "2013-03-17") - Date.parse("yyyy-MM-dd", "2012-12-30")
    assert duration2.days == 77
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
Christian
  • 1,241
  • 2
  • 8
  • 11

1 Answers1

0

@Damien_The_Unbeliever had it right. Since EST was being used, around March, it is switched to EDT which is 1 hour ahead (so converting 2013-03-17 EDT to EST would mean it would lose one hour.)

I've changed the test to confirm that this is true. The second and third asserts pass.

use(groovy.time.TimeCategory) {
    def duration = Date.parse("yyyy-MM-dd", "2013-03-10") - Date.parse("yyyy-MM-dd", "2012-12-30")
    assert duration.days == 70

    def duration2 = Date.parse("yyyy-MM-dd", "2013-03-17") - Date.parse("yyyy-MM-dd", "2012-12-30")
    assert duration2.days == 76
    assert duration2.hours == 23
}
Christian
  • 1,241
  • 2
  • 8
  • 11
  • @Damien_The_Unbeliever truly does deserve the credit. But saying it as a comment will have to do since There's only one answer here – Christian Jun 09 '16 at 12:27