-
-
Save renlight10/590eb1d14d252a88de9978bbe350f0f5 to your computer and use it in GitHub Desktop.
[PHP] pengecekan tanggal merah berdasarkan hari libur nasional dan hari minggu
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 characters
| <?php | |
| /** | |
| * PHP Indonesia holiday check | |
| * | |
| * PHP version 5 | |
| * | |
| * @category Tools | |
| * @package Indonesia_Holiday | |
| * @author ren <ren_ice@live.com> | |
| * @copyright 2010-2017 notepy | |
| * @license MIT http://opensource.org/licenses/MIT | |
| * @link https://notepy.gitlab.io | |
| */ | |
| //default time zone | |
| date_default_timezone_set("Asia/Jakarta"); | |
| /** | |
| * Function check Indonesia holiday | |
| * | |
| * @param string $value type date Ymd | |
| * | |
| * @return json | |
| **/ | |
| function tanggalMerah($value) | |
| { | |
| $array=json_decode(file_get_contents("https://raw.githubusercontent.com/guangrei/Json-Indonesia-holidays/master/libur_nasional_apple.json"), true); | |
| //check tanggal merah berdasarkan libur nasional | |
| if(isset($array[$value])) : $res = ["is_holiday"=>true,"event"=>$array[$value]]; | |
| //check tanggal merah berdasarkan hari minggu | |
| elseif(date("D", strtotime($value))==="Sun" | |
| ) : $res = ["is_holiday"=>true,"event"=>"Sunday"]; | |
| //bukan tanggal merah | |
| else | |
| : $res = ["is_holiday"=>false,"event"=>null]; | |
| endif; | |
| return json_encode($res); | |
| } | |
| //testing | |
| $static_date=20161225; | |
| $dynamic_date=date("Ymd"); | |
| var_dump(tanggalMerah($static_date), tanggalMerah($dynamic_date)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment