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

JuliaLang / julia / #37527

pending completion
#37527

push

local

web-flow
make `IRShow.method_name` inferrable (#49607)

18 of 18 new or added lines in 3 files covered. (100.0%)

68710 of 81829 relevant lines covered (83.97%)

33068903.12 hits per line

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

73.91
/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))
35✔
11
guess(a::Date, b::Date, c) = Int64(div(value(b - a), days(c)))
143✔
12
len(a::Time, b::Time, c) = Int64(div(value(b - a), tons(c)))
5✔
13
function len(a, b, c)
178✔
14
    lo, hi, st = min(a, b), max(a, b), abs(c)
178✔
15
    i = guess(a, b, c)
178✔
16
    v = lo + st * i
178✔
17
    prev = v  # Ensure `v` does not overflow
178✔
18
    while v <= hi && prev <= v
356✔
19
        prev = v
178✔
20
        v += st
178✔
21
        i += 1
178✔
22
    end
178✔
23
    return i - 1
178✔
24
end
25
Base.length(r::StepRange{<:TimeType}) = isempty(r) ? Int64(0) : len(r.start, r.stop, r.step) + 1
175✔
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)))
5✔
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
52✔
32
    if isa(step, AbstractFloat)
52✔
33
        throw(ArgumentError("StepRange should not be used with floating point"))
×
34
    end
35
    z = zero(step)
52✔
36
    step == z && throw(ArgumentError("step cannot be zero"))
52✔
37

38
    if stop == start
52✔
39
        last = stop
2✔
40
    else
41
        if (step > z) != (stop > start)
50✔
42
            last = Base.steprange_last_empty(start, step, stop)
1✔
43
        else
44
            diff = stop - start
49✔
45
            if (diff > zero(diff)) != (stop > start)
49✔
46
                throw(OverflowError("Difference between stop and start overflowed"))
×
47
            end
48
            remain = stop - (start + step * len(start, stop, step))
49✔
49
            last = stop - remain
49✔
50
        end
51
    end
52
    return last
52✔
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))
23✔
62
Base.iterate(r::StepRange{<:TimeType}, (l, i)) = l <= i ? nothing : (r.start + r.step * i, (l, i + 1))
91,646✔
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))
7✔
68
*(r::AbstractRange{<:Real}, x::Period) = x * r
3✔
69
/(r::AbstractRange{<:P}, x::P) where {P<:Period} = (first(r)/x):(step(r)/x):(last(r)/x)
1✔
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