Skip to content

Commit

Permalink
remove const from local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
felipenoris committed Sep 3, 2017
1 parent 86f2d3a commit 270522a
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 68 deletions.
14 changes: 7 additions & 7 deletions src/bdayscache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ end

function bdays(hcc::HolidayCalendarCache, dt0::Date, dt1::Date)
# Computation is always based on next Business Days if given dates are not Business Days, inspired by Banking Account convention.
const dt0_tobday = tobday(hcc.hc, dt0) # cache bounds are checked inside tobday -> isbday
const dt1_tobday = tobday(hcc.hc, dt1) # cache bounds are checked inside tobday -> isbday
dt0_tobday = tobday(hcc.hc, dt0) # cache bounds are checked inside tobday -> isbday
dt1_tobday = tobday(hcc.hc, dt1) # cache bounds are checked inside tobday -> isbday

return Day(convert(Int, hcc.bdayscounter_array[_linenumber(hcc, dt1_tobday)]) - convert(Int, hcc.bdayscounter_array[_linenumber(hcc, dt0_tobday)]))
end
Expand All @@ -45,14 +45,14 @@ end
# tuple[1] = Array of Bool (isBday) , tuple[2] = Array of UInt32 (bdaycounter)
function _createbdayscache(hc::HolidayCalendar, d0::Date, d1::Date)

const d0_ = min(d0, d1)
const d1_ = max(d0, d1)
d0_ = min(d0, d1)
d1_ = max(d0, d1)

const d0_rata = Dates.days(d0_)
const d1_rata = Dates.days(d1_)
d0_rata = Dates.days(d0_)
d1_rata = Dates.days(d1_)

# length of the cache arrays
const len::Int = d1_rata - d0_rata + 1
len::Int = d1_rata - d0_rata + 1

# This function uses UInt32 to store bdayscounter array
# We need to check if we'll exceed typemax(UInt32)
Expand Down
22 changes: 11 additions & 11 deletions src/bdaysvecfun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function isbday(hc::HolidayCalendar, dt::Vector{Date})
end

function isbday(hc::Vector{HolidayCalendar}, dt::Vector{Date})
const l_hc = length(hc)
const l_dt = length(dt)
l_hc = length(hc)
l_dt = length(dt)

@assert l_hc == l_dt "Input vectors must have the same size. $(l_hc) != $(l_dt)"

Expand All @@ -41,8 +41,8 @@ function tobday(hc::HolidayCalendar, dt::Vector{Date}; forward::Bool = true)
end

function tobday(hc::Vector{HolidayCalendar}, dt::Vector{Date}; forward::Bool = true)
const l_hc = length(hc)
const l_dt = length(dt)
l_hc = length(hc)
l_dt = length(dt)

@assert l_hc == l_dt "Input vectors must have the same size. $(l_hc) != $(l_dt)"

