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

ability to convert TmStruct to DateTime? #31524

Closed
vtjnash opened this issue Mar 28, 2019 · 4 comments · Fixed by #31575
Closed

ability to convert TmStruct to DateTime? #31524

vtjnash opened this issue Mar 28, 2019 · 4 comments · Fixed by #31575
Labels
dates Dates, times, and the Dates stdlib module good first issue Indicates a good issue for first-time contributors to Julia

Comments

@vtjnash
Copy link
Member

vtjnash commented Mar 28, 2019

The "obvious" attempts to type-cast this didn't seem to work:

julia> DateTime(Libc.strptime("%Y-%M-%dT%H:%M:%SZ", "2018-11-16T10:26:14Z"))
ERROR: MethodError: no method matching Int64(::Base.Libc.TmStruct)
Closest candidates are:
  Int64(::Union{Bool, Int32, Int64, UInt32, UInt64, UInt8, Int128, Int16, Int8, UInt128, UInt16}) at boot.jl:707
  Int64(::Ptr) at boot.jl:717
  Int64(::Float32) at float.jl:700
  ...
Stacktrace:
 [1] DateTime(::Base.Libc.TmStruct, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64) at /data/vtjnash/julia/usr/share/julia/stdlib/v1.2/Dates/src/types.jl:342 (repeats 2 times)
 [2] top-level scope at REPL[85]:1

julia> convert(DateTime, Libc.strptime("%Y-%M-%dT%H:%M:%SZ", "2018-11-16T10:26:14Z"))
ERROR: MethodError: Cannot `convert` an object of type Base.Libc.TmStruct to an object of type DateTime
Closest candidates are:
  convert(::Type{DateTime}, ::Date) at /data/vtjnash/julia/usr/share/julia/stdlib/v1.2/Dates/src/conversions.jl:30
  convert(::Type{DateTime}, ::Millisecond) at /data/vtjnash/julia/usr/share/julia/stdlib/v1.2/Dates/src/conversions.jl:34
  convert(::Type{T}, ::T) where T at essentials.jl:167
  ...
Stacktrace:
 [1] top-level scope at REPL[86]:1

julia> unix2datetime(time(Libc.strptime("%Y-%M-%dT%H:%M:%SZ", "2018-11-16T10:26:14Z")))
2018-01-16T15:26:14
@vtjnash vtjnash added the dates Dates, times, and the Dates stdlib module label Mar 28, 2019
@StefanKarpinski
Copy link
Member

StefanKarpinski commented Mar 29, 2019

I'm a little unclear on what the request is. Make this work? Or what the right way is? cc @quinnj

@quinnj
Copy link
Member

quinnj commented Mar 29, 2019

Yeah, we did discuss this originally, but it wasn't clear at the time which direction should take the dependency. Now we have libc.jl in Base and Dates as a stdlib, so it's a little more clear. Probably would be a great up-for-grabs kind of PR is someone wants to take it on.

@quinnj quinnj added the good first issue Indicates a good issue for first-time contributors to Julia label Mar 29, 2019
@StefanKarpinski
Copy link
Member

Can you describe what should be done? I can't tell from this discussion.

@KristofferC
Copy link
Member

Add a constructor DateTime(::Base.Libc.TmStruct)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants