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

JuliaLang / julia / #37539

pending completion
#37539

push

local

web-flow
add devdocs how to profile package precompilation with tracy (#49784)

1 of 1 new or added line in 1 file covered. (100.0%)

72624 of 83590 relevant lines covered (86.88%)

35576540.76 hits per line

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

79.03
/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
906,703✔
6

7
# TimeType arithmetic
8
(+)(x::TimeType) = x
×
9
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
906,975✔
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)
145,050✔
25
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
435,150✔
26
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
145,050✔
27
end
28
function (+)(dt::Date,y::Year)
883,170✔
29
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
2,649,510✔
30
    return Date(ny, m, d <= ld ? d : ld)
883,170✔
31
end
32
function (-)(dt::DateTime,y::Year)
10✔
33
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
30✔
34
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
10✔
35
end
36
function (-)(dt::Date,y::Year)
12✔
37
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
36✔
38
    return Date(ny, m, d <= ld ? d : ld)
12✔
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)
3,586,183✔
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)
1,202,061✔
47

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

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

74
(+)(x::Date, y::Quarter) = x + Month(y)
101,958✔
75
(-)(x::Date, y::Quarter) = x - Month(y)
10✔
76
(+)(x::DateTime, y::Quarter) = x + Month(y)
101,905✔
77
(-)(x::DateTime, y::Quarter) = x - Month(y)
10✔
78
(+)(x::Date, y::Week) = return Date(UTD(value(x) + 7 * value(y)))
54,139✔
79
(-)(x::Date, y::Week) = return Date(UTD(value(x) - 7 * value(y)))
10✔
80
(+)(x::Date, y::Day)  = return Date(UTD(value(x) + value(y)))
177,662✔
81
(-)(x::Date, y::Day)  = return Date(UTD(value(x) - value(y)))
220,674✔
82
(+)(x::DateTime, y::Period) = return DateTime(UTM(value(x) + toms(y)))
526,169,883✔
83
(-)(x::DateTime, y::Period) = return DateTime(UTM(value(x) - toms(y)))
20,846✔
84
(+)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) + tons(y)))
36,989✔
85
(-)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) - tons(y)))
62✔
86
(+)(y::Period, x::TimeType) = x + y
2✔
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)
×
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