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

JuliaLang / julia / #37496

pending completion
#37496

push

local

web-flow
Fix LazyString building with non-ASCII preceding $ (#49248)

1 of 1 new or added line in 1 file covered. (100.0%)

72822 of 83142 relevant lines covered (87.59%)

36432669.51 hits per line

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

84.78
/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)
1✔
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))
46,213✔
11
guess(a::Date, b::Date, c) = Int64(div(value(b - a), days(c)))
444,004✔
12
len(a::Time, b::Time, c) = Int64(div(value(b - a), tons(c)))
154✔
13
function len(a, b, c)
490,217✔
14
    lo, hi, st = min(a, b), max(a, b), abs(c)
490,217✔
15
    i = guess(a, b, c)
490,217✔
16
    v = lo + st * i
490,217✔
17
    prev = v  # Ensure `v` does not overflow
490,217✔
18
    while v <= hi && prev <= v
527,241,747✔
19
        prev = v
526,751,530✔
20
        v += st
526,751,530✔
21
        i += 1
526,751,530✔
22
    end
526,751,530✔
23
    return i - 1
490,217✔
24
end
25
Base.length(r::StepRange{<:TimeType}) = isempty(r) ? Int64(0) : len(r.start, r.stop, r.step) + 1
496,748✔
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)))
4✔
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
242,644✔
32
    if isa(step, AbstractFloat)
242,644✔
33
        throw(ArgumentError("StepRange should not be used with floating point"))
×
34
    end
35
    z = zero(step)
242,644✔
36
    step == z && throw(ArgumentError("step cannot be zero"))
242,644✔
37

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

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

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

64
+(x::Period, r::AbstractRange{<:TimeType}) = (x + first(r)):step(r):(x + last(r))
1✔
65
+(r::AbstractRange{<:TimeType}, x::Period) = x + r
1✔
66
-(r::AbstractRange{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x)
1✔
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