A very simple way to determine if a certain date is holiday or not.
- China
- Honkong
You can easily start using it in multiple programming languages, here are some examples:
#!/bin/bash
if curl -s https://raw.githubusercontent.com/HouCoder/is-holiday/master/dist/cn/2020.txt | grep -q `date '+%Y%m%d'`
then
echo "Enjoy your day off"
else
echo "Go back to work"
fi
// jQuery and Moment required.
$.ajax({
type: 'GET',
url: 'https://raw.githubusercontent.com/HouCoder/is-holiday/master/dist/cn/2020.txt',
dataType: "text",
crossDomain: true,
success: function (data) {
console.log(data);
const today = moment(new Date()).format('YYYYMMDD');
if (data.includes(today)) {
console.log('Enjoy your day off');
} else {
console.log('Go back to work');
}
},
});
import urllib.request
from datetime import datetime
today = datetime.today().strftime('%Y%m%d')
contents = urllib.request.urlopen("https://raw.githubusercontent.com/HouCoder/is-holiday/master/dist/cn/2020.txt").read()
if today.encode() in contents:
print('Enjoy your day off')
else:
print('Go back to work')
$today = date('Ymd');
$data = file_get_contents('https://raw.githubusercontent.com/HouCoder/is-holiday/master/dist/cn/2020.txt');
if (strpos($data, $today) !== false) {
echo 'Enjoy your day off';
} else {
echo 'Go back to work';
}
$ node generate.js --region cn --year 2020
This command will read holiday settings stored in source/cn/2020.js. The holiday settings JS file is a simple node module that consists of 2 properties: holidays
and workWeekends
. Here's how it looks like - example.
That's the point, I want to make it simple, stupid and reliable to use, that's why I prefer to host it directly on GitHub rather than making it into a real API service and host it on my server, my own server's stability is nowhere near GitHub's, plus even if you think GitHub isn't stable enough you can just download the txt file and store it in your local.