Comments (1)
The documentation is vague here, but I believe the existing code is correct; your interpretation is not what the author intended.
delta
is intended to show whether a boundary condition is happening in whatever unit of time measure you are interested in. Hence, for day, there is a difference if the two dates are on different days (in the referenced timezone) even if the number of hours difference between them is less than 24.
Hence, given your examples
> d1
DateTime { date = Date { year = 2017, month = 12, day = 11 }, offset = 52200000 }
: Time.DateTime.DateTime
> d3
DateTime { date = Date { year = 2017, month = 12, day = 12 }, offset = 1800000 }
: Time.DateTime.DateTime
Note that the dates are different: Dec 11, 2017 vs Dec 12, 2017.
Looking at the delta
:
> d3D1 = DateTime.delta d3 d1
{ years = 0, months = 0, days = 1, hours = 10, minutes = 600, seconds = 36000, milliseconds = 36000000 }
the current implementation indicates accurately that it's 1 day difference.
Looking at the hours for the two DateTime
's:
> DateTime.hour d1
14 : Int
> DateTime.hour d3
0 : Int
you can see that d1 is 14 hours into the day. I.e. it's only 10 hours away from its "next day". On the other hand, d3 is only 0 hours into its new day. Hence,
> d3D1.hours
10 : Int
is correct; the two DateTime
's are 10 hours apart.
The minutes into the hour are the same for both DateTime
s:
> DateTime.minute d1
30 : Int
> DateTime.minute d3
30 : Int
And so we would expect the delta minutes difference to be 10 hours times 60 minutes/hour = 600 minutes. Indeed:
> d3D1.minutes
600 : Int
and so on into seconds and milliseconds.
In summary, the delta gives you the difference across boundaries in the time unit that you choose. The result is (I believe) rounded into the desired unit.
So your test is incorrect because it presumes a different purpose.
The documentation needs to be clarified to show this.
Hope this helps.
from elm-time.
Related Issues (20)
- DateTime.toISO8601 truncates to seconds HOT 23
- DateTime.fromISO8601 fails to parse valid formats HOT 6
- travis build fails HOT 1
- Parsing fails when milliseconds are explicitly zero HOT 5
- Math naming of the fractional variables is wrong HOT 1
- Epoch and Millisencond HOT 1
- Timezone lost when reading from ISO 8601 HOT 2
- Beef up examples a bit HOT 1
- 1.0.11 & 1.0.12 versions produce compilation error HOT 14
- Upgrade to use version 2 of elm-community/parser-combinator HOT 1
- Problem with Etc/UTC±n timezone definitions? HOT 9
- Error parsing a valid ISO8601 date with a year less than 1000 HOT 2
- How to be with DateTimeData alias being internal? HOT 3
- [enhancement] Support unix epoch and epoch millisecond HOT 2
- Support end-of-day (hour 24) like ISO8601 HOT 1
- Range function to generate a list of dates between two dates HOT 2
- Calculate age in years HOT 5
- update for 0.19? HOT 5
- Support for time only ISO8601 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-time.