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

JuliaLang / julia / #37762

28 Apr 2024 07:31AM UTC coverage: 86.373% (-1.1%) from 87.431%
#37762

push

local

web-flow
infer_effects: add `optimize::Bool` optional argument (#54241)

`optimize=false` would be useful for testing effects refinements with
post-optimization analysis.

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

947 existing lines in 40 files now uncovered.

75087 of 86933 relevant lines covered (86.37%)

14939860.08 hits per line

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

80.95
/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
1,008,321✔
6

7
# TimeType arithmetic
8
(+)(x::TimeType) = x
×
9
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
1,003,748✔
10
(-)(x::T, y::T) where {T<:AbstractDateTime} = x.instant - y.instant
41,553✔
11
(-)(x::AbstractDateTime, y::AbstractDateTime) = -(promote(x, y)...)
×
12

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

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

24
# TimeType-Year arithmetic
25
function (+)(dt::DateTime, y::Year)
149,607✔
26
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
169,607✔
27
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
169,607✔
28
end
29
function (+)(dt::Date,y::Year)
919,738✔
30
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
919,909✔
31
    return Date(ny, m, d <= ld ? d : ld)
919,738✔
32
end
33
function (-)(dt::DateTime,y::Year)
10✔
34
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
10✔
35
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
10✔
36
end
37
function (-)(dt::Date,y::Year)
10✔
38
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
10✔
39
    return Date(ny, m, d <= ld ? d : ld)
10✔
40
end
41

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

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

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

75
(+)(x::Date, y::Quarter) = x + Month(y)
151,529✔
76
(-)(x::Date, y::Quarter) = x - Month(y)
10✔
77
(+)(x::DateTime, y::Quarter) = x + Month(y)
135,465✔
78
(-)(x::DateTime, y::Quarter) = x - Month(y)
10✔
79
(+)(x::Date, y::Week) = return Date(UTD(value(x) + 7 * value(y)))
71,521✔
80
(-)(x::Date, y::Week) = return Date(UTD(value(x) - 7 * value(y)))
10✔
81
(+)(x::Date, y::Day)  = return Date(UTD(value(x) + value(y)))
260,930✔
82
(-)(x::Date, y::Day)  = return Date(UTD(value(x) - value(y)))
220,675✔
83
(+)(x::DateTime, y::Period) = return DateTime(UTM(value(x) + toms(y)))
526,206,981✔
84
(-)(x::DateTime, y::Period) = return DateTime(UTM(value(x) - toms(y)))
20,858✔
85
(+)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) + tons(y)))
36,984✔
86
(-)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) - tons(y)))
62✔
87
(+)(y::Period, x::TimeType) = x + y
2✔
88

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

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

99
# Allow dates, times, and time zones to broadcast as unwrapped scalars
100
Base.Broadcast.broadcastable(x::AbstractTime) = Ref(x)
34✔
UNCOV
101
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