Googleカレンダーから祝日を取得して配列に展開するコンポーネントを作ってみた。

ここを参照して作ってみました。
国については適宜追加してください。
[PHP]
class HolidayComponent extends Object {
/**
* 指定年の祝日リストを配列で取得します。
*/
function getHoliday($year = null, $country = ‘ja’){
$ret = array();;
if(empty($year)){
$dateBegin = date( “Y-m-01” );
$dateEnd = date( “Y-m-t” );
}else{
$dateBegin = date( “Y-01-01”, mktime( 0, 0, 0, 1, 1, $year ) );
$dateEnd = date( “Y-12-t”, mktime( 0, 0, 0, 12, 1, $year ) );
}
$query = “start-min=” . $dateBegin . “&start-max=” . $dateEnd . “&max-results=100”;
switch($country){
case ‘ja’:
$feed = “http://www.google.com/calendar/feeds/japanese__ja@holiday.calendar.google.com/public/full” . “?” . $query;
break;
case ‘us’:
$feed = “http://www.google.com/calendar/feeds/usa__ja@holiday.calendar.google.com/public/full” . “?” . $query;
break;
case ‘uk’:
$feed = “http://www.google.com/calendar/feeds/uk__ja@holiday.calendar.google.com/public/full” . “?” . $query;
break;
case ‘ch’:
$feed = “http://www.google.com/calendar/feeds/china__ja@holiday.calendar.google.com/public/full” . “?” . $query;
break;
case ‘ph’:
$feed = “http://www.google.com/calendar/feeds/philippines__ja@holiday.calendar.google.com/public/full” . “?” . $query;
break;
default :
$feed = “http://www.google.com/calendar/feeds/japanese__ja@holiday.calendar.google.com/public/full” . “?” . $query;
break;
}

$xml = simplexml_load_file( $feed );
if(!$xml){
return $ret;
}
$ii = 0;
foreach( $xml->entry as $entry ){
$gd = $entry->children( “http://schemas.google.com/g/2005” );
$attributes = $gd->when->attributes();
foreach( $attributes as $name => $value ){
if( $name == “startTime” ){
$ret[$ii][‘date’] = “”.$value.””;
$ret[$ii][‘title’] = “”.$entry->title.””;
$ii++;
break;
}
}
}
usort($ret, array($this, “_cmp”));
return $ret;
}
/**
* 指定年の祝日リスト配列のソート
*/
function _cmp($a, $b) {
if ($a[‘date’] == $b[‘date’]) {
return 0;
}
return ($a[‘date’] < $b['date']) ? -1 : 1; } } [/PHP]