Last active
August 13, 2022 00:53
-
-
Save buagern/96f7c1fe7847e0122fa2c215426ed058 to your computer and use it in GitHub Desktop.
Revisions
-
buagern revised this gist
Apr 7, 2017 . 1 changed file with 6 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,29 @@ <?php function dateth() { if (0 === $given = func_num_args()) { return trigger_error(__FUNCTION__.'() expects at least 1 parameter, '.$given.' given', E_USER_WARNING); } $mapping = [ 'D' => [ 'Mon' => 'จ.', 'Tue' => 'อ.', 'Wed' => 'พ.', 'Thu' => 'พฤ.', 'Fri' => 'ศ.', 'Sat' => 'ส.', 'Sun' => 'อา.' ], 'l' => [ 'Monday' => 'จันทร์', 'Tuesday' => 'อังคาร', 'Wednesday' => 'พุธ', 'Thursday' => 'พฤหัสบดี', 'Friday' => 'ศุกร์', 'Saturday' => 'เสาร์', 'Sunday' => 'อาทิตย์' ], 'M' => [ 'Jan' => 'ม.ค.', 'Feb' => 'ก.พ.', 'Mar' => 'มี.ค.', 'Apr' => 'เม.ย.', 'May' => 'พ.ค.', 'Jun' => 'มิ.ย.', 'Jul' => 'ก.ค.', 'Aug' => 'ส.ค.', 'Sep' => 'ก.ย.', 'Oct' => 'ต.ค.', 'Nov' => 'พ.ย.', 'Dec' => 'ธ.ค.' ], 'F' => [ 'January' => 'มกราคม', 'February' => 'กุมภาพันธ์', 'March' => 'มีนาคม', 'April' => 'เมษายน', 'May' => 'พฤษภาคม', 'June' => 'มิถุนายน', 'July' => 'กรกฎาคม', 'August' => 'สิงหาคม', 'September' => 'กันยายน', 'October' => 'ตุลาคม', 'November' => 'พฤศจิกายน', 'December' => 'ธันวาคม' ]]; $args = func_get_args(); $ts = ($args[1]) ?? time(); // var_dump(implode('', array_keys($mapping))); $mapregex = '/['.(implode('', array_keys($mapping))).']/'; $args[0] = preg_replace_callback_array([ '/[yYo]/' => function ($match) use($args, $ts) { $year = (int) date('Y', $ts); $year = $year + 543; if ($match[0] == 'y') { $year = substr($year, -2); } return $year; }, $mapregex => function ($match) use($args, $ts, $mapping) { return $mapping[$match[0]][date($match[0], $ts)]; } ], $args[0]); return call_user_func_array('date', $args); } -
buagern revised this gist
Mar 19, 2017 . No changes.There are no files selected for viewing
-
buagern created this gist
Mar 19, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ <?php function dateth() { if (0 === $given = func_num_args()) { return trigger_error(__FUNCTION__.'() expects at least 1 parameter, '.$given.' given', E_USER_WARNING); } $mapping = [ 'D' => [ 'Mon' => 'จ.', 'Tue' => 'อ.', 'Wed' => 'พ.', 'Thu' => 'พฤ.', 'Fri' => 'ศ.', 'Sat' => 'ส.', 'Sun' => 'อา.' ], 'l' => [ 'Monday' => 'จันทร์', 'Tuesday' => 'อังคาร', 'Wednesday' => 'พุธ', 'Thursday' => 'พฤหัสบดี', 'Friday' => 'ศุกร์', 'Saturday' => 'เสาร์', 'Sunday' => 'อาทิตย์' ], 'M' => [ 'Jan' => 'ม.ค.', 'Feb' => 'ก.พ.', 'Mar' => 'มี.ค.', 'Apr' => 'เม.ย.', 'May' => 'พ.ค.', 'Jun' => 'มิ.ย.', 'Jul' => 'ก.ค.', 'Aug' => 'ส.ค.', 'Sep' => 'ก.ย.', 'Oct' => 'ต.ค.', 'Nov' => 'พ.ย.', 'Dec' => 'ธ.ค.' ], 'F' => [ 'January' => 'มกราคม', 'February' => 'กุมภาพันธ์', 'March' => 'มีนาคม', 'April' => 'เมษายน', 'May' => 'พฤษภาคม', 'June' => 'มิถุนายน', 'July' => 'กรกฎาคม', 'August' => 'สิงหาคม', 'September' => 'กันยายน', 'October' => 'ตุลาคม', 'November' => 'พฤศจิกายน', 'December' => 'ธันวาคม' ]]; $args = func_get_args(); $ts = ($args[1]) ?? time(); $args[0] = preg_replace_callback_array([ '/[yYo]/' => function ($match) use($args, $ts) { $year = (int) date('Y', $ts); $year = $year + 543; if ($match[0] == 'y') { $year = substr($year, -2); } return $year; }, '/['.implode('', array_keys($mapping)).']/' => function ($match) use($args, $ts, $mapping) { return $mapping[$match[0]][date($match[0], $ts)]; } ], $args[0]); var_dump($args); return call_user_func_array('date', $args); }