-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52370c1
commit bb52a1b
Showing
5 changed files
with
116 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,114 @@ | ||
|
||
use chrono::Datelike; | ||
use chrono::{Datelike, Weekday}; | ||
use HolidayCalendar; | ||
use easter; | ||
|
||
/// Brazilian banking holidays. | ||
/// This calendar is defined by brazilian federal holidays plus Carnival. | ||
pub struct BRSettlement; | ||
|
||
fn is_brazilian_national_holiday<T: Datelike + Copy + PartialOrd>(date: T) -> bool { | ||
|
||
let (yy, mm, dd) = (date.year(), date.month(), date.day()); | ||
|
||
// Bisection | ||
if mm >= 8 { | ||
// Fixed holidays | ||
if // Independencia do Brasil | ||
((mm == 9) && (dd == 7)) | ||
|| | ||
// Nossa Senhora Aparecida | ||
((mm == 10) && (dd == 12)) | ||
|| | ||
// Finados | ||
((mm == 11) && (dd == 2)) | ||
|| | ||
// Proclamacao da Republica | ||
((mm == 11) && (dd == 15)) | ||
|| | ||
// Natal | ||
((mm == 12) && (dd == 25)) | ||
|
||
{ | ||
return true | ||
} | ||
} else { | ||
// mm < 8 | ||
// Fixed holidays | ||
if | ||
// Confraternizacao Universal | ||
((mm == 1) && (dd == 1)) | ||
|| | ||
// Tiradentes | ||
((mm == 4) && (dd == 21)) | ||
|| | ||
// Dia do Trabalho | ||
((mm == 5) && (dd == 1)) | ||
{ | ||
return true | ||
} | ||
|
||
// Easter occurs up to April, so Corpus Christi will be up to July in the worst case, which is before August (mm < 8). | ||
// Holidays based on easter date. | ||
let dt_rata = date.num_days_from_ce(); | ||
let e_rata = easter::easter_num_days_from_ce(yy).unwrap(); | ||
|
||
if | ||
// Segunda de Carnaval | ||
( dt_rata == ( e_rata - 48 ) ) | ||
|| | ||
// Terca de Carnaval | ||
( dt_rata == ( e_rata - 47 ) ) | ||
|| | ||
// Sexta-feira Santa | ||
( dt_rata == ( e_rata - 2 ) ) | ||
|| | ||
// Corpus Christi | ||
( dt_rata == ( e_rata + 60 ) ) | ||
{ | ||
return true | ||
} | ||
} | ||
|
||
false | ||
} | ||
|
||
impl<T: Datelike + Copy + PartialOrd> HolidayCalendar<T> for BRSettlement { | ||
|
||
fn is_holiday(&self, date: T) -> bool { | ||
is_brazilian_national_holiday(date) | ||
} | ||
} | ||
|
||
/// BMF&BOVESPA Exchange holidays (http://www.bmfbovespa.com.br). | ||
pub struct BrazilExchange; | ||
|
||
impl<T: Datelike + Copy + PartialOrd> HolidayCalendar<T> for BrazilExchange { | ||
|
||
fn is_holiday(&self, date: T) -> bool { | ||
|
||
let (yy, mm, dd) = (date.year(), date.month(), date.day()); | ||
|
||
// Bisection | ||
if mm >= 8 { | ||
// Fixed holidays | ||
if // Independencia do Brasil | ||
((mm == 9) && (dd == 7)) | ||
|| | ||
// Nossa Senhora Aparecida | ||
((mm == 10) && (dd == 12)) | ||
|| | ||
// Finados | ||
((mm == 11) && (dd == 2)) | ||
|| | ||
// Proclamacao da Republica | ||
((mm == 11) && (dd == 15)) | ||
|| | ||
// Natal | ||
((mm == 12) && (dd == 25)) | ||
|
||
{ | ||
return true | ||
} | ||
} else { | ||
// mm < 8 | ||
// Fixed holidays | ||
if | ||
// Confraternizacao Universal | ||
((mm == 1) && (dd == 1)) | ||
|| | ||
// Tiradentes | ||
((mm == 4) && (dd == 21)) | ||
|| | ||
// Dia do Trabalho | ||
((mm == 5) && (dd == 1)) | ||
{ | ||
return true | ||
} | ||
|
||
// Easter occurs up to April, so Corpus Christi will be up to July in the worst case, which is before August (mm < 8). | ||
// Holidays based on easter date. | ||
let dt_rata = date.num_days_from_ce(); | ||
let e_rata = easter::easter_num_days_from_ce(yy).unwrap(); | ||
|
||
if | ||
// Segunda de Carnaval | ||
( dt_rata == ( e_rata - 48 ) ) | ||
|| | ||
// Terca de Carnaval | ||
( dt_rata == ( e_rata - 47 ) ) | ||
|| | ||
// Sexta-feira Santa | ||
( dt_rata == ( e_rata - 2 ) ) | ||
|| | ||
// Corpus Christi | ||
( dt_rata == ( e_rata + 60 ) ) | ||
{ | ||
return true | ||
} | ||
if | ||
// Aniversário de São Paulo | ||
( mm == 1 && dd == 25 ) | ||
|| | ||
// Revolucão | ||
( mm == 7 && dd == 9 ) | ||
|| | ||
// Conciência Negra (a partir de 2007) | ||
( yy >= 2007 && mm == 11 && dd == 20 ) | ||
// Christmas Eve | ||
|| | ||
( mm == 12 && dd == 24) | ||
|| | ||
// Último dia útil do ano | ||
( mm == 12 && (dd == 31 || (dd>=29 && date.weekday() == Weekday::Fri) )) | ||
{ | ||
return true; | ||
} | ||
|
||
false | ||
// national holidays | ||
is_brazilian_national_holiday(date) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters