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
Addition/subtraction for some AnchoredInterval
s produces unexpected results
#1
Comments
My plan is to proceed with solution 1 for now, and consider 2 in the future. |
One way to support MWE: using Base.Dates
using Base.Dates: TimeType
const AbstractDateTime = TimeType
struct AnchoredInterval{P, T, R}
anchor::T
end
AnchoredInterval{P, T}(i::T) where {P, T} = AnchoredInterval{P, T, false}(i)
const HourEnding{T} = AnchoredInterval{Hour(-1), T, true} where T <: AbstractDateTime
HourEnding{T}(i::T) where T <: AbstractDateTime = invoke(HourEnding{T}, Tuple{Any}, ceil(i, Hour))
HourEnding{DateTime}(now())
AnchoredInterval{Hour(-1), DateTime}(now()) |
I think I would prefer option 2 however. |
It seems to me that the third type parameter is likely to cause a lot of confusion. How do you feel about something like:
Names subject to change, of course. |
I like that proposal. My only issue is that I think |
Remove rounding from `AnchoredInterval{P}` (which was a special case when `P` is a `Period`) and replace it with the pseudoconstructors `HE` and `HB`. This fixes some problems associated arithmetic involving `AnchoredInterval`s. Also `intersect(AnchoredInterval, AnchoredInterval)` now returns an `AnchoredInterval` instead of an `Interval` (but the tests are broken; they'll be fixed once we change the value type parameter to a field). Closes #1
* Remove rounding from AnchoredInterval Remove rounding from `AnchoredInterval{P}` (which was a special case when `P` is a `Period`) and replace it with the pseudoconstructors `HE` and `HB`. This fixes some problems associated arithmetic involving `AnchoredInterval`s. Also `intersect(AnchoredInterval, AnchoredInterval)` now returns an `AnchoredInterval` instead of an `Interval` (but the tests are broken; they'll be fixed once we change the value type parameter to a field). Closes #1 * Document rounding changes to HourEnding * Add tests for `in(::Interval, ::Interval)` * Updates as per code review * Fix broken tests, improve coverage * Rename promote_period to canonicalize
Arithmetic involving an
AnchoredInterval{P, T}
whenP isa Period
runs afoul of the rounding code in the constructor, producing counterintuitive results:Rounding will have to be removed from the
AnchoredInterval{P, T}
constructor to resolve this issue, but it is nice being able to callHourEnding(now())
without having to explicitly roundnow()
to the nearest hour.Of the many possible solutions @omus and I have considered, two seem most promising:
HourEnding{T}
remains a type alias forAnchoredInterval{Hour(-1), T}
, but only theHourEnding
constructor will perform the rounding operationHourEnding{DateTime}(now())
will not be rounded (as it's just an alias forAnchoredInterval{Hour(-1), DateTime}
), which may lead to confusionHourEnding
andAnchoredInterval
both become subtypes of a newAbstractAnchoredInterval
(Curt has suggestedSpanInterval
as a replacement name)Either way, I'll have to fix the way
string(::AnchoredInterval{P, T})
works, because currently it assumes that everything will be rounded whenT <: TimeType
.The text was updated successfully, but these errors were encountered: