3 * Table Definition for core company
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Core_holiday extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'core_holiday'; // table name
18 /* the code above is auto generated do not remove the tag below */
23 'hk' => 'http://www.1823.gov.hk/common/ical/gc/en.ics'
27 function updateHolidays($country)
30 if (!isset(self::$map[$country])) {
31 die("invalid country");
34 // do we alredy have the data for this year.
35 $d = DB_DataObject::Factory('core_holiday');
36 $d->country = $country;
37 $d->orderBy('holiday_date DESC');
39 if ($d->count() && $d->find(true) && strtotime($d->holiday_date) > strtotime('NOW + 6 MONTHS')) {
46 $data = file_get_contents("https://www.1823.gov.hk/common/ical/gc/en.ics", false,
47 stream_context_create(array(
50 "verify_peer_name"=>false,
55 $vevents = explode('BEGIN:VEVENT', $data);
57 foreach ($vevents as $vevent){
59 $lines = explode("\n", $vevent);
64 foreach ($lines as $line){
66 if(preg_match('/^DTSTART;VALUE=DATE:([0-9]+)/', $line, $matches)){
67 $fmt = substr($matches[1], 0, 4) . "-" . substr($matches[1], 4, 2) . "-" . substr($matches[1], 6, 2);
68 $start_dt = date('Y-m-d', strtotime($fmt));
71 if(preg_match('/^DTEND;VALUE=DATE:([0-9]+)/', $line, $matches)){
72 $fmt = substr($matches[1], 0, 4) . "-" . substr($matches[1], 4, 2) . "-" . substr($matches[1], 6, 2);
73 $end_dt = date('Y-m-d', strtotime($fmt));
78 if(empty($start_dt) || empty($end_dt)){
82 //var_dump($start_dt); var_dump($end_dt); exit;
84 for ($i = strtotime($start_dt); $i < strtotime($end_dt) ; $i += (60 * 60 * 24)) {
86 $d = DB_DataObject::Factory('core_holiday');
87 $d->country = $country;
88 $d->holiday_date = date('Y-m-d', $i);
99 function isHoliday($country, $date)
101 $d = DB_DataObject::Factory('core_holiday');
102 $d->country = $country;
103 $d->holiday_date = $date;