-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
WIP: Modified Date types to allow use of Float for definitive periods. #9424
Conversation
@eval immutable $T <: TimePeriod | ||
value::Int64 | ||
$T(v::Number) = new(v) | ||
value::Real |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to make these parametric so the value
field can be concretely-typed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should just be Float64
. I think making it parametric can come later with concrete use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a bunch of issues with making Week
, Day
, Hour
, etc. strictly Float64. Specifically when testing ranges, which is why I ended up making these Real
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making the field type abstract is going to ruin performance, unfortunately.
Sorry about the initial unrelated failure on appveyor, but it does look like there is a legitimate failure here on 32-bit:
|
@@ -1,3 +1,5 @@ | |||
using Base.Test | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my apologies, missed this in cleaning up
…apped around Int Week, Day, Hour, Minute, Second are wrapped around Real to allow for conversion between Millisecond remained wrapped around Int Ref Issue JuliaLang#9393
Ok, here's a list of additional changes we'd need to consider/do:
($op){P<:Period}(x::P,y::Real) = P(($op)(value(x),Int64(y))) since they depend on converting
So all in all, we'd probably have to restructure the Honestly, I really don't feel convinced yet that we need this change. Having walked through all the code considering how this affects everything, it just seems like it messes with some of the nice, simple, operations (dates internal representations, arithmetic, ranges, etc.), for not much gain. |
@quinnj Have you had a chance to give any further thought to this issue? I've gotten a little distracted over the holidays myself, but looking to dive back in. While I agree that Dates currently is very simple and nearly complete operationally, I would argue that it's best to minimize limitations in the language for sake of simplicity. The case which I would present is the desire to use specific units for a period without having to convert down. It's just as common for 18 Hours to be presented as 1.5 Days and converting between the two should not be impractical. It doesn't make sense to me that |
"exactly 1.5 days". I love the quote. :-) I'm not sure what your concrete use case is, but IMHO the strength of Dates is that they are forced to fit within the (very peculiar) framework of days, months and years. It's already complex enough. As @quinnj explained above, if non-integer values were allowed, then canonicalization of If you are working with hours, do not try to convert them in days, just use a function to display them in the most human-readable unit when you need to. What's the trouble with that solution? |
I'd personally view that more as a workaround then a solution, but the issue would present itself when you are first working with ranges of days and begin to manipulate that data. The issue in which I first ran into this is in the testing of Gadfly. To create a bar graph with a range of |
For what it's worth, I'm sold on this functionality even though I'm not sure about the implementation. |
I still stand by my previous comments here that the amount of complexity introduced by an internal |
modified Types such that Year and Month are part of CalendarPeriod wrapp...ed around Int
Week, Day, Hour, Minute, Second are wrapped around Real to allow for both Int and Float types
Millisecond remained wrapped around Int
Ref Issue #9393