Giter Club home page Giter Club logo

Comments (1)

oldfartdeveloper avatar oldfartdeveloper commented on August 23, 2024

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 DateTimes:

> 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.