Calendar with Federal Holidays

This Hyper-text Markup Language (HTML) file captures study-notes for HTML, JavaScript, Base64 encoding, and Calendrical Computation. The primary subject is listed last -- Calendars.

When this page loads, the browser asks for a year to plot. Reload the page to pick a different year. The calendar is rendered in the browser using a courier font that can be copied and pasted into a word processor for additional hand-editing and easy manipulation.

In the browser, Federal Holidays are rendered in red and as abbreviations <abbr> so that the full name appears when one hovers the mouse-cursor above the number on the calendar. Federal Holidays are also listed as text below the calendar for easy reference and copying.

 


See OPM Federal Holidays for holidays.


NOTES

Have a look at the source code for this HTML file. It is divided into several sections separated by <!-- comments ---- -->

Search for -- --> to search the many lines of text.


This document has been purposefully forced into a single monolithic, self-contained HTML file. Viewing the source code gives one access to study-notes. Computing calendars can be a bit tricky. Writing JavaScript can be a bit tricky. Embedding images directly into an HTML file (avoiding external references) can be a bit tricky. Typesetting equations in HTML can be a bit tricky.

Working through Information Technology (IT) policy can add complexity and has definitely retarded the development presented here. Specifically, I cannot e-mail HTML files between my computers for to do so might unintentionally execute code. If you have received these notes in the form of a text file (*.txt), then you must first edit and rename the file. The edit consists of adding the text <HTML> as the very first in the file and the text </HTML> as the very last. The filename must also be changed to have a *.htm or *.html suffix. The resulting HTML file can be openned directly in a web-browser.

Calendrical Calculations

This page is focused on the Gregorian Calendar, which defines a year to be leap if it is divisble by 4 and is not a century year (multiple of 100) or if it is divisble by 400. In leap years, February has 29 days. We also index the days of the week: Sunday is zero, Monday is one, Tuesday is two, ... Saturday is 6.

Dershowitz, Nachum & Reingold, Edward M., Calendrical Calculations, © 1997 Cambridge University Press, ISBN: 0-521-56474-3. Is an excellent reference.

Their body of work is captured in common LISP and embedded in the GNU EMACS editor, which is how I learned of it in the first place.

Dershowitz and Reingold define a fixed day (Rata Die) to be fixed at Midnight at the onset of Monday, January 1 in the Year 1. In their book and code, they provide a concise mathematical and algorithmic mapping of various calendars to and from a timeline starting from this point. Computations for Gregorean Calendars are repeated here for refernece.


⌊ ⌋ is the floor function


gregorian-leap-year? (g-year) =
(g-year mod 4) = 0 &
(g-year mod 100) ∉ {100, 200, 300}

fixed-from-gregorian (year, month, day) = 365(year - 1) +
| year - 1 |
⌊      4    
-
| year - 1 |
⌊    100  
+
| year - 1 |
⌊    400  
+
| (367)month -362 |
⌊           12  
+ day - [offset]

where:

offset = 0 if month ≤ 2;
offset = 1 if month > 2 & gregorian-leap-year?(year);
offset = 2 {otherwise}


gregorian-year-from-fixed (date) = year
{ if n100=4 or n1=4 }
gregorian-year-from-fixed (date) = year + 1
{     otherwise          }

where:

d0
=
date -1
n400
=
|     d0    |
⌊146097
d1
=
d0 mod
146097
n100
=
|     d1    |
⌊ 36524
d2
=
d1 mod
36524
n4
=
|     d2    |
⌊   1461
d3
=
d2 mod
1461
n1
=
|     d3    |
⌊    365
d4
=
(d3 mod
365) + 1

year = (400)(n400) + (100)(n100) + (4)(n4) + n1


gregorian-from-fixed (date) = year, month, day

where:

year = gregorian-year-from-fixed (date)

prior-days = date - fixed-from-gregorian (January 1, year)

offset = 0 if date fixed-from-gregorian (March 1, year)
offset = 1 if date ≥ fixed-from-gregorian (March 1, year)
offset = 2 {otherwise}

month
=
|(12)(prior-days + offset) + 373|
⌊                     367

day = date - fixed-from-gregorian (month 1, year)


Base64 table from RFC 4648 and Emeding Images in HTML

Binary data can be encoded with 4 printable characters for every three bytes.
The result is called base 64 encoding (26-bits = 64). The following table lists the characters.

IndexBinaryCharIndexBinaryCharIndexBinaryCharIndexBinaryChar
0 000000   A 16010000   Q32100000   g48110000   w
1 000001   B 17010001   R33100001   h49110001   x
2 000010   C 18010010   S34100010   i50110010   y
3 000011   D 19010011   T35100011   j51110011   z
4 000100   E 20010100   U36100100   k52110100   0
5 000101   F 21010101   V37100101   l53110101   1
6 000110   G 22010110   W38100110   m54110110   2
7 000111   H 23010111   X39100111   n55110111   3
8 001000   I 24011000   Y40101000   o56111000   4
9 001001   J 25011001   Z41101001   p57111001   5
10 001010   K 26011010   a42101010   q58111010   6
11 001011   L 27011011   b43101011   r59111011   7
12 001100   M 28011100   c44101100   s60111100   8
13 001101   N 29011101   d45101101   t61111101   9
14 001110   O 30011110   e46101110   u62111110   +
15 001111   P 31011111   f47101111   v63111111   /
Padding   =

on Windows one can use the certutil command to encode an image file as base64 text.

certutil -encode infile   outfile

certutil -encode filename.jpg   filename.txt

<img style="max-width:70%;" src="data:image/jpeg; base64,{snip from filename.txt} />
or
<img style="max-width:70%;" src="./filename.jpg" />

Style can contain many other options and settings. Src is a Universal Resource Locator (URL) and can point to embeded content or an external file (on the web or local/server).

Time Ruler

Dershowitz and Reingold introduce the ISO calendar, which is easily looked-up on the web. The basic idea is to label the weeks of a year W01 to W52 (or W53 in some cases). This lends itself nicely to labeling pairs of weeks (what Defense Finance Accounting Service--DFAS--calls a pay period). A small innovation on my part has been flip the list of weeks onto its side; start counting each week on Sunday (vs. the ISO calendar starting on Monday) and labeling the end of each pay period and each quarter of a year (fiscal or calendar) as shown in the following figure. Last calendar quarter of a year with 53 weeks has 14 weeks; all other quarters have 13 weeks (13 weeks * 7 days/week = 91 days).

Doomsdays

The following dates always fall on the same day of the week each year: March 14, April 4, June 6, August 8, October 10, and December 12. "I work from 9 to 5 at the 7-11"-> May 9, July 11, September 5, and November 7. Knowing this fact helps in figuring the day of the week without needing a computer.

Schuler