Expand All @@ -59,7 +59,7 @@ tobday(calendar, dt::Vector{Date}; forward::Bool = true) = tobday(convert(Holida
tobday{A<:AbstractArray}(calendars::A, dt::Vector{Date}; forward::Bool = true) = tobday(convert(Vector{HolidayCalendar}, calendars), dt; forward=forward)

function bdays(hc::HolidayCalendar, base_date::Date, dt_vec::Vector{Date})
const len = length(dt_vec)
len = length(dt_vec)

result = Array{Day}(len)

Expand All @@ -71,8 +71,8 @@ function bdays(hc::HolidayCalendar, base_date::Date, dt_vec::Vector{Date})
end

function bdays(hc::HolidayCalendar, dt0::Vector{Date}, dt1::Vector{Date})
const l0 = length(dt0)
const l1 = length(dt1)
l0 = length(dt0)
l1 = length(dt1)

@assert l0 == l1 "Input vectors must have the same size. $(l0) != $(l1)"

Expand All @@ -86,9 +86,9 @@ function bdays(hc::HolidayCalendar, dt0::Vector{Date}, dt1::Vector{Date})
end

function bdays(hc::Vector{HolidayCalendar}, dt0::Vector{Date}, dt1::Vector{Date})
const l_hc = length(hc)
const l0 = length(dt0)
const l1 = length(dt1)
l_hc = length(hc)
l0 = length(dt0)
l1 = length(dt1)

@assert l_hc == l0 && l0 == l1 "Input vectors must have the same size. $(l_hc), $(l0), $(l1)"

Expand All @@ -104,7 +104,7 @@ end
bdays{A<:AbstractArray}(calendars::A, dt0::Vector{Date}, dt1::Vector{Date}) = bdays(convert(Vector{HolidayCalendar}, calendars), dt0, dt1)

function advancebdays(hc::HolidayCalendar, dt::Date, bdays_count_vec::Vector{Int})
const l = length(bdays_count_vec)
l = length(bdays_count_vec)
result = Array{Date}(l)
for i in 1:l
result[i] = advancebdays(hc, dt, bdays_count_vec[i])
Expand Down
16 changes: 8 additions & 8 deletions src/calendars/brazil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const BrazilBMF = BrazilExchange
# Brazilian Banking Holidays
function isholiday(::Brazil, dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

# Bisection
if mm >= 8
Expand Down Expand Up @@ -57,8 +57,8 @@ function isholiday(::Brazil, dt::Date)

# Easter occurs up to April, so Corpus Christi will be up to July in the worst case, which is before August (mm < 8). See `test/easter-min-max.jl`.
# Holidays based on easter date.
const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# Segunda de Carnaval
Expand All @@ -81,9 +81,9 @@ function isholiday(::Brazil, dt::Date)
end

function isholiday(::BrazilExchange, dt::Date)
const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

if (
# Aniversário de São Paulo
Expand Down
26 changes: 14 additions & 12 deletions src/calendars/canada.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type CanadaTSX <: HolidayCalendar end

function isholiday(::CanadaSettlement, dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
const ww = Dates.dayofweek(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)
ww = Dates.dayofweek(dt)

# Bisection
if mm >= 8
Expand Down Expand Up @@ -54,8 +54,8 @@ function isholiday(::CanadaSettlement, dt::Date)

# Easter occurs up to April, which is before August (mm < 8). See test/easter-min-max.jl .
# Holidays based on easter date
const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# Good Friday
Expand All @@ -64,15 +64,16 @@ function isholiday(::CanadaSettlement, dt::Date)
return true
end
end

return false
end

function isholiday(::CanadaTSX, dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
const ww = Dates.dayofweek(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)
ww = Dates.dayofweek(dt)

# Bisection
if mm >= 8
Expand Down Expand Up @@ -110,8 +111,8 @@ function isholiday(::CanadaTSX, dt::Date)

# Easter occurs up to April, which is before August (mm < 8). See test/easter-min-max.jl .
# Holidays based on easter date
const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# Good Friday
Expand All @@ -120,5 +121,6 @@ function isholiday(::CanadaTSX, dt::Date)
return true
end
end

return false
end
10 changes: 5 additions & 5 deletions src/calendars/target.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const TARGET2 = TARGET
const EuroZone = TARGET

function isholiday(::TARGET, dt::Date)
const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

# Bisection
if mm < 8
Expand All @@ -26,8 +26,8 @@ function isholiday(::TARGET, dt::Date)

if yy >= 2000

const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# Good Friday
Expand Down
10 changes: 5 additions & 5 deletions src/calendars/uk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const UnitedKingdom = UKSettlement
# England and Wales Banking Holidays
function isholiday(::UKSettlement, dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

# Bisection
if mm >= 8
Expand Down Expand Up @@ -50,8 +50,8 @@ function isholiday(::UKSettlement, dt::Date)

# Easter occurs up to April, which is before August (mm < 8). See test/easter-min-max.jl .
# Holidays based on easter date
const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# Good Friday
Expand Down
26 changes: 13 additions & 13 deletions src/calendars/us.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type USGovernmentBond <: HolidayCalendar end

function isholiday(::USSettlement , dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

if (
# New Year's Day
Expand Down Expand Up @@ -65,12 +65,12 @@ end

function isholiday(::USNYSE , dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# New Year's Day
Expand Down Expand Up @@ -175,12 +175,12 @@ end

function isholiday(::USGovernmentBond , dt::Date)

const yy = Dates.year(dt)
const mm = Dates.month(dt)
const dd = Dates.day(dt)
yy = Dates.year(dt)
mm = Dates.month(dt)
dd = Dates.day(dt)

const dt_rata::Int = Dates.days(dt)
const e_rata::Int = easter_rata(Dates.Year(yy))
dt_rata::Int = Dates.days(dt)
e_rata::Int = easter_rata(Dates.Year(yy))

if (
# New Year's Day
Expand Down
1 change: 1 addition & 0 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ function isholiday(hc::CompositeHolidayCalendar, dt::Date)
return true
end
end

return false
end
4 changes: 2 additions & 2 deletions src/dateutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function easter_rata(y::Year)
end

# Century
const c = div(y.value , 100) + 1
c = div(y.value , 100) + 1

# Shifted Epact
local se::Int = mod(14 + 11*(mod(y.value, 19)) - div(3*c, 4) + div(5+8*c, 25), 30)
Expand All @@ -26,7 +26,7 @@ function easter_rata(y::Year)
end

# Paschal Moon
const p = Date(y.value, 4, 19).instant.periods.value - se
p = Date(y.value, 4, 19).instant.periods.value - se

# Easter: locate the Sunday after the Paschal Moon
return p + 7 - mod(p, 7)
Expand Down
1 change: 1 addition & 0 deletions src/holidaycalendar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function symtocalendar(sym::Symbol)
else
error("$sym is not a valid HolidayCalendar.")
end

return result
end

Expand Down
11 changes: 6 additions & 5 deletions src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Returns the list of holidays between `dt0` and `dt1`.
"""
function listholidays(hc::HolidayCalendar, dt0::Date, dt1::Date)
const d0 = min(dt0, dt1)
const d1 = max(dt0, dt1)
const dt_range = d0:d1
d0 = min(dt0, dt1)
d1 = max(dt0, dt1)
dt_range = d0:d1
isholiday_vec = [ isholiday(hc, i) for i in dt_range ]
return dt_range[isholiday_vec]
end
Expand All @@ -21,14 +21,14 @@ Returns the list of business days between `dt0` and `dt1`.
"""
function listbdays(hc::HolidayCalendar, dt0::Date, dt1::Date)
d = tobday(hc,min(dt0,dt1))
const d1 = max(dt0, dt1)
d1 = max(dt0, dt1)

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

const n = Dates.value(d1) - Dates.value(d) + 1
n = Dates.value(d1) - Dates.value(d) + 1
raw_vec = Array{Date}(n)
raw_vec[1] = d
i::Int = 2
Expand All @@ -38,6 +38,7 @@ function listbdays(hc::HolidayCalendar, dt0::Date, dt1::Date)
i += 1
d = advancebdays(hc,d,1)
end

return raw_vec[1:(i-1)]
end

Expand Down

0 comments on commit 270522a

Please sign in to comment.