ergo icon indicating copy to clipboard operation
ergo copied to clipboard

Unexpected behaviour of DateTime getDay method

Open adrianffletcher opened this issue 5 years ago • 5 comments

When the getDay method is called in ergo on a DateTime from a request that was created using the String "2020-01-02" the value returned is 1 rather than 2.

To Reproduce Run 'cicero trigger' on the attached smart clause template.

Expected behavior Based on the contract logic I would expect 2 to be returned and no payment obligation to be raised. In fact a payment obligation is raised.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS

Additional context This was running in the New York locale and this may be a timezone issue.

adrianffletcher avatar Jan 10 '20 19:01 adrianffletcher

It's most likely a timezone issue, can you run with cicero --currentTime= "2020-01-23T00:00:00-05:00" or cicero --currentTime= "2020-01-23T00:00:00Z" to see the difference?

Currently dates are always interpreted as a Date/Time with zero hours/minutes/seconds and are interpreted as instants in a given timezone. This means, it is always preferable to provide explicit timezones to avoid confusion in the request and/or for execution.

I would be interested to know if there are requirements for a different behaviour.

jeromesimeon avatar Jan 23 '20 12:01 jeromesimeon

Yes, this is a timezone issue. On reflection I think we need a logical Date object that does not include timezone information for this kind of logic.

adrianffletcher avatar Mar 09 '20 11:03 adrianffletcher

Yes, this is a timezone issue. On reflection I think we need a logical Date object that does not include timezone information for this kind of logic.

Maybe...what does a date without a timezone mean? If the contract says by January 24th, 2020 I think there would always be an implicit timezone? (that date in Paris or Canberra).

jeromesimeon avatar Mar 09 '20 13:03 jeromesimeon

Yes, you are right, there would be an implicit timezone but the object would behave the same regardless of the timezone. So if you call getDay on "2020-01-02" then you will always get 2 regardless of timezone.

adrianffletcher avatar Mar 09 '20 13:03 adrianffletcher