@@ -443,10 +443,20 @@ Base.promote_rule(::Type{Year}, ::Type{Month}) = Month
443
443
(== )(x:: FixedPeriod , y:: OtherPeriod ) = throw (MethodError (== , (x, y)))
444
444
(== )(x:: OtherPeriod , y:: FixedPeriod ) = throw (MethodError (== , (x, y)))
445
445
446
+ const fixedperiod_seed = UInt === UInt64 ? 0x5b7fc751bba97516 : 0xeae0fdcb
447
+ const otherperiod_seed = UInt === UInt64 ? 0xe1837356ff2d2ac9 : 0x170d1b00
448
+ # tons() will overflow for periods longer than ~300,000 years, implying a hash collision
449
+ # which is relatively harmless given how infrequent such periods should appear
450
+ Base. hash (x:: FixedPeriod , h:: UInt ) = hash (tons (x), h + fixedperiod_seed)
451
+ # Overflow can also happen here for really long periods (~8e17 years)
452
+ Base. hash (x:: Year , h:: UInt ) = hash (12 * value (x), h + otherperiod_seed)
453
+ Base. hash (x:: Month , h:: UInt ) = hash (value (x), h + otherperiod_seed)
454
+
446
455
Base. isless (x:: FixedPeriod , y:: OtherPeriod ) = throw (MethodError (isless, (x, y)))
447
456
Base. isless (x:: OtherPeriod , y:: FixedPeriod ) = throw (MethodError (isless, (x, y)))
448
457
449
- # truncating conversions to milliseconds and days:
458
+ # truncating conversions to milliseconds, nanoseconds and days:
459
+ # overflow can happen for periods longer than ~300,000 years
450
460
toms (c:: Nanosecond ) = div (value (c), 1000000 )
451
461
toms (c:: Microsecond ) = div (value (c), 1000 )
452
462
toms (c:: Millisecond ) = value (c)
0 commit comments