• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37545

pending completion
#37545

push

local

web-flow
Fix jl_timing_show_method_instance for top-level thunks (#49862)

This was causing invalid pointer dereferences when the method instance
had no backing method.

72631 of 83733 relevant lines covered (86.74%)

33727021.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.13
/stdlib/Dates/src/arithmetic.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# Instant arithmetic
4
(+)(x::Instant) = x
×
5
(-)(x::T, y::T) where {T<:Instant} = x.periods - y.periods
134✔
6

7
# TimeType arithmetic
8
(+)(x::TimeType) = x
×
9
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
134✔
10
(-)(x::TimeType, y::TimeType) = -(promote(x, y)...)
×
11

12
# Date-Time arithmetic
13
"""
14
    dt::Date + t::Time -> DateTime
15

16
The addition of a `Date` with a `Time` produces a `DateTime`. The hour, minute, second, and millisecond parts of
17
the `Time` are used along with the year, month, and day of the `Date` to create the new `DateTime`.
18
Non-zero microseconds or nanoseconds in the `Time` type will result in an `InexactError` being thrown.
19
"""
20
(+)(dt::Date, t::Time) = DateTime(dt ,t)
×
21
(+)(t::Time, dt::Date) = DateTime(dt, t)
×
22

23
# TimeType-Year arithmetic
24
function (+)(dt::DateTime, y::Year)
21✔
25
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
63✔
26
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
21✔
27
end
28
function (+)(dt::Date,y::Year)
12✔
29
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
36✔
30
    return Date(ny, m, d <= ld ? d : ld)
12✔
31
end
32
function (-)(dt::DateTime,y::Year)
×
33
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
×
34
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
×
35
end
36
function (-)(dt::Date,y::Year)
2✔
37
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
6✔
38
    return Date(ny, m, d <= ld ? d : ld)
2✔
39
end
40

41
# TimeType-Month arithmetic
42
# monthwrap adds two months with wraparound behavior (i.e. 12 + 1 == 1)
43
monthwrap(m1, m2) = (v = mod1(m1 + m2, 12); return v < 0 ? 12 + v : v)
78✔
44
# yearwrap takes a starting year/month and a month to add and returns
45
# the resulting year with wraparound behavior (i.e. 2000-12 + 1 == 2001)
46
yearwrap(y, m1, m2) = y + fld(m1 + m2 - 1, 12)
26✔
47

48
function (+)(dt::DateTime, z::Month)
10✔
49
    y,m,d = yearmonthday(dt)
10✔
50
    ny = yearwrap(y, m, value(z))
10✔
51
    mm = monthwrap(m, value(z)); ld = daysinmonth(ny, mm)
30✔
52
    return DateTime(ny, mm, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
10✔
53
end
54

55
function (+)(dt::Date, z::Month)
11✔
56
    y,m,d = yearmonthday(dt)
11✔
57
    ny = yearwrap(y, m, value(z))
11✔
58
    mm = monthwrap(m, value(z)); ld = daysinmonth(ny, mm)
33✔
59
    return Date(ny, mm, d <= ld ? d : ld)
11✔
60
end
61
function (-)(dt::DateTime, z::Month)
4✔
62
    y,m,d = yearmonthday(dt)
4✔
63
    ny = yearwrap(y, m, -value(z))
4✔
64
    mm = monthwrap(m, -value(z)); ld = daysinmonth(ny, mm)
12✔
65
    return DateTime(ny, mm, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
4✔
66
end
67
function (-)(dt::Date, z::Month)
1✔
68
    y,m,d = yearmonthday(dt)
1✔
69
    ny = yearwrap(y, m, -value(z))
1✔
70
    mm = monthwrap(m, -value(z)); ld = daysinmonth(ny, mm)
3✔
71
    return Date(ny, mm, d <= ld ? d : ld)
1✔
72
end
73

74
(+)(x::Date, y::Quarter) = x + Month(y)
2✔
75
(-)(x::Date, y::Quarter) = x - Month(y)
×
76
(+)(x::DateTime, y::Quarter) = x + Month(y)
×
77
(-)(x::DateTime, y::Quarter) = x - Month(y)
×
78
(+)(x::Date, y::Week) = return Date(UTD(value(x) + 7 * value(y)))
2✔
79
(-)(x::Date, y::Week) = return Date(UTD(value(x) - 7 * value(y)))
×
80
(+)(x::Date, y::Day)  = return Date(UTD(value(x) + value(y)))
256✔
81
(-)(x::Date, y::Day)  = return Date(UTD(value(x) - value(y)))
33✔
82
(+)(x::DateTime, y::Period) = return DateTime(UTM(value(x) + toms(y)))
906✔
83
(-)(x::DateTime, y::Period) = return DateTime(UTM(value(x) - toms(y)))
26✔
84
(+)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) + tons(y)))
10✔
85
(-)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) - tons(y)))
×
86
(+)(y::Period, x::TimeType) = x + y
×
87

88
# Missing support
89
(+)(x::AbstractTime, y::Missing) = missing
×
90
(+)(x::Missing, y::AbstractTime) = missing
×
91
(-)(x::AbstractTime, y::Missing) = missing
×
92
(-)(x::Missing, y::AbstractTime) = missing
×
93

94
# AbstractArray{TimeType}, AbstractArray{TimeType}
95
(-)(x::OrdinalRange{T}, y::OrdinalRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)
×
96
(-)(x::AbstractRange{T}, y::AbstractRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)
×
97

98
# Allow dates, times, and time zones to broadcast as unwrapped scalars
99
Base.Broadcast.broadcastable(x::AbstractTime) = Ref(x)
34✔
100
Base.Broadcast.broadcastable(x::TimeZone) = Ref(x)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc