Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request JuliaLang#13581 from omus/dates_conversion_Int32
Browse files Browse the repository at this point in the history
DateTime conversion issues with Int32 on 32-bit
  • Loading branch information
quinnj committed Oct 30, 2015
2 parents 8307c6d + 079eec8 commit 197672f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Base.convert{R<:Real}(::Type{R},x::Date) = convert(R,value(x))
### External Conversions
const UNIXEPOCH = value(DateTime(1970)) #Rata Die milliseconds for 1970-01-01T00:00:00
function unix2datetime(x)
rata = UNIXEPOCH + round(Int64,1000*x)
rata = UNIXEPOCH + round(Int64, Int64(1000) * x)
return DateTime(UTM(rata))
end
# Returns unix seconds since 1970-01-01T00:00:00
Expand All @@ -32,7 +32,7 @@ datetime2rata(dt::DateTime) = days(dt)
# Julian conversions
const JULIANEPOCH = value(DateTime(-4713,11,24,12))
function julian2datetime(f)
rata = JULIANEPOCH + round(Int64,86400000*f)
rata = JULIANEPOCH + round(Int64, Int64(86400000) * f)
return DateTime(UTM(rata))
end
# Returns # of julian days since -4713-11-24T12:00:00
Expand Down
9 changes: 9 additions & 0 deletions test/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ end
@test Dates.Year(3) < Dates.Month(37)
@test_throws InexactError convert(Dates.Year, Dates.Month(37))
@test_throws InexactError Dates.Month(Dates.Year(typemax(Int64)))

# Ensure that conversion of 32-bit integers work
let dt = DateTime(1915,1,1,12)
unix = Int32(Dates.datetime2unix(dt))
julian = Int32(Dates.datetime2julian(dt))

@test Dates.unix2datetime(unix) == dt
@test Dates.julian2datetime(julian) == dt
end

0 comments on commit 197672f

Please sign in to comment.