Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.log('Starting clock.js.');
- ;(function()
- {
- console.log('Reached 1');
- var MILLISECONDS_DELAY_BETWEEN_UPDATES = 1000;
- var MAXIMUM_LOG_MESSAGES = 100;
- var current_messages_logged = 0;
- var on_athos_time = false;
- var days_into_future = 1;
- var sunrises_and_sunsets = {};
- var place = null;
- var DISTINCT_PLACE_THRESHOLD = .1;
- var log = function(message)
- {
- if (current_messages_logged >= MAXIMUM_LOG_MESSAGES)
- {
- console.log(message);
- }
- current_messages_logged += 1;
- }
- var get_stored_data = function()
- {
- log('Reached 1.1');
- if (typeof Storage !== 'undefined')
- {
- log('Reached 1.2');
- if (typeof localStorage['place'] !== 'undefined')
- {
- log('Reached 1.3');
- place = JSON.parse(localStorage['place']);
- }
- if (typeof localStorage['sunrises_and_sunsets'] !== 'undefined')
- {
- log('Reached 1.4');
- sunrises_and_sunsets = JSON.parse(localStorage[
- 'sunrises_and_sunsets']);
- }
- }
- };
- get_stored_data();
- log('Reached 2');
- var save_data = function()
- {
- log('Reached 2.1');
- if (typeof Storage !== 'undefined')
- {
- log('Reached 2.2');
- if (place)
- {
- log('Reached 2.3');
- localStorage['place'] = JSON.stringify(place);
- }
- if (sunrises_and_sunsets)
- {
- log('Reached 2.4');
- localStorage['sunrises_and_sunsets'] = JSON.stringify(
- sunrises_and_sunsets);
- }
- }
- }
- log('Reached 3');
- var prune_places = function()
- {
- log('Reached 3.1');
- var changed = false;
- for(var entry in sunrises_and_sunsets)
- {
- log('Reached 3.2');
- if (sunrises_and_sunsets.hasOwnProperty(entry))
- {
- log('Reached 3.3');
- if (typeof sunrises_and_sunsets[entry] !== 'undefined' &&
- Math.abs(sunrises_and_sunsets[entry]['latitude'] -
- place['latitude']) >= DISTINCT_PLACE_THRESHOLD ||
- Math.abs(sunrises_and_sunsets[entry]['longitude'] -
- place['longitude']) >= DISTINCT_PLACE_THRESHOLD)
- {
- log('Reached 3.4');
- changed = true;
- delete sunrises_and_sunsets[entry];
- }
- }
- }
- if (changed)
- {
- log('Reached 3.5');
- save_data();
- }
- }
- log('Reached 4');
- var get_place = function()
- {
- log('Reached 4.1');
- if (on_athos_time)
- {
- log('Reached 4.2');
- jQuery.ajax('http://ip-api.com/json',
- {
- 'success': function(data, textStatus, jqXHR)
- {
- console.log('Reached 4.2.1');
- var received = JSON.parse(jqXHR.responseText);
- place = {
- 'latitude': received['lat'],
- 'longitude': received['lon']
- };
- }
- });
- }
- else
- {
- log('Reached 4.3');
- place = {
- 'latitude': 40.169332656,
- 'longitude': 24.376331828
- };
- }
- };
- get_place();
- log('Reached 5');
- var format_date = function(days_ahead = 0)
- {
- log('Reached 5.1');
- var now_date = new Date();
- var time = now_date.getTime();
- time += days_ahead * 24 * 60 * 60 * 1000;
- var adjusted_date = new Date();
- adjusted_date.setTime(time);
- return adjusted_date.toISOString().substr(0, 10);
- };
- log('Reached 6');
- var get_time = function(ISOString)
- {
- log('Reached 6.1');
- return new Date(ISOString).getTime();
- }
- log('Reached 7');
- var populate_days = function(days_ahead = 1)
- {
- log('Reached 7.1');
- if (place)
- {
- log('Reached 7.2');
- for(var delta = -1; delta <= days_ahead; delta += 1)
- {
- log('Reached 7.3');
- if (typeof sunrises_and_sunsets[format_date(delta)] ===
- 'undefined')
- {
- log('Reached 7.4');
- jQuery.ajax(
- 'http://api.sunrise-sunset.org/?lat=' +
- place['latitude'] + '&lng=' + place['longitude'] +
- '&date=' + format_date(delta) + '&formatted=0',
- {
- 'success': function(data, textStatus, jqXHR)
- {
- log('Reached 7.5');
- var received = JSON.parse(jqXHR.responseText);
- sunrises_and_sunsets[format_date(delta)] = {};
- sunrises_and_sunsets[format_date(delta)][
- 'latitude'] = place['latitude'];
- sunrises_and_sunsets[format_date(delta)][
- 'longitude'] = place['longitude'];
- sunrises_and_sunsets[format_date(delta)][
- 'sunrise'] = received['sunrise'];
- sunrises_and_sunsets[format_date(delta)][
- 'sunset'] = received['sunset'];
- save_sunrises_and_sunsets();
- }
- });
- }
- }
- }
- };
- log('Reached 8');
- setInterval(function()
- {
- log('Reached 8.1');
- populate_days(days_in_future);
- prune_places();
- days_in_future += 1;
- }, 60 * 60 * 1000);
- log('Reached 9');
- var adjusted_time = new Date();
- var force_old_dst = 0;
- var hours_to_add = 0;
- var home = 'Athos';
- var offset = null;
- var ones_numerals = new Array();
- ones_numerals[0] = "";
- ones_numerals[1] = "I";
- ones_numerals[2] = "II";
- ones_numerals[3] = "III";
- ones_numerals[4] = "IV";
- ones_numerals[5] = "V";
- ones_numerals[6] = "VI";
- ones_numerals[7] = "VII";
- ones_numerals[8] = "VIII";
- ones_numerals[9] = "IX";
- var tens_numerals = new Array();
- tens_numerals[0] = "";
- tens_numerals[1] = "X";
- tens_numerals[2] = "XX";
- tens_numerals[3] = "XXX";
- tens_numerals[4] = "XL";
- tens_numerals[5] = "L";
- tens_numerals[6] = "LX";
- tens_numerals[7] = "LXX";
- tens_numerals[8] = "LXXX";
- tens_numerals[9] = "XC";
- var hundreds_numerals = new Array();
- hundreds_numerals[0] = "";
- hundreds_numerals[1] = "C";
- hundreds_numerals[2] = "CC";
- hundreds_numerals[3] = "CCC";
- hundreds_numerals[4] = "CD";
- hundreds_numerals[5] = "D";
- hundreds_numerals[6] = "DC";
- hundreds_numerals[7] = "DCC";
- hundreds_numerals[8] = "DCCC";
- hundreds_numerals[9] = "CM";
- var thousands_numerals = new Array();
- thousands_numerals[0] = "";
- thousands_numerals[1] = "M";
- thousands_numerals[2] = "MM";
- thousands_numerals[3] = "MMM";
- log('Reached 10');
- var checkNumber = function(number)
- {
- log('Reached 10.1');
- if ((parseInt(number) < 4000) && (parseInt(number) > 0))
- {
- log('Reached 10.2');
- var numeral = createNumeral(number);
- if(numeral.indexOf('undefined') === -1)
- {
- log('Reached 10.3');
- }
- }
- else
- {
- log('Reached 10.4');
- alert('you must enter a valid number');
- }
- }
- log('Reached 11');
- var createNumeral = function(num)
- {
- log('Reached 11.1');
- var new_num = num;
- var thousands = Math.floor(new_num / 1000);
- new_num -= thousands * 1000;
- var hundreds = Math.floor(new_num / 100);
- new_num -= hundreds * 100;
- var tens = Math.floor(new_num / 10);
- new_num -= tens * 10;
- var ones = Math.floor(new_num / 1);
- if((thousands === NaN)||(hundreds === NaN)||(tens === NaN)||(ones === NaN))
- {
- log('Reached 11.2');
- alert('you must enter a valid number');
- }
- else
- {
- log('Reached 11.3');
- var array = new Array(thousands,hundreds,tens,ones);
- return makeNumeral(array);
- }
- }
- log('Reached 12');
- var makeNumeral = function(place_values)
- {
- log('Reached 12.1');
- var numeral = "";
- numeral += thousands_numerals[place_values[0]];
- numeral += hundreds_numerals[place_values[1]];
- numeral += tens_numerals[place_values[2]];
- numeral += ones_numerals[place_values[3]];
- return numeral;
- }
- log('Reached 13');
- var update_liturgical_time = function()
- {
- log('Reached 13.1');
- if (sunrises_and_sunsets[format_date(-1)] &&
- sunrises_and_sunsets[format_date(0)] &&
- sunrises_and_sunsets[format_date(1)])
- {
- log('Reached 13.2');
- var sunrise_yesterday_as_double = get_time(sunrises_and_sunsets[
- format_date(-1)]['sunrise']);
- var sunset_yesterday_as_double = get_time(sunrises_and_sunsets[
- format_date(-1)]['sunset']);
- var sunrise_today_as_double = get_time(sunrises_and_sunsets[
- format_date(0)]['sunrise']);
- var sunset_today_as_double = get_time(sunrises_and_sunsets[
- format_date(0)]['sunset']);
- var sunrise_tomorrow_as_double = get_time(sunrises_and_sunsets[
- format_date(1)]['sunrise']);
- var sunset_tomorrow_as_double = get_time(sunrises_and_sunsets[
- format_date(1)]['sunset']);
- var now = new Date();
- if (now.getTime() < sunrise_today_as_double)
- {
- log('Reached 13.3');
- proportion_along = (Number(now.getTime()) - sunset_yesterday_as_double) / (sunrise_today_as_double - sunset_yesterday_as_double);
- seconds_elapsed = today.getTime() + (-6 + proportion_along * 12) * 60 * 60 * 1000;
- }
- else if (now.getTime() < sunset_today_as_double)
- {
- log('Reached 13.4');
- proportion_along = (Number(now.getTime()) - sunrise_today_as_double) / (sunset_today_as_double - sunrise_today_as_double);
- seconds_elapsed = today.getTime() + (6 + proportion_along * 12) * 60 * 60 * 1000;
- }
- else
- {
- log('Reached 13.5');
- proportion_along = (Number(now.getTime()) - sunset_today_as_double) / (sunrise_tomorrow_as_double - sunset_today_as_double);
- seconds_elapsed = today.getTime() + (18 + 24 + proportion_along * 12) * 60 * 60 * 1000;
- }
- adjusted_time.setTime(seconds_elapsed);
- }
- var colon = 0;
- while (("" + now).substr(colon, 1) !== ":")
- {
- log('Reached 13.6');
- ++colon;
- }
- var annotated_now = "";
- annotated_now += ("" + now).substr(0, colon - 2);
- annotated_now += "<span class='now'>";
- annotated_now += ("" + now).substr(colon - 2, 5);
- annotated_now += "</span>";
- var date_string = "";
- var week_day = "";
- if (adjusted_time.getDay() === 0)
- {
- log('Reached 13.7');
- week_day = "Sunday";
- }
- if (adjusted_time.getDay() === 1)
- {
- log('Reached 13.8');
- week_day = "Monday";
- }
- if (adjusted_time.getDay() === 2)
- {
- log('Reached 13.9');
- week_day = "Tuesday";
- }
- if (adjusted_time.getDay() === 3)
- {
- log('Reached 13.10');
- week_day = "Wednesday";
- }
- if (adjusted_time.getDay() === 4)
- {
- log('Reached 13.11');
- week_day = "Thursday";
- }
- if (adjusted_time.getDay() === 5)
- {
- log('Reached 13.12');
- week_day = "Friday";
- }
- if (adjusted_time.getDay() === 6)
- {
- log('Reached 13.11');
- week_day = "Saturday";
- }
- adjusted_time.setTime(adjusted_time.getTime() - 13 * 86400 * 1000)
- var month_name = "";
- if (adjusted_time.getMonth() === 0)
- {
- log('Reached 13.12');
- month_name = "January";
- }
- if (adjusted_time.getMonth() === 1)
- {
- log('Reached 13.13');
- month_name = "February";
- }
- if (adjusted_time.getMonth() === 2)
- {
- log('Reached 13.14');
- month_name = "March";
- }
- if (adjusted_time.getMonth() === 3)
- {
- log('Reached 13.15');
- month_name = "April";
- }
- if (adjusted_time.getMonth() === 4)
- {
- log('Reached 13.16');
- month_name = "May";
- }
- if (adjusted_time.getMonth() === 5)
- {
- log('Reached 13.17');
- month_name = "June";
- }
- if (adjusted_time.getMonth() === 6)
- {
- log('Reached 13.18');
- month_name = "July";
- }
- if (adjusted_time.getMonth() === 7)
- {
- log('Reached 13.19');
- month_name = "August";
- }
- if (adjusted_time.getMonth() === 8)
- {
- log('Reached 13.20');
- month_name = "September";
- }
- if (adjusted_time.getMonth() === 9)
- {
- log('Reached 13.21');
- month_name = "October";
- }
- if (adjusted_time.getMonth() === 10)
- {
- log('Reached 13.22');
- month_name = "November";
- }
- if (adjusted_time.getMonth() === 11)
- {
- log('Reached 13.23');
- month_name = "December";
- }
- var hours = -1;
- var meridian;
- if (adjusted_time.getHours() === 0)
- {
- log('Reached 13.24');
- hours = 12;
- meredian = "ante meridian";
- }
- if (adjusted_time.getHours() > 0 && adjusted_time.getHours() < 12)
- {
- log('Reached 13.25');
- hours = adjusted_time.getHours();
- meridian = "ante meridian";
- }
- if (adjusted_time.getHours() === 12)
- {
- log('Reached 13.26');
- hours = 12;
- meridian = "post meridian";
- }
- if (adjusted_time.getHours() > 12)
- {
- log('Reached 13.27');
- hours = adjusted_time.getHours() - 12;
- meridian = "post meridian";
- }
- var minutes;
- if (adjusted_time.getMinutes() < 10)
- {
- log('Reached 13.28');
- minutes = "0" + adjusted_time.getMinutes();
- }
- if (adjusted_time.getMinutes() >= 10)
- {
- log('Reached 13.29');
- minutes = adjusted_time.getMinutes();
- }
- var seconds;
- if (adjusted_time.getSeconds() < 10)
- {
- log('Reached 13.30');
- seconds = "0" + adjusted_time.getSeconds();
- }
- if (adjusted_time.getSeconds() >= 10)
- {
- log('Reached 13.31');
- seconds = adjusted_time.getSeconds();
- }
- var hour_expression;
- var prayer = "";
- if (adjusted_time.getHours() === 0)
- {
- log('Reached 13.32');
- liturgical_hour = "The third hour of the second watch";
- }
- if (adjusted_time.getHours() === 1)
- {
- log('Reached 13.33');
- liturgical_hour = "The fourth hour of the second watch";
- }
- if (adjusted_time.getHours() === 2)
- {
- log('Reached 13.34');
- liturgical_hour = "The first hour of the third watch";
- }
- if (adjusted_time.getHours() === 3)
- {
- log('Reached 13.35');
- liturgical_hour = "The second hour of the third watch";
- }
- if (adjusted_time.getHours() === 4)
- {
- log('Reached 13.36');
- liturgical_hour = "The third hour of the third watch";
- }
- if (adjusted_time.getHours() === 5)
- {
- log('Reached 13.37');
- liturgical_hour = "The fourth hour of the third watch";
- }
- if (adjusted_time.getHours() === 6)
- {
- log('Reached 13.38');
- liturgical_hour = "The first hour";
- }
- if (adjusted_time.getHours() === 7)
- {
- log('Reached 13.39');
- liturgical_hour = "The second hour";
- }
- if (adjusted_time.getHours() === 8)
- {
- log('Reached 13.40');
- liturgical_hour = "The third hour";
- }
- if (adjusted_time.getHours() === 9)
- {
- log('Reached 13.41');
- liturgical_hour = "The fourth hour";
- }
- if (adjusted_time.getHours() === 10)
- {
- log('Reached 13.42');
- liturgical_hour = "The fifth hour";
- }
- if (adjusted_time.getHours() === 11)
- {
- log('Reached 13.43');
- liturgical_hour = "The sixth hour";
- }
- if (adjusted_time.getHours() === 12)
- {
- log('Reached 13.44');
- liturgical_hour = "The seventh hour";
- }
- if (adjusted_time.getHours() === 13)
- {
- log('Reached 13.45');
- liturgical_hour = "The eighth hour";
- }
- if (adjusted_time.getHours() === 14)
- {
- log('Reached 13.46');
- liturgical_hour = "The ninth hour";
- }
- if (adjusted_time.getHours() === 15)
- {
- log('Reached 13.47');
- liturgical_hour = "The tenth hour";
- }
- if (adjusted_time.getHours() === 16)
- {
- log('Reached 13.48');
- liturgical_hour = "The eleventh hour";
- }
- if (adjusted_time.getHours() === 17)
- {
- log('Reached 13.49');
- liturgical_hour = "The twelfth hour";
- }
- if (adjusted_time.getHours() === 18)
- {
- log('Reached 13.50');
- liturgical_hour = "The first hour of the first watch";
- }
- if (adjusted_time.getHours() === 19)
- {
- log('Reached 13.51');
- liturgical_hour = "The second hour of the first watch";
- }
- if (adjusted_time.getHours() === 20)
- {
- log('Reached 13.52');
- liturgical_hour = "The third hour of the first watch";
- }
- if (adjusted_time.getHours() === 21)
- {
- log('Reached 13.53');
- liturgical_hour = "The fourth hour of the first watch";
- }
- if (adjusted_time.getHours() === 22)
- {
- log('Reached 13.54');
- liturgical_hour = "The first hour of the second watch";
- }
- if (adjusted_time.getHours() === 23)
- {
- log('Reached 13.55');
- liturgical_hour = "The second hour of the second watch";
- }
- date_string = liturgical_hour + ", " + hours + ":" + minutes + ":" + seconds + " " + meridian + ", " + week_day + ", " + adjusted_time.getDate() + " " + month_name + " " + createNumeral(adjusted_time.getFullYear()) + ", anno domini.";
- document.getElementById('clock').innerHTML = liturgical_hour + ', ' + adjusted_time.toString().substr(0, 21);
- };
- log('Reached 16');
- update_liturgical_time();
- setInterval(update_liturgical_time, MILLISECONDS_DELAY_BETWEEN_UPDATE);
- })();
- console.log('Finished pass through clock.js.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement