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

JuliaLang / julia / #37844

20 Jul 2024 12:09AM UTC coverage: 85.368% (-2.2%) from 87.523%
#37844

push

local

web-flow
Compat for `Base.@nospecializeinfer` (#55178)

This macro was added in v1.10 but was missing a compat notice.

75349 of 88264 relevant lines covered (85.37%)

15222940.81 hits per line

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

49.21
/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
140✔
6

7
# TimeType arithmetic
8
(+)(x::TimeType) = x
×
9
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
101✔
10
(-)(x::T, y::T) where {T<:AbstractDateTime} = x.instant - y.instant
19✔
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
"""
21
(+)(dt::Date, t::Time) = DateTime(dt ,t)
×
22
(+)(t::Time, dt::Date) = DateTime(dt, t)
×
23

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

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

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

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

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

95
# AbstractArray{TimeType}, AbstractArray{TimeType}
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)
×
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