API interface and example functions for determining whether a date is a statutory holiday

Source: Internet
Author: User

Need to determine whether a date is a statutory holiday, because the national holidays are changing every year, so the use of interface determination is necessary. Unfortunately, this is not a lot of interfaces, summarized in three:

    • http://tool.bitefu.net/jiari/
    • Http://www.easybots.cn/holiday_api.net
    • https://www.juhe.cn/docs/api/id/177

The first two appear to be personal and the last one is the perpetual calendar interface for aggregating data.

The first two were used in my small project. The feeling of personal build may not be too stable, but the aggregation of the API I see more and more restrictions, only 100 times a day to make calls.

Comes with code from a small project, using curl to get the first two interfaces and the THINKPHP5 caching mechanism to determine whether the current date is a holiday function.

PHP<textarea class="crayon-plain print-no" style="-moz-tab-size: 4; font-size: 14px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden;" readonly="" data-settings="dblclick">function Isholiday () {$today = date (' Ymd '); if (cache ($today)!== false) {return cache ($today); } else {$api 1 = juhecurl (' http://tool.bitefu.net/jiari/?d= '. $today); if (Is_numeric ($api 1)) {cache ($today, $api 1, 86400); Return cache ($today); } else {$api 2 = Json_decode (Juhecurl (' http://www.easybots.cn/api/holiday.php?d= '. $today)); if (Is_numeric ($api 2)) {cache ($today, $api 2-> $today, 86400); Return cache ($today); } else {return-1; } } }}</textarea>
12345678910111213141516171819202122 function isholiday() { $today = date(' YMD '); if (cache($today) !== false) { /c11> return cache($today); } else { $api 1 = juhecurl(' http://tool.bitefu.net/jiari/?d= '). $today); if (is_numeric($api 1)) { Cache($today, $api 1, 86400); return cache($today); } else {              $api 2 = json_decode (juhecurl ' http://www.easybots.cn/api/holiday.php?d= ' . $today ;              if (is_numeric< Span class= "Crayon-sy" > ( $api 2) ) { Cache($today, $today $api2, 86400); return cache($today); } else { return -1;             }        }    }}

The cache helper function in the code above is THINKPHP5, and Juhecurl () is a curl access function that is for reference only and cannot be transferred directly to other projects.

Since two interfaces return the result is more unified, the working day is 0, the rest day 1, the holiday 2. So no detailed judgment is taken, and no result is returned-1.

Since none of the two interfaces are too prescriptive, it is recommended that you look at the availability when using it. If you can consider a certain budget, we recommend using the aggregation interface to stabilize the point.

API interface and example functions for determining whether a date is a statutory holiday

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.