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

JuliaLang / julia / #37997

29 Jan 2025 02:08AM UTC coverage: 17.283% (-68.7%) from 85.981%
#37997

push

local

web-flow
bpart: Start enforcing min_world for global variable definitions (#57150)

This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.

1 of 22 new or added lines in 3 files covered. (4.55%)

31430 existing lines in 188 files now uncovered.

7903 of 45728 relevant lines covered (17.28%)

98663.7 hits per line

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

0.0
/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
×
UNCOV
5
(-)(x::T, y::T) where {T<:Instant} = x.periods - y.periods
×
6

7
# TimeType arithmetic
8
(+)(x::TimeType) = x
×
UNCOV
9
(-)(x::T, y::T) where {T<:TimeType} = x.instant - y.instant
×
UNCOV
10
(-)(x::T, y::T) where {T<:AbstractDateTime} = x.instant - y.instant
×
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
UNCOV
25
function (+)(dt::DateTime, y::Year)
×
UNCOV
26
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
×
UNCOV
27
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
×
28
end
UNCOV
29
function (+)(dt::Date,y::Year)
×
UNCOV
30
    oy, m, d = yearmonthday(dt); ny = oy + value(y); ld = daysinmonth(ny, m)
×
UNCOV
31
    return Date(ny, m, d <= ld ? d : ld)
×
32
end
UNCOV
33
function (-)(dt::DateTime,y::Year)
×
UNCOV
34
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
×
UNCOV
35
    return DateTime(ny, m, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt))
×
36
end
UNCOV
37
function (-)(dt::Date,y::Year)
×
UNCOV
38
    oy, m, d = yearmonthday(dt); ny = oy - value(y); ld = daysinmonth(ny, m)
×
UNCOV
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)
UNCOV
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)
UNCOV
47
yearwrap(y, m1, m2) = y + fld(m1 + m2 - 1, 12)
×
48

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

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

UNCOV
75
(+)(x::Date, y::Quarter) = x + Month(y)
×
UNCOV
76
(-)(x::Date, y::Quarter) = x - Month(y)
×
UNCOV
77
(+)(x::DateTime, y::Quarter) = x + Month(y)
×
UNCOV
78
(-)(x::DateTime, y::Quarter) = x - Month(y)
×
UNCOV
79
(+)(x::Date, y::Week) = return Date(UTD(value(x) + 7 * value(y)))
×
UNCOV
80
(-)(x::Date, y::Week) = return Date(UTD(value(x) - 7 * value(y)))
×
UNCOV
81
(+)(x::Date, y::Day)  = return Date(UTD(value(x) + value(y)))
×
UNCOV
82
(-)(x::Date, y::Day)  = return Date(UTD(value(x) - value(y)))
×
UNCOV
83
(+)(x::DateTime, y::Period) = return DateTime(UTM(value(x) + toms(y)))
×
UNCOV
84
(-)(x::DateTime, y::Period) = return DateTime(UTM(value(x) - toms(y)))
×
UNCOV
85
(+)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) + tons(y)))
×
UNCOV
86
(-)(x::Time, y::TimePeriod) = return Time(Nanosecond(value(x) - tons(y)))
×
UNCOV
87
(+)(y::Period, x::TimeType) = x + y
×
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
UNCOV
100
Base.Broadcast.broadcastable(x::AbstractTime) = Ref(x)
×
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