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',
24 'cny' => 'https://raw.githubusercontent.com/andrewlkho/cny.ics/master/cny.ics', // CNY
28 function updateHolidays($country)
31 if (!isset(self::$map[$country])) {
32 die("invalid country");
35 // do we alredy have the data for this year.
36 $d = DB_DataObject::Factory('core_holiday');
37 $d->country = $country;
38 $d->orderBy('holiday_date DESC');
40 if ($d->count() && $d->find(true) && strtotime($d->holiday_date) > strtotime('NOW + 6 MONTHS')) {
47 $data = file_get_contents("https://www.1823.gov.hk/common/ical/gc/en.ics", false,
48 stream_context_create(array(
51 "verify_peer_name"=>false,
56 $vevents = explode('BEGIN:VEVENT', $data);
58 foreach ($vevents as $vevent){
60 $lines = explode("\n", $vevent);
65 foreach ($lines as $line){
67 if(preg_match('/^DTSTART;VALUE=DATE:([0-9]+)/', $line, $matches)){
68 $fmt = substr($matches[1], 0, 4) . "-" . substr($matches[1], 4, 2) . "-" . substr($matches[1], 6, 2);
69 $start_dt = date('Y-m-d', strtotime($fmt));
72 if(preg_match('/^DTEND;VALUE=DATE:([0-9]+)/', $line, $matches)){
73 $fmt = substr($matches[1], 0, 4) . "-" . substr($matches[1], 4, 2) . "-" . substr($matches[1], 6, 2);
74 $end_dt = date('Y-m-d', strtotime($fmt));
79 if(empty($start_dt) || empty($end_dt)){
83 //var_dump($start_dt); var_dump($end_dt); exit;
85 for ($i = strtotime($start_dt); $i < strtotime($end_dt) ; $i += (60 * 60 * 24)) {
87 $d = DB_DataObject::Factory('core_holiday');
88 $d->country = $country;
89 $d->holiday_date = date('Y-m-d', $i);
100 function isHoliday($country, $date)
102 $d = DB_DataObject::Factory('core_holiday');
103 $d->country = $country;
104 $d->holiday_date = $date;