Comments (8)
@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.
@sstigler If you have any better idea, please send a pull request! I'm looking forward to it. I close this issue.
from timepiece.
@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 Int
s as NSDateComponents
instead of Duration
s.
from timepiece.
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.
@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 Duration
s should not be allowed.
@mattijsf, what do you think?
from timepiece.
@maelp I decided to deprecate these computations. These will be obsoleted in 0.5.0
. Would you check #30?
from timepiece.
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.
@maelp Thanks! I will merge this pull request and close this issue.
from timepiece.
Related Issues (20)
- problems installing with CocoaPods
- Swift Package Manager support, please make this happen
- A new release version?
- SPM 1.3.1 version doesn't work HOT 1
- syntactic sugar for week days HOT 3
- Missing interval ? HOT 2
- inFormat is returning wrong weekday HOT 5
- Weekend HOT 5
- How to modify a date. HOT 4
- How to modify the time zone HOT 4
- changing timezone HOT 2
- Shortcut for timeIntervalSince(_:) HOT 3
- time ago support HOT 3
- Wrong time retrieved
- How to find number of days in a particular year? HOT 1
- endOfDay handles date differently for iOS 10 as it does for iOS 11
- Change the default calendar HOT 4
- Can you add more date math examples to readme? HOT 2
- Swift 4.2 HOT 1
- swift 5
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 timepiece.