12 Holiday detector

 

No matter the time of year, it seems that a holiday looms on the horizon. It could be a religious holiday, a national day, or some other festive event. Many people may get the day off from work to celebrate. For programmers, the holiday is also a celebration but not from work: coders still code, but it’s a more enjoyable experience because everyone else is on vacation, which means fewer interruptions.

Your computer doesn’t care whether one day is a holiday. It’s not being ignorant; it just doesn’t know. To help the computer understand which day is a holiday, and to help you complete other programming projects that rely upon knowing which days are holidays, you must:

  • Understand how the operating system uses return values
  • Work with date programming in C
  • Review major holidays
  • Calculate regular holidays
  • Deal with irregular holidays
  • Figure out when Easter occurs
  • Put your holiday function to the test

These tasks help build routines that detect and report on holidays given a specific day of the year. Such a utility isn’t specifically useful by itself, but it does come into play when programming dates or performing other tasks where knowing when a holiday occurs is important. For example, I wrote a stock tracker where it was useful to know which days not to fetch the stock data because the markets are closed. And my trash pickup reminder shell script uses my holiday program to see whether trash day has shifted.

12.1 The operating system wants its vig

12.1.1 Understanding exit status versus the termination status

12.1.2 Setting a return value

12.1.3 Interpreting the return value

12.1.4 Using the preset return values

12.2 All about today

12.2.1 Getting today’s date

12.2.2 Obtaining any old date

12.3 Happy holidays

12.3.1 Reviewing holidays in the United States

12.3.2 Discovering holidays in the UK

12.4 Is today a holiday?