mardi 10 mars 2020

Hamcrest test strange time shift failure

I'm trying to build https://github.com/jenkinsci/jira-trigger-plugin and have failures in tests related to time/date:

expect commentEvent.issue.creationDate, is(new DateTime(1980, 1, 1, 0, 0, 0, 0))

Fails:

Condition not satisfied:

expect commentEvent.issue.creationDate, is(new DateTime(1980, 1, 1, 0, 0, 0, 0))
|      |            |     |                |
false  |            |     |                1980-01-01T00:00:00.000+03:00
       |            |     1980-01-01T03:00:00.000+03:00
<...>
Expected: is <1980-01-01T00:00:00.000+03:00>
 but: was <1980-01-01T03:00:00.000+03:00>

As can be seen, the failure is due to the time shift, which is equal to the timezone offset.

But according to the timestamp, timezone is taken into account.

I have made a quick fix with JodaTime's .minusHours(), but this is not an option for a permanent fix.

Aucun commentaire:

Enregistrer un commentaire