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

DateTime conversion issues with Int32 on 32-bit #13581

Merged
merged 1 commit into from
Oct 30, 2015

Conversation

omus
Copy link
Member

@omus omus commented Oct 13, 2015

Dates functions unix2datetime and julian2datetime have issues on 32-bit systems due to the use integer literals.

Here is a brief example of the issue which can be used on 64-bit systems:

julia> import Base.Dates: UNIXEPOCH, UTM

julia> function unix2datetime32(x)
           rata = UNIXEPOCH + round(Int64, Int32(1000) * x)
           return DateTime(UTM(rata))
       end
unix2datetime32 (generic function with 1 method)

julia> v = Int64(Dates.datetime2unix(DateTime(1915,1,1,12)))
-1735646400

julia> unix2datetime32(Int64(v))
1915-01-01T12:00:00

julia> unix2datetime32(Int32(v))
1969-12-26T10:46:27.584


@test Dates.unix2datetime(unix) == dt
@test Dates.julia2datetime(julian) == dt
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing new line at the end of the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also misspelled julian2datetime as julia2datetime

@yuyichao
Copy link
Contributor

Otherwise, LGTM.

On 32-bit systems when using unix2datetime or julian2datetime and
passing a Int32 will result in a DateTime in an extremely limited range:

```
julia> Dates.unix2datetime(div(typemin(Int32), Int32(1000)))
1969-12-07T03:28:37

julia> Dates.unix2datetime(div(typemax(Int32), Int32(1000)))
1970-01-25T20:31:23
```
omus added a commit to invenia/TimeZones.jl that referenced this pull request Oct 13, 2015
@tkelman tkelman added the domain:dates Dates, times, and the Dates stdlib module label Oct 13, 2015
@omus
Copy link
Member Author

omus commented Oct 30, 2015

cc: @quinnj

quinnj added a commit that referenced this pull request Oct 30, 2015
DateTime conversion issues with Int32 on 32-bit
@quinnj quinnj merged commit 197672f into JuliaLang:master Oct 30, 2015
@quinnj
Copy link
Member

quinnj commented Oct 30, 2015

Thanks for the ping!

@tkelman
Copy link
Contributor

tkelman commented Oct 30, 2015

this is also a bug on release-0.4, yeah?

@quinnj
Copy link
Member

quinnj commented Oct 30, 2015

yes

@omus omus deleted the dates_conversion_Int32 branch October 30, 2015 21:00
tkelman pushed a commit that referenced this pull request Oct 31, 2015
On 32-bit systems when using unix2datetime or julian2datetime and
passing a Int32 will result in a DateTime in an extremely limited range:

```
julia> Dates.unix2datetime(div(typemin(Int32), Int32(1000)))
1969-12-07T03:28:37

julia> Dates.unix2datetime(div(typemax(Int32), Int32(1000)))
1970-01-25T20:31:23
```

(cherry picked from commit 079eec8)
ref #13581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:dates Dates, times, and the Dates stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants