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

JuliaLang / julia / #38162

06 Aug 2025 08:25PM UTC coverage: 25.688% (-43.6%) from 69.336%
#38162

push

local

web-flow
fix runtime cglobal builtin function implementation (#59210)

This had failed to be updated for the LazyLibrary changes to codegen.

12976 of 50513 relevant lines covered (25.69%)

676965.51 hits per line

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

4.76
/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✔
6

7
# TimeType arithmetic
8
(+)(x::TimeType) = x
×
9
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
×
10
(-)(x::T, y::T) where {T<:AbstractDateTime} = x.instant - y.instant
1✔
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)
×
26
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
×
27
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
×
28
end
29
function (+)(dt::Date,y::Year)
×
30
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
×
31
    return Date(ny, m, d <= ld ? d : ld)
×
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)
×
38
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
×
39
    return Date(ny, m, d <= ld ? d : ld)
×
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)
×
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)
×
48

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

56
function (+)(dt::Date, z::Month)
×
57
    y,m,d = yearmonthday(dt)
×
58
    ny = yearwrap(y, m, value(z))
×
59
    mm = monthwrap(m, value(z)); ld = daysinmonth(ny, mm)
×
60
    return Date(ny, mm, d <= ld ? d : ld)
×
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)
×
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)))
×
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)))
×
82
(-)(x::Date, y::Day)  = return Date(UTD(value(x) - value(y)))
×
83
(+)(x::DateTime, y::Period) = return DateTime(UTM(value(x) + toms(y)))
×
84
(-)(x::DateTime, y::Period) = return DateTime(UTM(value(x) - toms(y)))
1✔
85
(+)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) + tons(y)))
×
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