type Dates.DateTime has no field utc_datetime
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
https://github.com/JuliaTime/TimeZones.jl/blob/f8f39b3100334a0079f525304f7dddc7656204da/src/conversions.jl#L181
by=v -> typeof(v) == Transition ? (v::Transition).utc_datetime : v
@aviatesk why isn't it clear that the v after the ? is typeof(v) == Transition
That form isn't inferrable. Use v isa Transition instead.
https://github.com/JuliaTime/TimeZones.jl/blob/f8f39b3100334a0079f525304f7dddc7656204da/src/types/zoneddatetime.jl#L19
@aviatesk why can't JET infere that timezone.cutoff !== nothing. How to fix it?
═════ 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)
││││└────
Maybe the timezone.cutoff field is mutable? Then extract it into a local object.
https://github.com/JuliaTime/TimeZones.jl/blob/906cea08c2ca4a5c76b12e14fb60d5df7990fbf7/src/types/variabletimezone.jl#L16
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