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

Dates.format dispatches to TimeZones.format #374

Open
samtkaplan opened this issue Feb 23, 2022 · 2 comments
Open

Dates.format dispatches to TimeZones.format #374

samtkaplan opened this issue Feb 23, 2022 · 2 comments

Comments

@samtkaplan
Copy link

This causes an error. For example in Julia 1.7.2, I see:

julia> using TimeZones, Dates

julia> Dates.format(now(), "yyyy-mm-ddTHH:MM:SSZ")
ERROR: type DateTime has no field zone
Stacktrace:
 [1] getproperty
   @ ./Base.jl:42 [inlined]
 [2] format(io::IOBuffer, d::Dates.DatePart{'Z'}, zdt::DateTime, locale::Dates.DateLocale)
   @ TimeZones ~/.julia/packages/TimeZones/1ALMR/src/parse.jl:81
 [3] macro expansion
   @ /opt/julia/share/julia/stdlib/v1.7/Dates/src/io.jl:663 [inlined]
 [4] format(io::IOBuffer, dt::DateTime, fmt::DateFormat{Symbol("yyyy-mm-ddTHH:MM:SSZ"), Tuple{Dates.DatePart{'y'}, Dates.Delim{Char, 1}, Dates.DatePart{'m'}, Dates.Delim{Char, 1}, Dates.DatePart{'d'}, Dates.Delim{Char, 1}, Dates.DatePart{'H'}, Dates.Delim{Char, 1}, Dates.DatePart{'M'}, Dates.Delim{Char, 1}, Dates.DatePart{'S'}, Dates.DatePart{'Z'}}})
   @ Dates /opt/julia/share/julia/stdlib/v1.7/Dates/src/io.jl:658
 [5] format(dt::DateTime, fmt::DateFormat{Symbol("yyyy-mm-ddTHH:MM:SSZ"), Tuple{Dates.DatePart{'y'}, Dates.Delim{Char, 1}, Dates.DatePart{'m'}, Dates.Delim{Char, 1}, Dates.DatePart{'d'}, Dates.Delim{Char, 1}, Dates.DatePart{'H'}, Dates.Delim{Char, 1}, Dates.DatePart{'M'}, Dates.Delim{Char, 1}, Dates.DatePart{'S'}, Dates.DatePart{'Z'}}}, bufsize::Int64)
   @ Dates /opt/julia/share/julia/stdlib/v1.7/Dates/src/io.jl:670
 [6] format(dt::DateTime, fmt::DateFormat{Symbol("yyyy-mm-ddTHH:MM:SSZ"), Tuple{Dates.DatePart{'y'}, Dates.Delim{Char, 1}, Dates.DatePart{'m'}, Dates.Delim{Char, 1}, Dates.DatePart{'d'}, Dates.Delim{Char, 1}, Dates.DatePart{'H'}, Dates.Delim{Char, 1}, Dates.DatePart{'M'}, Dates.Delim{Char, 1}, Dates.DatePart{'S'}, Dates.DatePart{'Z'}}})
   @ Dates /opt/julia/share/julia/stdlib/v1.7/Dates/src/io.jl:669
 [7] format(dt::DateTime, f::String; locale::Dates.DateLocale)
   @ Dates /opt/julia/share/julia/stdlib/v1.7/Dates/src/io.jl:709
 [8] format(dt::DateTime, f::String)
   @ Dates /opt/julia/share/julia/stdlib/v1.7/Dates/src/io.jl:709
 [9] top-level scope
   @ REPL[3]:1
@omus
Copy link
Member

omus commented Feb 25, 2022

Related upstream issue: JuliaLang/julia#29339

@omus
Copy link
Member

omus commented Feb 25, 2022

You can work around this problem by escaping the characters you want to treat as literals:

julia> using TimeZones, Dates

julia> Dates.format(now(), "yyyy-mm-dd\\THH:MM:SS\\Z")
"2022-02-25T10:03:06Z"

julia> Dates.format(now(), dateformat"yyyy-mm-dd\THH:MM:SS\Z")
"2022-02-25T10:03:14Z"

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

2 participants