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.
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.
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)
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.
Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | Index | Binary | Char |
0 | 000000 | A | 16 | 010000 | Q | 32 | 100000 | g | 48 | 110000 | w |
1 | 000001 | B | 17 | 010001 | R | 33 | 100001 | h | 49 | 110001 | x |
2 | 000010 | C | 18 | 010010 | S | 34 | 100010 | i | 50 | 110010 | y |
3 | 000011 | D | 19 | 010011 | T | 35 | 100011 | j | 51 | 110011 | z |
4 | 000100 | E | 20 | 010100 | U | 36 | 100100 | k | 52 | 110100 | 0 |
5 | 000101 | F | 21 | 010101 | V | 37 | 100101 | l | 53 | 110101 | 1 |
6 | 000110 | G | 22 | 010110 | W | 38 | 100110 | m | 54 | 110110 | 2 |
7 | 000111 | H | 23 | 010111 | X | 39 | 100111 | n | 55 | 110111 | 3 |
8 | 001000 | I | 24 | 011000 | Y | 40 | 101000 | o | 56 | 111000 | 4 |
9 | 001001 | J | 25 | 011001 | Z | 41 | 101001 | p | 57 | 111001 | 5 |
10 | 001010 | K | 26 | 011010 | a | 42 | 101010 | q | 58 | 111010 | 6 |
11 | 001011 | L | 27 | 011011 | b | 43 | 101011 | r | 59 | 111011 | 7 |
12 | 001100 | M | 28 | 011100 | c | 44 | 101100 | s | 60 | 111100 | 8 |
13 | 001101 | N | 29 | 011101 | d | 45 | 101101 | t | 61 | 111101 | 9 |
14 | 001110 | O | 30 | 011110 | e | 46 | 101110 | u | 62 | 111110 | + |
15 | 001111 | P | 31 | 011111 | f | 47 | 101111 | v | 63 | 111111 | / |
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).
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).
Schuler