Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculating time intervals under daylight savings time? #133

Open
danielcompton opened this issue Dec 9, 2018 · 2 comments
Open

Calculating time intervals under daylight savings time? #133

danielcompton opened this issue Dec 9, 2018 · 2 comments

Comments

@danielcompton
Copy link
Collaborator

In New Zealand, the following test will fail:

(let [date-start (format/parse-local-date yyyy-mm-dd "2016-09-01")
          date-end   (format/parse-local-date yyyy-mm-dd "2016-09-30")]
      (let [interval (time/interval date-start date-end)]
        (is (= 29 (time/in-days interval))))
Chrome 71.0.3578 (Mac OS X 10.14.1) day8.apps-lib.cljstime-local-date-test local-date-interval-test FAILED
	FAIL in   (local-date-interval-test) (cljs/test.js:433:14)
	expected: (=
	            29
	            (time/in-days interval))
	  actual: (=
	            29
	            28)
	    diff: - 29
	          + 28

The issue is that in 2016, New Zealand switched over to daylight savings time on Sunday 25th September. (time/in-days) on Interval bottoms out by calculating the millisecond difference between two dates. On Sunday 25th the clocks went forward an hour, meaning there was 'one less hour' in that day. This means that there is one hour less between the two local dates than there would ordinarily be at other times of the year.

I wonder whether in-days on at least goog.date.Date should count the number of days between the dates, not counting the number of milliseconds between them?

@henryw374
Copy link

@danielcompton I had some similar issues a while back with local dates.

I did a couple of PR's to fix but decided to work on a new library, which has resulted in tick https://github.com/juxt/tick . We're planning to do an announce shortly.

@danielcompton
Copy link
Collaborator Author

Thanks, that was helpful in pointing me towards this comment: #22 (comment). I've been experimenting locally with making a UtcDate type where DateTime : UtcDateTime :: Date : UtcDate. It seems to provide a good foundation for dealing with local dates that have no time nor timezone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants