Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.log('Starting clock.js.');
  2. ;(function()
  3.     {
  4.     console.log('Reached 1');
  5.     var MILLISECONDS_DELAY_BETWEEN_UPDATES = 1000;
  6.     var MAXIMUM_LOG_MESSAGES = 100;
  7.     var current_messages_logged = 0;
  8.     var on_athos_time = false;
  9.     var days_into_future = 1;
  10.     var sunrises_and_sunsets = {};
  11.     var place = null;
  12.     var DISTINCT_PLACE_THRESHOLD = .1;
  13.     var log = function(message)
  14.         {
  15.         if (current_messages_logged >= MAXIMUM_LOG_MESSAGES)
  16.             {
  17.             console.log(message);
  18.             }
  19.         current_messages_logged += 1;
  20.         }
  21.     var get_stored_data = function()
  22.         {
  23.         log('Reached 1.1');
  24.         if (typeof Storage !== 'undefined')
  25.             {
  26.             log('Reached 1.2');
  27.             if (typeof localStorage['place'] !== 'undefined')
  28.                 {
  29.                 log('Reached 1.3');
  30.                 place = JSON.parse(localStorage['place']);
  31.                 }
  32.             if (typeof localStorage['sunrises_and_sunsets'] !== 'undefined')
  33.                 {
  34.                 log('Reached 1.4');
  35.                 sunrises_and_sunsets = JSON.parse(localStorage[
  36.                   'sunrises_and_sunsets']);
  37.                 }
  38.             }
  39.         };
  40.     get_stored_data();
  41.     log('Reached 2');
  42.     var save_data = function()
  43.         {
  44.         log('Reached 2.1');
  45.         if (typeof Storage !== 'undefined')
  46.             {
  47.             log('Reached 2.2');
  48.             if (place)
  49.                 {
  50.                 log('Reached 2.3');
  51.                 localStorage['place'] = JSON.stringify(place);
  52.                 }
  53.             if (sunrises_and_sunsets)
  54.                 {
  55.                 log('Reached 2.4');
  56.                 localStorage['sunrises_and_sunsets'] = JSON.stringify(
  57.                   sunrises_and_sunsets);
  58.                 }
  59.             }
  60.         }
  61.     log('Reached 3');
  62.     var prune_places = function()
  63.         {
  64.         log('Reached 3.1');
  65.         var changed = false;
  66.         for(var entry in sunrises_and_sunsets)
  67.             {
  68.             log('Reached 3.2');
  69.             if (sunrises_and_sunsets.hasOwnProperty(entry))
  70.                 {
  71.                 log('Reached 3.3');
  72.                 if (typeof sunrises_and_sunsets[entry] !== 'undefined' &&
  73.                   Math.abs(sunrises_and_sunsets[entry]['latitude'] -
  74.                   place['latitude']) >= DISTINCT_PLACE_THRESHOLD ||
  75.                   Math.abs(sunrises_and_sunsets[entry]['longitude'] -
  76.                   place['longitude']) >= DISTINCT_PLACE_THRESHOLD)
  77.                     {
  78.                     log('Reached 3.4');
  79.                     changed = true;
  80.                     delete sunrises_and_sunsets[entry];
  81.                     }
  82.                 }
  83.             }
  84.         if (changed)
  85.             {
  86.             log('Reached 3.5');
  87.             save_data();
  88.             }
  89.         }
  90.     log('Reached 4');
  91.     var get_place = function()
  92.         {
  93.         log('Reached 4.1');
  94.         if (on_athos_time)
  95.             {
  96.             log('Reached 4.2');
  97.             jQuery.ajax('http://ip-api.com/json',
  98.                 {
  99.                 'success': function(data, textStatus, jqXHR)
  100.                     {
  101.                     console.log('Reached 4.2.1');
  102.                     var received = JSON.parse(jqXHR.responseText);
  103.                     place = {
  104.                       'latitude': received['lat'],
  105.                       'longitude': received['lon']
  106.                       };
  107.                     }
  108.                 });
  109.             }
  110.         else
  111.             {
  112.             log('Reached 4.3');
  113.             place = {
  114.               'latitude': 40.169332656,
  115.               'longitude': 24.376331828
  116.               };
  117.             }
  118.         };
  119.     get_place();
  120.     log('Reached 5');
  121.     var format_date = function(days_ahead = 0)
  122.         {
  123.         log('Reached 5.1');
  124.         var now_date = new Date();
  125.         var time = now_date.getTime();
  126.         time += days_ahead * 24 * 60 * 60 * 1000;
  127.         var adjusted_date = new Date();
  128.         adjusted_date.setTime(time);
  129.         return adjusted_date.toISOString().substr(0, 10);
  130.         };
  131.     log('Reached 6');
  132.     var get_time = function(ISOString)
  133.         {
  134.         log('Reached 6.1');
  135.         return new Date(ISOString).getTime();
  136.         }
  137.     log('Reached 7');
  138.     var populate_days = function(days_ahead = 1)
  139.         {
  140.         log('Reached 7.1');
  141.         if (place)
  142.             {
  143.             log('Reached 7.2');
  144.             for(var delta = -1; delta <= days_ahead; delta += 1)
  145.                 {
  146.                 log('Reached 7.3');
  147.                 if (typeof sunrises_and_sunsets[format_date(delta)] ===
  148.                   'undefined')
  149.                     {
  150.                     log('Reached 7.4');
  151.                     jQuery.ajax(
  152.                       'http://api.sunrise-sunset.org/?lat=' +
  153.                       place['latitude'] + '&lng=' + place['longitude'] +
  154.                       '&date=' + format_date(delta) + '&formatted=0',
  155.                         {
  156.                         'success': function(data, textStatus, jqXHR)
  157.                             {
  158.                             log('Reached 7.5');
  159.                             var received = JSON.parse(jqXHR.responseText);
  160.                             sunrises_and_sunsets[format_date(delta)] = {};
  161.                             sunrises_and_sunsets[format_date(delta)][
  162.                               'latitude'] = place['latitude'];
  163.                             sunrises_and_sunsets[format_date(delta)][
  164.                               'longitude'] = place['longitude'];
  165.                             sunrises_and_sunsets[format_date(delta)][
  166.                               'sunrise'] = received['sunrise'];
  167.                             sunrises_and_sunsets[format_date(delta)][
  168.                               'sunset'] = received['sunset'];
  169.                             save_sunrises_and_sunsets();
  170.                             }
  171.                         });
  172.                     }
  173.                 }
  174.             }
  175.         };
  176.     log('Reached 8');
  177.     setInterval(function()
  178.         {
  179.         log('Reached 8.1');
  180.         populate_days(days_in_future);
  181.         prune_places();
  182.         days_in_future += 1;
  183.         }, 60 * 60 * 1000);
  184.     log('Reached 9');
  185.     var adjusted_time = new Date();
  186.     var force_old_dst = 0;
  187.     var hours_to_add = 0;
  188.     var home = 'Athos';
  189.     var offset = null;
  190.     var ones_numerals = new Array();
  191.     ones_numerals[0] = "";
  192.     ones_numerals[1] = "I";
  193.     ones_numerals[2] = "II";
  194.     ones_numerals[3] = "III";
  195.     ones_numerals[4] = "IV";
  196.     ones_numerals[5] = "V";
  197.     ones_numerals[6] = "VI";
  198.     ones_numerals[7] = "VII";
  199.     ones_numerals[8] = "VIII";
  200.     ones_numerals[9] = "IX";
  201.     var tens_numerals = new Array();
  202.     tens_numerals[0] = "";
  203.     tens_numerals[1] = "X";
  204.     tens_numerals[2] = "XX";
  205.     tens_numerals[3] = "XXX";
  206.     tens_numerals[4] = "XL";
  207.     tens_numerals[5] = "L";
  208.     tens_numerals[6] = "LX";
  209.     tens_numerals[7] = "LXX";
  210.     tens_numerals[8] = "LXXX";
  211.     tens_numerals[9] = "XC";
  212.     var hundreds_numerals = new Array();
  213.     hundreds_numerals[0] = "";
  214.     hundreds_numerals[1] = "C";
  215.     hundreds_numerals[2] = "CC";
  216.     hundreds_numerals[3] = "CCC";
  217.     hundreds_numerals[4] = "CD";
  218.     hundreds_numerals[5] = "D";
  219.     hundreds_numerals[6] = "DC";
  220.     hundreds_numerals[7] = "DCC";
  221.     hundreds_numerals[8] = "DCCC";
  222.     hundreds_numerals[9] = "CM";
  223.     var thousands_numerals = new Array();
  224.     thousands_numerals[0] = "";
  225.     thousands_numerals[1] = "M";
  226.     thousands_numerals[2] = "MM";
  227.     thousands_numerals[3] = "MMM";
  228.     log('Reached 10');
  229.     var checkNumber = function(number)
  230.         {
  231.         log('Reached 10.1');
  232.         if ((parseInt(number) < 4000) && (parseInt(number) > 0))
  233.             {
  234.             log('Reached 10.2');
  235.             var numeral = createNumeral(number);
  236.             if(numeral.indexOf('undefined') === -1)
  237.                 {
  238.                 log('Reached 10.3');
  239.                 }
  240.             }
  241.         else
  242.             {
  243.             log('Reached 10.4');
  244.             alert('you must enter a valid number');
  245.             }
  246.         }
  247.     log('Reached 11');
  248.     var createNumeral = function(num)
  249.         {
  250.         log('Reached 11.1');
  251.         var new_num = num;
  252.         var thousands = Math.floor(new_num / 1000);
  253.         new_num -= thousands * 1000;
  254.         var hundreds = Math.floor(new_num / 100);
  255.         new_num -= hundreds * 100;
  256.         var tens = Math.floor(new_num / 10);
  257.         new_num -= tens * 10;
  258.         var ones = Math.floor(new_num / 1);
  259.         if((thousands === NaN)||(hundreds === NaN)||(tens === NaN)||(ones === NaN))
  260.             {
  261.             log('Reached 11.2');
  262.             alert('you must enter a valid number');
  263.             }
  264.         else
  265.             {
  266.             log('Reached 11.3');
  267.             var array = new Array(thousands,hundreds,tens,ones);
  268.             return makeNumeral(array);
  269.             }
  270.         }
  271.     log('Reached 12');
  272.     var makeNumeral = function(place_values)
  273.         {
  274.         log('Reached 12.1');
  275.         var numeral = "";
  276.         numeral += thousands_numerals[place_values[0]];
  277.         numeral += hundreds_numerals[place_values[1]];
  278.         numeral += tens_numerals[place_values[2]];
  279.         numeral += ones_numerals[place_values[3]];
  280.         return numeral;
  281.         }
  282.     log('Reached 13');
  283.     var update_liturgical_time = function()
  284.         {
  285.         log('Reached 13.1');
  286.         if (sunrises_and_sunsets[format_date(-1)] &&
  287.           sunrises_and_sunsets[format_date(0)] &&
  288.           sunrises_and_sunsets[format_date(1)])
  289.             {
  290.             log('Reached 13.2');
  291.             var sunrise_yesterday_as_double = get_time(sunrises_and_sunsets[
  292.               format_date(-1)]['sunrise']);
  293.             var sunset_yesterday_as_double = get_time(sunrises_and_sunsets[
  294.               format_date(-1)]['sunset']);
  295.             var sunrise_today_as_double = get_time(sunrises_and_sunsets[
  296.               format_date(0)]['sunrise']);
  297.             var sunset_today_as_double = get_time(sunrises_and_sunsets[
  298.               format_date(0)]['sunset']);
  299.             var sunrise_tomorrow_as_double = get_time(sunrises_and_sunsets[
  300.               format_date(1)]['sunrise']);
  301.             var sunset_tomorrow_as_double = get_time(sunrises_and_sunsets[
  302.               format_date(1)]['sunset']);
  303.             var now = new Date();
  304.             if (now.getTime() < sunrise_today_as_double)
  305.                 {
  306.                 log('Reached 13.3');
  307.                 proportion_along = (Number(now.getTime()) - sunset_yesterday_as_double) / (sunrise_today_as_double - sunset_yesterday_as_double);
  308.                 seconds_elapsed = today.getTime() + (-6 + proportion_along * 12) * 60 * 60 * 1000;
  309.                 }
  310.             else if (now.getTime() < sunset_today_as_double)
  311.                 {
  312.                 log('Reached 13.4');
  313.                 proportion_along = (Number(now.getTime()) - sunrise_today_as_double) / (sunset_today_as_double - sunrise_today_as_double);
  314.                 seconds_elapsed = today.getTime() + (6 + proportion_along * 12) * 60 * 60 * 1000;
  315.                 }
  316.             else
  317.                 {
  318.                 log('Reached 13.5');
  319.                 proportion_along = (Number(now.getTime()) - sunset_today_as_double) / (sunrise_tomorrow_as_double - sunset_today_as_double);
  320.                 seconds_elapsed = today.getTime() + (18 + 24 + proportion_along * 12) * 60 * 60 * 1000;
  321.                 }
  322.             adjusted_time.setTime(seconds_elapsed);
  323.             }
  324.         var colon = 0;
  325.         while (("" + now).substr(colon, 1) !== ":")
  326.             {
  327.             log('Reached 13.6');
  328.             ++colon;
  329.             }
  330.         var annotated_now = "";
  331.         annotated_now += ("" + now).substr(0, colon - 2);
  332.         annotated_now += "<span class='now'>";
  333.         annotated_now += ("" + now).substr(colon - 2, 5);
  334.         annotated_now += "</span>";
  335.         var date_string = "";
  336.         var week_day = "";
  337.         if (adjusted_time.getDay() === 0)
  338.             {
  339.             log('Reached 13.7');
  340.             week_day = "Sunday";
  341.             }
  342.         if (adjusted_time.getDay() === 1)
  343.             {
  344.             log('Reached 13.8');
  345.             week_day = "Monday";
  346.             }
  347.         if (adjusted_time.getDay() === 2)
  348.             {
  349.             log('Reached 13.9');
  350.             week_day = "Tuesday";
  351.             }
  352.         if (adjusted_time.getDay() === 3)
  353.             {
  354.             log('Reached 13.10');
  355.             week_day = "Wednesday";
  356.             }
  357.         if (adjusted_time.getDay() === 4)
  358.             {
  359.             log('Reached 13.11');
  360.             week_day = "Thursday";
  361.             }
  362.         if (adjusted_time.getDay() === 5)
  363.             {
  364.             log('Reached 13.12');
  365.             week_day = "Friday";
  366.             }
  367.         if (adjusted_time.getDay() === 6)
  368.             {
  369.             log('Reached 13.11');
  370.             week_day = "Saturday";
  371.             }
  372.         adjusted_time.setTime(adjusted_time.getTime() - 13 * 86400 * 1000)
  373.         var month_name = "";
  374.         if (adjusted_time.getMonth() === 0)
  375.             {
  376.             log('Reached 13.12');
  377.             month_name = "January";
  378.             }
  379.         if (adjusted_time.getMonth() === 1)
  380.             {
  381.             log('Reached 13.13');
  382.             month_name = "February";
  383.             }
  384.         if (adjusted_time.getMonth() === 2)
  385.             {
  386.             log('Reached 13.14');
  387.             month_name = "March";
  388.             }
  389.         if (adjusted_time.getMonth() === 3)
  390.             {
  391.             log('Reached 13.15');
  392.             month_name = "April";
  393.             }
  394.         if (adjusted_time.getMonth() === 4)
  395.             {
  396.             log('Reached 13.16');
  397.             month_name = "May";
  398.             }
  399.         if (adjusted_time.getMonth() === 5)
  400.             {
  401.             log('Reached 13.17');
  402.             month_name = "June";
  403.             }
  404.         if (adjusted_time.getMonth() === 6)
  405.             {
  406.             log('Reached 13.18');
  407.             month_name = "July";
  408.             }
  409.         if (adjusted_time.getMonth() === 7)
  410.             {
  411.             log('Reached 13.19');
  412.             month_name = "August";
  413.             }
  414.         if (adjusted_time.getMonth() === 8)
  415.             {
  416.             log('Reached 13.20');
  417.             month_name = "September";
  418.             }
  419.         if (adjusted_time.getMonth() === 9)
  420.             {
  421.             log('Reached 13.21');
  422.             month_name = "October";
  423.             }
  424.         if (adjusted_time.getMonth() === 10)
  425.             {
  426.             log('Reached 13.22');
  427.             month_name = "November";
  428.             }
  429.         if (adjusted_time.getMonth() === 11)
  430.             {
  431.             log('Reached 13.23');
  432.             month_name = "December";
  433.             }
  434.         var hours = -1;
  435.         var meridian;
  436.         if (adjusted_time.getHours() === 0)
  437.             {
  438.             log('Reached 13.24');
  439.             hours = 12;
  440.             meredian = "ante meridian";
  441.             }
  442.         if (adjusted_time.getHours() > 0 && adjusted_time.getHours() < 12)
  443.             {
  444.             log('Reached 13.25');
  445.             hours = adjusted_time.getHours();
  446.             meridian = "ante meridian";
  447.             }
  448.         if (adjusted_time.getHours() === 12)
  449.             {
  450.             log('Reached 13.26');
  451.             hours = 12;
  452.             meridian = "post meridian";
  453.             }
  454.         if (adjusted_time.getHours() > 12)
  455.             {
  456.             log('Reached 13.27');
  457.             hours = adjusted_time.getHours() - 12;
  458.             meridian = "post meridian";
  459.             }
  460.         var minutes;
  461.         if (adjusted_time.getMinutes() < 10)
  462.             {
  463.             log('Reached 13.28');
  464.             minutes = "0" + adjusted_time.getMinutes();
  465.             }
  466.         if (adjusted_time.getMinutes() >= 10)
  467.             {
  468.             log('Reached 13.29');
  469.             minutes = adjusted_time.getMinutes();
  470.             }
  471.         var seconds;
  472.         if (adjusted_time.getSeconds() < 10)
  473.             {
  474.             log('Reached 13.30');
  475.             seconds = "0" + adjusted_time.getSeconds();
  476.             }
  477.         if (adjusted_time.getSeconds() >= 10)
  478.             {
  479.             log('Reached 13.31');
  480.             seconds = adjusted_time.getSeconds();
  481.             }
  482.         var hour_expression;
  483.         var prayer = "";
  484.         if (adjusted_time.getHours() === 0)
  485.             {
  486.             log('Reached 13.32');
  487.             liturgical_hour = "The third hour of the second watch";
  488.             }
  489.         if (adjusted_time.getHours() === 1)
  490.             {
  491.             log('Reached 13.33');
  492.             liturgical_hour = "The fourth hour of the second watch";
  493.             }
  494.         if (adjusted_time.getHours() === 2)
  495.             {
  496.             log('Reached 13.34');
  497.             liturgical_hour = "The first hour of the third watch";
  498.             }
  499.         if (adjusted_time.getHours() === 3)
  500.             {
  501.             log('Reached 13.35');
  502.             liturgical_hour = "The second hour of the third watch";
  503.             }
  504.         if (adjusted_time.getHours() === 4)
  505.             {
  506.             log('Reached 13.36');
  507.             liturgical_hour = "The third hour of the third watch";
  508.             }
  509.         if (adjusted_time.getHours() === 5)
  510.             {
  511.             log('Reached 13.37');
  512.             liturgical_hour = "The fourth hour of the third watch";
  513.             }
  514.         if (adjusted_time.getHours() === 6)
  515.             {
  516.             log('Reached 13.38');
  517.             liturgical_hour = "The first hour";
  518.             }
  519.         if (adjusted_time.getHours() === 7)
  520.             {
  521.             log('Reached 13.39');
  522.             liturgical_hour = "The second hour";
  523.             }
  524.         if (adjusted_time.getHours() === 8)
  525.             {
  526.             log('Reached 13.40');
  527.             liturgical_hour = "The third hour";
  528.             }
  529.         if (adjusted_time.getHours() === 9)
  530.             {
  531.             log('Reached 13.41');
  532.             liturgical_hour = "The fourth hour";
  533.             }
  534.         if (adjusted_time.getHours() === 10)
  535.             {
  536.             log('Reached 13.42');
  537.             liturgical_hour = "The fifth hour";
  538.             }
  539.         if (adjusted_time.getHours() === 11)
  540.             {
  541.             log('Reached 13.43');
  542.             liturgical_hour = "The sixth hour";
  543.             }
  544.         if (adjusted_time.getHours() === 12)
  545.             {
  546.             log('Reached 13.44');
  547.             liturgical_hour = "The seventh hour";
  548.             }
  549.         if (adjusted_time.getHours() === 13)
  550.             {
  551.             log('Reached 13.45');
  552.             liturgical_hour = "The eighth hour";
  553.             }
  554.         if (adjusted_time.getHours() === 14)
  555.             {
  556.             log('Reached 13.46');
  557.             liturgical_hour = "The ninth hour";
  558.             }
  559.         if (adjusted_time.getHours() === 15)
  560.             {
  561.             log('Reached 13.47');
  562.             liturgical_hour = "The tenth hour";
  563.             }
  564.         if (adjusted_time.getHours() === 16)
  565.             {
  566.             log('Reached 13.48');
  567.             liturgical_hour = "The eleventh hour";
  568.             }
  569.         if (adjusted_time.getHours() === 17)
  570.             {
  571.             log('Reached 13.49');
  572.             liturgical_hour = "The twelfth hour";
  573.             }
  574.         if (adjusted_time.getHours() === 18)
  575.             {
  576.             log('Reached 13.50');
  577.             liturgical_hour = "The first hour of the first watch";
  578.             }
  579.         if (adjusted_time.getHours() === 19)
  580.             {
  581.             log('Reached 13.51');
  582.             liturgical_hour = "The second hour of the first watch";
  583.             }
  584.         if (adjusted_time.getHours() === 20)
  585.             {
  586.             log('Reached 13.52');
  587.             liturgical_hour = "The third hour of the first watch";
  588.             }
  589.         if (adjusted_time.getHours() === 21)
  590.             {
  591.             log('Reached 13.53');
  592.             liturgical_hour = "The fourth hour of the first watch";
  593.             }
  594.         if (adjusted_time.getHours() === 22)
  595.             {
  596.             log('Reached 13.54');
  597.             liturgical_hour = "The first hour of the second watch";
  598.             }
  599.         if (adjusted_time.getHours() === 23)
  600.             {
  601.             log('Reached 13.55');
  602.             liturgical_hour = "The second hour of the second watch";
  603.             }
  604.         date_string = liturgical_hour + ", " + hours + ":" + minutes + ":" + seconds + " " + meridian + ", " + week_day + ", " + adjusted_time.getDate() + " " + month_name + " " + createNumeral(adjusted_time.getFullYear()) + ", anno domini.";
  605.         document.getElementById('clock').innerHTML = liturgical_hour + ', ' + adjusted_time.toString().substr(0, 21);
  606.         };
  607.     log('Reached 16');
  608.     update_liturgical_time();
  609.     setInterval(update_liturgical_time, MILLISECONDS_DELAY_BETWEEN_UPDATE);
  610.     })();
  611. console.log('Finished pass through clock.js.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement