Giter Site home page Giter Site logo

Comments (8)

naoty avatar naoty commented on June 10, 2024

@sstigler As you said, this library has incorrect assumptions. This problem was discussed at #9. I think we need to return constant values because Duration doesn't have any context about current time. Do you have any better idea?

from timepiece.

naoty avatar naoty commented on June 10, 2024

@sstigler If you have any better idea, please send a pull request! I'm looking forward to it. I close this issue.

from timepiece.

sstigler avatar sstigler commented on June 10, 2024

@naoty I might do that eventually. I probably don't completely understand the purpose of the Duration class, but the gist of what I'd recommend is to represent the Ints as NSDateComponents instead of Durations.

from timepiece.

maelp avatar maelp commented on June 10, 2024

I think the Duration class might be misleading indeed for those reasons, and should probably be represented as a stack of consecutive NSDateComponents if you want to add them, because "date + (1.month + 1.day)" cannot be coerced to "date + (31.day)", so you need to keep the internal representation as a stack if you want to be able to make correct computations afterwards

Otherwise I'd suggest not allowing to add / subtract Duration and force them to be added to dates immediately, so someone has to do: "(date + 1.month) + 1.day" which then has the current date context and uses NSCalendar to disambiguate the correct number of days

Would this be a solution?

from timepiece.

naoty avatar naoty commented on June 10, 2024

@maelp Thank you for suggestion! I agree with you.

While the addition/subtraction of Duration with NSDate is possible, the exact conversion of Duration into NSTimeInterval is impossible because Duration doesn't know current datetime. Current implementation is useful but misleading.

I think the correctness of calculating dates is most important for date calculation libraries. So, I agree that the conversion of Duration into NSTimeInterval and the comparison between Durations should not be allowed.

@mattijsf, what do you think?

from timepiece.

naoty avatar naoty commented on June 10, 2024

@maelp I decided to deprecate these computations. These will be obsoleted in 0.5.0. Would you check #30?

from timepiece.

maelp avatar maelp commented on June 10, 2024

Indeed I feel it is a better solution, just allow people to do common things that are unambiguous, like adding a set number of days / hours / minutes / seconds to a date using NSCalendar to account for eg a day with an hour less because of DST, but not adding the durations together

from timepiece.

naoty avatar naoty commented on June 10, 2024

@maelp Thanks! I will merge this pull request and close this issue.

from timepiece.

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.