Giter Site home page Giter Site logo

is-holiday's Introduction

is-holiday

A very simple way to determine if a certain date is holiday or not.

Supported regions

  • China
  • Honkong

Use it in multiple programming languages

You can easily start using it in multiple programming languages, here are some examples:

Bash

#!/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

JS

// 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');
      }
  },
});

Python

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')

PHP

$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';
}

Generate a new holiday list

$ 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.

Q&A

Searching in a txt file looks unfancy and inefficient.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.