Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type Dates.DateTime has no field utc_datetime #424

Open
lgeissbauer-btig opened this issue Jan 9, 2023 · 10 comments
Open

type Dates.DateTime has no field utc_datetime #424

lgeissbauer-btig opened this issue Jan 9, 2023 · 10 comments

Comments

@lgeissbauer-btig
Copy link
Contributor

julia> function utc_to_ny(date_time_utc::DateTime)::ZonedDateTime
               date_time_utc = ZonedDateTime(date_time_utc, tz"UTC")
               date_time_ny = TimeZones.astimezone(date_time_utc, tz"America/New_York")
                       return date_time_ny
           end
utc_to_ny (generic function with 1 method)

julia> JET.@report_call utc_to_ny(now())
═════ 2 possible errors found ═════
┌ @ REPL[23]:3 date_time_ny = astimezone(date_time_utc, America/New_York)
│┌ @ C:\.julia\packages\TimeZones\V28u7\src\conversions.jl:179 i = Core.kwcall(NamedTuple{(:by,)}(tuple(#24)), TimeZones.searchsortedlast, tz.transitions, zdt.utc_datetime)
││┌ @ sort.jl:285 Base.Sort.:(var"#searchsortedlast#5")(_10, _10, _10, _10, _3, v, x)
│││┌ @ sort.jl:285 searchsortedlast(v, x, Base.Sort.ord(lt, by, rev, order))
││││┌ @ sort.jl:283 searchsortedlast(v, x, Base.Sort.firstindex(v), Base.Sort.lastindex(v), o)
│││││┌ @ sort.jl:189 Base.Sort.lt(o, x, v[m])
││││││┌ @ ordering.jl:119 o.by(a)
│││││││┌ @ C:\.julia\packages\TimeZones\V28u7\src\conversions.jl:181 v.utc_datetime
││││││││┌ @ Base.jl:37 Base.getfield(x, f)
│││││││││ type Dates.DateTime has no field utc_datetime
││││││││└──────────────
││││││┌ @ ordering.jl:119 lt(o.order, o.by(a), o.by(b))
│││││││┌ @ ordering.jl:117 Base.Order.isless(a, b)
││││││││ no matching method found `isless(::DateTime, ::TimeZones.Transition)`: Base.Order.isless(a::DateTime, b::TimeZones.Transition)
│││││││└───────────────────

From JET.jl

@A1-Mathematik
Copy link

by=v -> typeof(v) == Transition ? v.utc_datetime : v,

@lgeissbauer-btig
Copy link
Contributor Author

by=v -> typeof(v) == Transition ? (v::Transition).utc_datetime : v

@lgeissbauer-btig
Copy link
Contributor Author

@aviatesk why isn't it clear that the v after the ? is typeof(v) == Transition

@aviatesk
Copy link

That form isn't inferrable. Use v isa Transition instead.

lgeissbauer-btig added a commit to lgeissbauer-btig/TimeZones.jl that referenced this issue Jan 12, 2023
@lgeissbauer-btig
Copy link
Contributor Author

if timezone.cutoff !== nothing && utc_datetime >= timezone.cutoff

@lgeissbauer-btig
Copy link
Contributor Author

@aviatesk why can't JET infere that timezone.cutoff !== nothing. How to fix it?

@lgeissbauer-btig
Copy link
Contributor Author

═════ 1 possible error found ═════
┌ @ REPL[31]:12 ZonedDateTime(zdt.utc_datetime, tz, zone)
│┌ @ C:\.julia\packages\TimeZones\V28u7\src\types\zoneddatetime.jl:19 utc_datetime TimeZones.:>= timezone.cutoff
││┌ @ operators.jl:429 y <= x
│││┌ @ operators.jl:405 x < y
││││┌ @ operators.jl:356 isless(x, y)
│││││ no matching method found `isless(::Nothing, ::DateTime)`: isless(x::Nothing, y::DateTime)
││││└────

@aviatesk
Copy link

Maybe the timezone.cutoff field is mutable? Then extract it into a local object.

@lgeissbauer-btig
Copy link
Contributor Author

cutoff::Union{DateTime,Nothing}

@lgeissbauer-btig
Copy link
Contributor Author

is not mutable

struct VariableTimeZone <: TimeZone
    name::String
    transitions::Vector{Transition}
    cutoff::Union{DateTime,Nothing}

    function VariableTimeZone(name::AbstractString, transitions::Vector{Transition}, cutoff::Union{DateTime,Nothing}=nothing)
        new(name, transitions, cutoff)
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants