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

Added Compat.AbstractDateTime #443

Merged
merged 3 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Currently, the `@compat` macro supports the following syntaxes:

## New types

Currently, no new exported types are introduced by Compat.
* `Compat.AbstractDateTime` is an alias for `Compat.Dates.AbstractDateTime` as of ([#25227]) and `Compat.Dates.TimeType` prior to that.

## Developer tips

Expand Down
6 changes: 6 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@ else
import Dates
end

if VERSION < v"0.7.0-DEV.3216"
const AbstractDateTime = Compat.Dates.TimeType
Copy link
Member

Choose a reason for hiding this comment

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

Seems slightly dangerous to use with dispatch. You could accidentally be given a Date or Time. I'm not sure what a better solution would be ATM

Copy link
Member

Choose a reason for hiding this comment

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

Possibly just having a const AbstractDateTime = Union{DateTime, ZonedDateTime} in TimeZones.jl would be a better solution. Doing this in Compat would make TimeZones a requirement in Compat which is probably worse.

Copy link
Contributor Author

@rofinn rofinn Jan 1, 2018

Choose a reason for hiding this comment

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

That could also work for our use cases, but I figured it's better to write code that is a bit too general than too restrictive. IFAICT, the worst case scenario is that someone passes in a Date or Time and the code errors at a later point... making the traceback more complicated.

Copy link
Member

Choose a reason for hiding this comment

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

A possible alternative solution is to implement @compat AbstractDateTime which would re-write this as a Union{DateTime,ZonedDateTime}. That would probably be a bit too annoying though.

else
const AbstractDateTime = Compat.Dates.AbstractDateTime
end

Copy link
Member

Choose a reason for hiding this comment

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

Probably should export this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like an odd choice given that it isn't exported in base.

Copy link
Member

Choose a reason for hiding this comment

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

You are right here. Don't export this since it isn't exported in Base

if VERSION < v"0.7.0-DEV.3052"
const Printf = Base.Printf
else
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ end
# 0.7.0-DEV.3172
@test replace("abcb", "b"=>"c") == "accc"
@test replace("abcb", "b"=>"c", count=1) == "accb"
# 0.7.0-DEV.3216
@test Compat.AbstractDateTime === (isdefined(Compat.Dates, :AbstractDateTime) ? Compat.Dates.AbstractDateTime : Compat.Dates.TimeType)
@test Compat.AbstractDateTime <: Compat.Dates.TimeType
@test Compat.Dates.DateTime <: Compat.AbstractDateTime

if VERSION < v"0.6.0"
include("deprecated.jl")
Expand Down