Who was president of the USA? Challenge

Write a program that takes as input a day from April 30, 1789 to August 21, 2019 and returns as output who was president of the USA that day.

Notes

For the list of US presidents, the format of their names, and the period of their presidency, see below:

April 30, 1789 - March 4, 1797          George Washington
March 4, 1797 - March 4, 1801           John Adams
March 4, 1801 - March 4, 1809           Thomas Jefferson
March 4, 1809 - March 4, 1817           James Madison
March 4, 1817 - March 4, 1825           James Monroe
March 4, 1825 - March 4, 1829           John Quincy Adams
March 4, 1829 - March 4, 1837           Andrew Jackson
March 4, 1837 - March 4, 1841           Martin Van Buren
March 4, 1841 - April 4, 1841           William Henry Harrison
April 4, 1841 - March 4, 1845           John Tyler
March 4, 1845 - March 4, 1849           James K. Polk
March 4, 1849 - July 9, 1850            Zachary Taylor
July 9, 1850 - March 4, 1853            Millard Fillmore
March 4, 1853 - March 4, 1857           Franklin Pierce
March 4, 1857 - March 4, 1861           James Buchanan
March 4, 1861 - April 15, 1865          Abraham Lincoln
April 15, 1865 - March 4, 1869          Andrew Johnson
March 4, 1869 - March 4, 1877           Ulysses S. Grant
March 4, 1877 - March 4, 1881           Rutherford B. Hayes
March 4, 1881 - September 19, 1881      James A. Garfield
September 19, 1881 - March 4, 1885      Chester A. Arthur
March 4, 1885 - March 4, 1889           Grover Cleveland
March 4, 1889 - March 4, 1893           Benjamin Harrison
March 4, 1893 - March 4, 1897           Grover Cleveland
March 4, 1897 - September 14, 1901      William McKinley
September 14, 1901 - March 4, 1909      Theodore Roosevelt
March 4, 1909 - March 4, 1913           William Howard Taft
March 4, 1913 - March 4, 1921           Woodrow Wilson
March 4, 1921 - August 2, 1923          Warren G. Harding
August 2, 1923 - March 4, 1929          Calvin Coolidge
March 4, 1929 - March 4, 1933           Herbert Hoover
March 4, 1933 - April 12, 1945          Franklin D. Roosevelt
April 12, 1945 - January 20, 1953       Harry S. Truman
January 20, 1953 - January 20, 1961     Dwight D. Eisenhower
January 20, 1961 - November 22, 1963    John F. Kennedy
November 22, 1963 - January 20, 1969    Lyndon B. Johnson
January 20, 1969 - August 9, 1974       Richard Nixon
August 9, 1974 - January 20, 1977       Gerald Ford
January 20, 1977 - January 20, 1981     Jimmy Carter
January 20, 1981 - January 20, 1989     Ronald Reagan
January 20, 1989 - January 20, 1993     George H. W. Bush
January 20, 1993 - January 20, 2001     Bill Clinton
January 20, 2001 - January 20, 2009     George W. Bush
January 20, 2009 - January 20, 2017     Barack Obama
January 20, 2017 - Incumbent            Donald Trump


A presidency is intended as first day included and last day excluded. For example, "March 4, 1861 - April 15, 1865; Abraham Lincoln" means that Lincoln was president from March 4, 1861 to April 14, 1865.

This is code-golf, the shortest program in each language wins.

Example

Input: "February 7, 1865" Output: "Abraham Lincoln"
PHP, 936 bytes



for($a=explode('-',gzinflate(base64_decode('dVTRbtswDPwV/YANKXZq+zFJ1wRts3VZtgB7Y2Mm1ipLAO0089+PtNIuHbAnAzySd+RRNkVZ6XxSJUsMdES1g66x/tgHn5iiKnSms+Q+NF7Nami7xJTajLFtE1ro1D0eDkidZJe6itnQYqfWUNsYNsV1OHgKyNHJ9G/rryfr98M7wyT2mfma8KzuYf8SG2Wx0Rqot179AK/mJ0JB8qhpZ52z0KoVehrUCoguEhjP38i2g0OS2PRK1kOqnoJ7kXAk/wn7BrjJFgYXJH2qdaHLZM0UQLW6428bSCaZZmPFHYF/cSzsySLtR+B68PmJG3oQNTdR7eyZoGG1jzx8cCMw1bnJ3wdntVH+TdT03Q1dx62+pWrJZD0jRaTYnPoG6RBY2DzlwQeUPZbmin/GRUAHi66OUGXKZNFg1yMJOKO+OcmgZdzLksIrIwuHr+jAj0VRxhz9L2h50KsFV9n/ii4n9GbNev9gvcMhMZUWDXJIGGrepNqE0EldL1j10dBwlqVv4SCgiWS7EGoKZ8VJo4hqcrkCloVeLWURVPMtC5RpPtxkAe6VhS9CcLY+ogCRaIX0jNQzkQzA8ewfU2/TD/pyccoksoFB/NjSqRVvKz4GY6rk9myPTS9Vn2yHvgnnsSs7L+h4h3epekDvsZZd3GTGTEzyOPg6ePHw3fyKzZeajZWDrNVn+3sMFzlPVPKrJXB8jmy9BIvY37btoBb8TkbWMrJugpfUDcJxlFrGxpd3v0rVLuUr7RqGqjjFnNfPZlovf4OJ1ua64C2b47HRHIifqvryDC1w1EQtfwA=')));$d=$a[+$i++];)date(Ymd,strtotime($argn))&gt;$d?$m=$a[$i++]:die($m);echo'Donald Trump';


Try it online!



Tests: 
Try it online!

The code for tests is the same logic but a little bit different to replace the die(...) with return... so I can loop over tests.



I have created a string having start date of presidency minus 1 day in format of YYYYMMDD and name of president in it, separated by -. Example: 17890429-George Washington-17970303-John Adams-18010303-Thomas Jefferson-...

This string is compressed using gzdeflate and also the compressed output is converted to base-64 so all characters are printable ASCII and I can post them here or use them in TIO.

In the script, the string is split by - and looped over. For each loop iteration:


$d is set to current iteration value (which is the president's start date -1 day) and the loop variable ($i) is increased by one.
If input date is larger than $d, then $m is set to next iteration value (which is the president name for $d) and the loop variable ($i) is increased by one again. This allows the loop to get president names but jump over them in iterations.
If input date is not larger than $d, then that means the previous iteration was the correct president, so $m is printed using die function, this will stop the whole program after printing the name.


At the end, if the loop is finished (which means no die was called), the last president's name is printed, since we know non of previous presidents have got a match (so basically anything after January 19, 2017) prints last president's name, even if it is January 1, 3999.