File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,23 @@ test = ((((((((dt + y) - m) + w) - d) + h) - mi) + s) - ms)
238238@test_throws MethodError Dates. Year (1 ) == Dates. Millisecond (1 )
239239@test_throws MethodError Dates. Millisecond (1 ) == Dates. Year (1 )
240240
241+ # Allow comparisons with new Period subtypes
242+ let
243+ # https://en.wikipedia.org/wiki/Swatch_Internet_Time
244+ struct BeatTime <: Dates.Period
245+ value:: Int64
246+ end
247+
248+ Dates. value (b:: BeatTime ) = b. value
249+ Dates. toms (b:: BeatTime ) = Dates. value (b) * 86400
250+ Dates. _units (b:: BeatTime ) = " beat" * (abs (Dates. value (b)) == 1 ? " " : " s" )
251+ Base. promote_rule (:: Type{Dates.Day} , :: Type{BeatTime} ) = Dates. Millisecond
252+ Base. convert {T<:Dates.Millisecond} (:: Type{T} , b:: BeatTime ) = T (Dates. toms (b))
253+
254+ @test BeatTime (1000 ) == Dates. Day (1 )
255+ @test BeatTime (1 ) < Dates. Day (1 )
256+ end
257+
241258@test Dates. Year (" 1" ) == y
242259@test Dates. Month (" 1" ) == m
243260@test Dates. Week (" 1" ) == w
You can’t perform that action at this time.
0 commit comments