Skip to content

Commit

Permalink
Replace Union{Date,DateTime} by TimeType
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
femtotrader committed Nov 19, 2016
1 parent a825687 commit b8dea88
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/TimeFrames.jl
@@ -1,6 +1,7 @@
module TimeFrames

import Base: range
using Base.Dates: TimeType

export TimeFrame, Boundary
export YearBegin, YearEnd
Expand Down Expand Up @@ -231,9 +232,7 @@ function apply(tf::TimeFrame, dt)
dt_grouper(tf, typeof(dt))(dt)
end

typealias DateOrDateTime Union{Date,DateTime}

function range(dt1::DateOrDateTime, tf::AbstractPeriodFrame, dt2::DateOrDateTime; apply_tf=true)
function range(dt1::TimeType, tf::AbstractPeriodFrame, dt2::TimeType; apply_tf=true)
td = period_step(typeof(dt2))
if apply_tf
apply(tf, dt1):tf.time_period:apply(tf, dt2-td)
Expand All @@ -242,19 +241,19 @@ function range(dt1::DateOrDateTime, tf::AbstractPeriodFrame, dt2::DateOrDateTime
end
end

function range(dt1::DateOrDateTime, td::Dates.Period, dt2::DateOrDateTime; apply_tf=true)
function range(dt1::TimeType, td::Dates.Period, dt2::TimeType; apply_tf=true)
range(dt1, TimeFrame(td), dt2; apply_tf=apply_tf)
end

function range(dt1::DateOrDateTime, tf::AbstractPeriodFrame, len::Integer)
function range(dt1::TimeType, tf::AbstractPeriodFrame, len::Integer)
range(dt1, tf.time_period, len)
end

function range(tf::AbstractPeriodFrame, dt2::DateOrDateTime, len::Integer)
function range(tf::AbstractPeriodFrame, dt2::TimeType, len::Integer)
range(dt2 - len * tf.time_period, tf.time_period, len)
end

function range(td::Dates.Period, dt2::DateOrDateTime, len::Integer)
function range(td::Dates.Period, dt2::TimeType, len::Integer)
range(TimeFrame(td), dt2, len)
end

Expand Down

2 comments on commit b8dea88

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

It's considered bad practice to extend Base functions on Base types, like a couple of these methods do. That can change the behavior of unrelated code when this package is imported. Would be best to make sure that at least one of the input types is from this package to avoid global side effects.

@femtotrader
Copy link
Owner Author

Choose a reason for hiding this comment

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

issue opened #26

Please sign in to comment.