Skip to content

Commit

Permalink
minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
felipenoris committed Jun 18, 2018
1 parent b3a4308 commit 7581db2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/bdays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Returns `true` otherwise.
"""
function isbday(hc::HolidayCalendar, dt::Date) :: Bool
if _getcachestate(hc)
hcc :: HolidayCalendarCache = _getholidaycalendarcache(hc)
return isbday(hcc, dt)
return isbday(_getholidaycalendarcache(hc), dt)
else
return !(isweekend(dt) || isholiday(hc, dt))
end
Expand Down Expand Up @@ -103,8 +102,7 @@ Computation is always based on next Business Day if given dates are not Business
"""
function bdayscount(hc::HolidayCalendar, dt0::Date, dt1::Date) :: Int
if _getcachestate(hc)
hcc::HolidayCalendarCache = _getholidaycalendarcache(hc)
return bdayscount(hcc, dt0, dt1)
return bdayscount(_getholidaycalendarcache(hc), dt0, dt1)
else
dt0 = tobday(hc, dt0)
dt1 = tobday(hc, dt1)
Expand Down
9 changes: 3 additions & 6 deletions src/holidaycalendar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ abstract type HolidayCalendar end

Base.string(hc::HolidayCalendar) = string(typeof(hc))

function symtocalendar(sym::Symbol)
local result::HolidayCalendar
function symtocalendar(sym::Symbol) :: HolidayCalendar

if isdefined(BusinessDays, sym) && eval(BusinessDays, sym) <: HolidayCalendar
result = eval(BusinessDays, sym)()
return eval(BusinessDays, sym)()
elseif isdefined(current_module(), sym) && eval(current_module(), sym) <: HolidayCalendar
result = eval(current_module(), sym)()
return eval(current_module(), sym)()
else
error("$sym is not a valid HolidayCalendar.")
end

return result
end

@inline strtocalendar(str::AbstractString) = symtocalendar(Symbol(str))
Expand Down
8 changes: 4 additions & 4 deletions src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ listholidays(calendar, dt0::Date, dt1::Date) = listholidays(convert(HolidayCalen
Returns the list of business days between `dt0` and `dt1`.
"""
function listbdays(hc::HolidayCalendar, dt0::Date, dt1::Date)
d = tobday(hc,min(dt0,dt1))
d = tobday(hc, min(dt0, dt1))
d1 = max(dt0, dt1)

# empty result
if d > d1
return Array{Date}(0)
return Vector{Date}()
end

n = Dates.value(d1) - Dates.value(d) + 1
raw_vec = Array{Date}(n)
raw_vec = Vector{Date}(n)
raw_vec[1] = d
i::Int = 2
d = advancebdays(hc,d,1)
i = 2
while d <= d1
raw_vec[i] = d
i += 1
Expand Down

0 comments on commit 7581db2

Please sign in to comment.