-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display 1st Sunday of Advent according to the selected year.
- Loading branch information
Showing
3 changed files
with
111 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
$(document).ready(function () { | ||
// Display the year of the current liturgical year in the select_year: | ||
var today = new Date(); | ||
var year = today.getFullYear(); | ||
var christmas = new Date(year, 11, 25); | ||
var christmas_weekday = christmas.getDay(); | ||
var first_sunday_advent = new Date(christmas - (christmas_weekday + (21 * 24 * 3600 * 1000))); | ||
if (today > first_sunday_advent) { | ||
year += 1; | ||
} | ||
// On loading, display the liturgical year of the current date in the select_year: | ||
var year = get_liturgical_year(new Date()); | ||
$('#select_year').val(year); | ||
refresh_ordo(year); | ||
|
||
// On selecting a new year, refresh the ordo: | ||
$('#select_year').change(function () { | ||
console.log($(this).val()); | ||
refresh_ordo($(this).val()); | ||
}); | ||
}); | ||
|
||
|
||
function weekday_human_readable(weekday) { | ||
return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][weekday]; | ||
} | ||
|
||
function month_human_readable(month) { | ||
return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][month]; | ||
} | ||
|
||
function get_liturgical_year(date) { | ||
var year = date.getFullYear(); | ||
var christmas = get_christmas_date(year); | ||
var christmas_weekday = get_christmas_weekday(christmas); | ||
var first_sunday_advent = get_first_sunday_advent(christmas, christmas_weekday); | ||
if (date > first_sunday_advent) { | ||
year += 1; | ||
} | ||
return year; | ||
} | ||
|
||
function get_christmas_date(year) { | ||
return new Date(year, 11, 25); | ||
} | ||
|
||
function get_christmas_weekday(christmas) { | ||
return christmas.getDay(); | ||
} | ||
|
||
function get_first_sunday_advent(christmas, christmas_weekday) { | ||
return new Date(christmas - ((21 + christmas_weekday) * 24 * 3600 * 1000)); | ||
} | ||
|
||
function refresh_ordo(year) { | ||
$('#content').html(''); | ||
var christmas = get_christmas_date(year - 1); | ||
var christmas_weekday = get_christmas_weekday(christmas); | ||
var first_sunday_advent = get_first_sunday_advent(christmas, christmas_weekday); | ||
$('#content').append( | ||
'<div class="year">' + first_sunday_advent.getFullYear() + '</div>' | ||
); | ||
$('#content').append( | ||
'<div class="month">' + month_human_readable(first_sunday_advent.getMonth()) + '</div>' | ||
); | ||
$('#content').append( | ||
'<div class="line">' | ||
+ '<span class="weekday">' + weekday_human_readable(first_sunday_advent.getDay()) + '</span>' | ||
+ ' ' | ||
+ '<span class="day">' + first_sunday_advent.getDate() + '</span>' | ||
+ '<span class="header">First Sunday of Advent</span>' | ||
+ '</div>' | ||
+ '<div class="body">Ad Vigilias dicitur Resp. <i>Aspiciens</i>.</div>' | ||
); | ||
} |