Skip to content

Commit

Permalink
Fix typo in comment, remove unnecessary escaping, and simplify toms (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Jul 6, 2022
1 parent 8cc5445 commit 4d50ff8
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions stdlib/Dates/src/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ coarserperiod(::Type{Month}) = (Year, 12)
CompoundPeriod
A `CompoundPeriod` is useful for expressing time periods that are not a fixed multiple of
smaller periods. For example, \"a year and a day\" is not a fixed number of days, but can
smaller periods. For example, "a year and a day" is not a fixed number of days, but can
be expressed using a `CompoundPeriod`. In fact, a `CompoundPeriod` is automatically
generated by addition of different period types, e.g. `Year(1) + Day(1)` produces a
`CompoundPeriod` result.
Expand Down Expand Up @@ -482,7 +482,7 @@ const zero_or_fixedperiod_seed = UInt === UInt64 ? 0x5b7fc751bba97516 : 0xeae0fd
const nonzero_otherperiod_seed = UInt === UInt64 ? 0xe1837356ff2d2ac9 : 0x170d1b00
otherperiod_seed(x::OtherPeriod) = iszero(value(x)) ? zero_or_fixedperiod_seed : nonzero_otherperiod_seed
# tons() will overflow for periods longer than ~300,000 years, implying a hash collision
# which is relatively harmless given how infrequent such periods should appear
# which is relatively harmless given how infrequently such periods should appear
Base.hash(x::FixedPeriod, h::UInt) = hash(tons(x), h + zero_or_fixedperiod_seed)
# Overflow can also happen here for really long periods (~8e17 years)
Base.hash(x::Year, h::UInt) = hash(12 * value(x), h + otherperiod_seed(x))
Expand Down Expand Up @@ -511,11 +511,7 @@ toms(c::Millisecond) = value(c)
toms(c::Second) = 1000 * value(c)
toms(c::Minute) = 60000 * value(c)
toms(c::Hour) = 3600000 * value(c)
toms(c::Day) = 86400000 * value(c)
toms(c::Week) = 604800000 * value(c)
toms(c::Month) = 86400000.0 * 30.436875 * value(c)
toms(c::Quarter) = 86400000.0 * 91.310625 * value(c)
toms(c::Year) = 86400000.0 * 365.2425 * value(c)
toms(c::Period) = 86400000 * days(c)
toms(c::CompoundPeriod) = isempty(c.periods) ? 0.0 : Float64(sum(toms, c.periods))
tons(x) = toms(x) * 1000000
tons(x::Microsecond) = value(x) * 1000
Expand Down

0 comments on commit 4d50ff8

Please sign in to comment.