Discussion about DateTime from POSIX timestamp. Was (incorrect assumption): Dates in Windows - error in datetime from posix

No, not for utc_datetime = DateTime(mtime_int) because is expects a year.

That’s very strange, because I get the same you do, unless I use unix2datetime(mtime_int) which is for that.

Note:

julia> typemax(DateTime)
146138512-12-31T23:59:59

despite that you can go higher, e.g. but a bit higher than this you overflow:

julia> utc_datetime = DateTime(291999699)
291999699-01-01T00:00:00

julia> dump(ans)
DateTime
  instant: Dates.UTInstant{Millisecond}
    periods: Millisecond
      value: Int64 9214620453907200000

julia> bitstring(9214620453907200000)
"0111111111100000111010000111101101001111001011111111100000000000"

we don’t actually need all those years… and we actually probably shouldn’t allow over typemax, so plausibly we could do unix2datetime for you implicitly if the “year” is over some value, e.g. 146138512 which corresponds to:

julia> unix2datetime(146138513)
1974-08-19T10:01:53

I’m not sure what other languages do, but it seems plausible, I doubt constructors are very speed-critical, but this wouldn’t be as general, not work for old timestamps (who cares?, those would use the alternative). This might be thought of as too magical.

For such high numbers I think we can, and should just ignore the optional m[onth] etc:

function DateTime(y::Int64, m::Int64=1, d::Int64=1,
                  h::Int64=0, mi::Int64=0, s::Int64=0, ms::Int64=0, ampm::AMPM=TWENTYFOURHOUR)
..