Skip to content
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

Various Date/Time fixes #20226

Merged
merged 12 commits into from
Jan 28, 2017
Merged

Various Date/Time fixes #20226

merged 12 commits into from
Jan 28, 2017

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Jan 25, 2017

No description provided.

@tkelman
Copy link
Contributor

tkelman commented Jan 25, 2017

you're deleting a lot of recent news additions here, probably wrong local conflict resolution?

@@ -219,15 +212,11 @@ Library improvements

* `notify` now returns a count of tasks woken up ([#19841]).

* A new `Dates.Time` type was added that supports representing the time of day with up to nanosecond resolution.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add PR reference

($op){T<:TimeType,P<:GeneralPeriod}(x::StridedArray{P}, y::T) = broadcast($op,x,y)
($op){P<:GeneralPeriod}(y::TimeType, x::StridedArray{P}) = broadcast($op,x,y)
($op){T<:TimeType}(x::AbstractArray{T}, y::GeneralPeriod) = broadcast($op, x, y)
($op){P<:GeneralPeriod}(y::TimeType, x::StridedArray{P}) = broadcast($op, x, y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this one be addition-only? or be sure the argument orders match?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you rebased this one back

@tkelman tkelman added the dates Dates, times, and the Dates stdlib module label Jan 25, 2017
(+)(x::Date, y::Day) = return Date(UTD(value(x) + value(y)))
(-)(x::Date, y::Day) = return Date(UTD(value(x) - value(y)))
(+)(x::DateTime, y::Period) = return DateTime(UTM(value(x) + toms(y)))
(-)(x::DateTime, y::Period) = return DateTime(UTM(value(x) - toms(y)))
(+)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) + tons(y)))
(-)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) - tons(y)))
(+)(y::Period, x::TimeType) = x + y
(-)(y::Period, x::TimeType) = x - y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know who might be finding these useful, but it would be a bit less disruptive to phase it out with a warning in deprecated.jl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anybody's relying on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would seem crazy to think this would work, so it's hard to imagine relying on this. In other words, imo deleting this method is a bugfix not a feature deletion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both #12094 and #12115 mention this which is why I pinged @GordStephen for input, but he might not be using julia as much lately, not sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree that this is crazy and more likely an oversight on my part than any kind of feature. I'm certainly not using this functionality.

for p in y.periods
x -= p
end
return x
end
(-)(x::CompoundPeriod,y::TimeType) = y - x
(-)(x::CompoundPeriod, y::TimeType) = y - x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another instance of commutative subtraction that should be deprecated

(looks like @GordStephen may have been the author of a few of these)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise I think your rebase lost the removal of this

if op == :+
@eval begin
($op){T<:TimeType}(y::GeneralPeriod, x::AbstractArray{T}) = broadcast($op, x, y)
($op){T<:TimeType,P<:GeneralPeriod}(x::StridedArray{P}, y::T) = broadcast($op, x, y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the argument order of this one is x, y on both lhs and rhs I think this one is fine to have defined for subtraction

@tkelman tkelman added this to the 0.6.0 milestone Jan 25, 2017
@tkelman
Copy link
Contributor

tkelman commented Jan 25, 2017

If you need a hand rebasing this, I can take a look late tonight. Just that one method to make a decision on. This addresses basically all of the feedback I had on the Time PR.

@quinnj
Copy link
Member Author

quinnj commented Jan 25, 2017

I'll see if I can get to this; if not, feel free to go for it. I've been having computer issues and had to try and get my windows machine set back up for julia dev last night and had struggles.

@quinnj
Copy link
Member Author

quinnj commented Jan 26, 2017

Rebasing now

@@ -86,11 +86,11 @@ for op in (:+, :-)
@eval begin
($op){T<:TimeType}(x::AbstractArray{T}, y::GeneralPeriod) = broadcast($op, x, y)
($op){P<:GeneralPeriod}(y::TimeType, x::StridedArray{P}) = broadcast($op, x, y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one's bad though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, why is this one bad?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the argument order is y, x on the left and x, y on the right so it only works for commutative ops

@quinnj
Copy link
Member Author

quinnj commented Jan 26, 2017

Travis is happy; @tkelman anything else to be changed here?

@tkelman
Copy link
Contributor

tkelman commented Jan 26, 2017

  • L88 of base/dates/arithmetic.jl
  • L395 of base/dates/periods.jl

@quinnj
Copy link
Member Author

quinnj commented Jan 26, 2017

@tkelman, could you fix the rebase for me? I unfortunately don't have access to my computer and my windows machine is all jacked. If you can't, I can probably get to it later tonight.

@tkelman
Copy link
Contributor

tkelman commented Jan 26, 2017

Okay done. The dates tests fail if run with JULIA_CPU_CORES=1 but I don't think that's caused by this PR.

@@ -314,63 +314,62 @@ emptyperiod = ((y + d) - d) - y
@test Dates.canonicalize(y - m + w - d + h - mi + s - ms).periods == Dates.Period[11m, 6d, 59mi, 999ms]
@test Dates.canonicalize(-y + m - w + d - h + mi - s + ms).periods == Dates.Period[-11m, -6d, -59mi, -999ms]

@test Dates.Date(2009,2,1) - (Dates.Month(1) + Dates.Day(1)) == Dates.Date(2008,12,31)
@test (Dates.Month(1) + Dates.Day(1)) - Dates.Date(2009,2,1) == Dates.Date(2008,12,31)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be left in to ensure this behaviour throws an exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Added back as @test_throws

(+)(a::TimeType, b::Period, c::Period) = (+)(a, b + c)
(-)(a::TimeType, b::Period, c::Period) = (-)(a, b - c)
(+)(a::TimeType, b::Period, c::Period, d::Period...) = (+)((+)(a, b + c), d...)
(-)(a::TimeType, b::Period, c::Period, d::Period...) = (-)((-)(a, b - c), d...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some strange associativity here too... if a - b - c is a - (b - c), then shouldn't a - b - c - d be a - (b - (c - d)) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests pass without them, should we get rid of these subtractions too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@tkelman tkelman merged commit 78448fa into master Jan 28, 2017
@tkelman tkelman deleted the jq/timetocleanup branch January 28, 2017 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants