• 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

58.7
/stdlib/Dates/src/ranges.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# Date/DateTime Ranges
4

5
StepRange{<:Dates.DatePeriod,<:Real}(start, step, stop) =
×
6
    throw(ArgumentError("must specify step as a Period when constructing Dates ranges"))
7
Base.:(:)(a::T, b::T) where {T<:Date} = (:)(a, Day(1), b)
×
8

9
# Given a start and end date, how many steps/periods are in between
10
guess(a::DateTime, b::DateTime, c) = floor(Int64, (Int128(value(b)) - Int128(value(a))) / toms(c))
3✔
11
guess(a::Date, b::Date, c) = Int64(div(value(b - a), days(c)))
31✔
12
len(a::Time, b::Time, c) = Int64(div(value(b - a), tons(c)))
×
13
function len(a, b, c)
3✔
14
    lo, hi, st = min(a, b), max(a, b), abs(c)
34✔
15
    i = guess(a, b, c)
34✔
16
    v = lo + st * i
34✔
17
    prev = v  # Ensure `v` does not overflow
34✔
18
    while v <= hi && prev <= v
68✔
19
        prev = v
34✔
20
        v += st
34✔
21
        i += 1
34✔
22
    end
34✔
23
    return i - 1
34✔
24
end
25
Base.length(r::StepRange{<:TimeType}) = isempty(r) ? Int64(0) : len(r.start, r.stop, r.step) + 1
14✔
26
# Period ranges hook into Int64 overflow detection
27
Base.length(r::StepRange{<:Period}) = length(StepRange(value(r.start), value(r.step), value(r.stop)))
×
28
Base.checked_length(r::StepRange{<:Period}) = Base.checked_length(StepRange(value(r.start), value(r.step), value(r.stop)))
×
29

30
# Overload Base.steprange_last because `step::Period` may be a variable amount of time (e.g. for Month and Year)
31
function Base.steprange_last(start::T, step, stop) where T<:TimeType
19✔
32
    if isa(step, AbstractFloat)
21✔
33
        throw(ArgumentError("StepRange should not be used with floating point"))
×
34
    end
35
    z = zero(step)
21✔
36
    step == z && throw(ArgumentError("step cannot be zero"))
21✔
37

38
    if stop == start
21✔
39
        last = stop
×
40
    else
41
        if (step > z) != (stop > start)
21✔
42
            last = Base.steprange_last_empty(start, step, stop)
×
43
        else
44
            diff = stop - start
21✔
45
            if (diff > zero(diff)) != (stop > start)
21✔
46
                throw(OverflowError("Difference between stop and start overflowed"))
×
47
            end
48
            remain = stop - (start + step * len(start, stop, step))
21✔
49
            last = stop - remain
21✔
50
        end
51
    end
52
    return last
21✔
53
end
54

55
import Base.in
56
function in(x::T, r::StepRange{T}) where T<:TimeType
×
57
    n = len(first(r), x, step(r)) + 1
×
58
    n >= 1 && n <= length(r) && r[n] == x
×
59
end
60

61
Base.iterate(r::StepRange{<:TimeType}) = length(r) <= 0 ? nothing : (r.start, (length(r), 1))
10✔
62
Base.iterate(r::StepRange{<:TimeType}, (l, i)) = l <= i ? nothing : (r.start + r.step * i, (l, i + 1))
55✔
63

64
+(x::Period, r::AbstractRange{<:TimeType}) = (x + first(r)):step(r):(x + last(r))
×
65
+(r::AbstractRange{<:TimeType}, x::Period) = x + r
×
66
-(r::AbstractRange{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x)
×
67
*(x::Period, r::AbstractRange{<:Real}) = (x * first(r)):(x * step(r)):(x * last(r))
×
68
*(r::AbstractRange{<:Real}, x::Period) = x * r
×
69
/(r::AbstractRange{<:P}, x::P) where {P<:Period} = (first(r)/x):(step(r)/x):(last(r)/x)
×
70

71
# Combinations of types and periods for which the range step is regular
72
Base.RangeStepStyle(::Type{<:OrdinalRange{<:TimeType, <:FixedPeriod}}) =
×
73
    Base.RangeStepRegular()
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

© 2025 Coveralls, Inc