PDA

View Full Version : adding more dates e.g. good friday

leccie
12-05-2017, 10:36 AM
1) Script Title: date function

2) Script URL (on DD): http://www.javascriptkit.com/script/script2/chdate.shtml

3) Describe problem: How can I add extra dates for example, Good Friday, Easter Monday, and whit Monday for example using the "edate" function as shown here:

calendar = new Date();
day = calendar.getDay();
month = calendar.getMonth();
date = calendar.getDate();
year = calendar.getYear();
if (year < 1000)
year+=1900
cent = parseInt(year/100);
g = year % 19;
k = parseInt((cent - 17)/25);
i = (cent - parseInt(cent/4) - parseInt((cent - k)/3) + 19*g + 15) % 30;
i = i - parseInt(i/28)*(1 - parseInt(i/28)*parseInt(29/(i+1))*parseInt((21-g)/11));
j = (year + parseInt(year/4) + i + 2 - cent + parseInt(cent/4)) % 7;
l = i - j;
emonth = 3 + parseInt((l + 40)/44);
edate = l + 28 - 31*parseInt((emonth/4));
emonth--;
var dayname = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var monthname =
new Array ("January","February","March","April","May","June","July","August","September","October","November","December" );

document.write("<b><font face=Arial size=3 font color=white> ");
// Easter
if ((month == emonth) && (date == edate)) document.write("Easter Sunday (Western) ");

jscheuer1
12-05-2017, 12:51 PM
Easter, Good Friday, and Whit Monday are different each year, and I'm not certain one can trust the calculation used in this code. Apparently they all work off of each other though, so theoretically, if you can calculate one, the other two should be easy enough to find. I would be tempted to just set them like the other fixed dates in the calender, and just update them every year. But assuming that the calculation for Easter is correct (which it is for 2017 and 2018 anyway), and that Good Friday is 2 days before, Whit Monday 50 days after:

emonth = 3 + parseInt((l + 40)/44);
edate = l + 28 - 31*parseInt((emonth/4));
emonth--;
gfwmcal = new Date();
gfwmcal.setMonth(emonth);
gfwmcal.setDate(edate - 2);
gfmonth = gfwmcal.getMonth();
gfdate = gfwmcal.getDate();
gfwmcal.setDate(gfdate + 52);
wmmonth = gfwmcal.getMonth();
wmdate = gfwmcal.getDate();
var dayname = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var monthname =
new Array ("January","February","March","April","May","June","July","August","September","October","November","December" );
document.write("");
document.write(dayname[day] + ", ");
document.write(monthname[month] + " ");
if (date< 10) document.write("0" + date + ", ");
else document.write(date + ", ");
document.write(year + " ");
// Easter and related
if ((month == emonth) && (date == edate)) document.write("Easter Sunday (Western) ");
if ((month == gfmonth) && (date == gfdate)) document.write("Good Friday (Western) ");
if ((month == wmmonth) && (date == wmdate)) document.write("Whit Monday ");
// January
if ((month == 0) && (date == 1)) documen . . .

leccie
12-05-2017, 02:18 PM
Thank you for your prompt response to my question. I am very grateful for your help and advice. I shall have a play with it and see what happens, and I will report back when I have done this. Once again thank you very much.
leccie

jscheuer1
12-05-2017, 09:37 PM
OK. I looked into this Easter date calculation bit more. It appears to be standard and valid to like 2099 or something like that. I kind of cringed though at the overall code, both inefficient and prone to conflicts. Here's an updated version. Slight change, you need to make a "datecontainer" (included in this demo). Also, if you don't want there to be a line break after the date, remove the highlighted line (near the end):

<!DOCTYPE html>
<html>
<title>Java Script Calendar - demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<body>
<span id="datecontainer"></span>
<script>
'use strict';
/* Adapted from Java Script Calendar the credit for which is preserved here - adaptation (c)2017 John Davenport Scheuer
as first seen in http://www.dynamicdrive.com/forums/
username: jscheuer1 - This Notice Must Remain for Legal Use */
/* Original script: http://www.javascriptkit.com/script/script2/chdate.shtml
Java Script Calendar is a small script for web pages which displays current Day of the week, Month, Date and Year along with Holidays notification. Just like this working demo below. It will work with Netscape 2++, Microsoft 3++ and Opera 3++ web browsers.

Tuesday, November 24, 1998

About 70 holidays from all over the world are displayed by Calendar (if you know other ones, let me know, I will add them). It even calculates Easter Sunday date! To see how it works change the date on your computer to January, 1,
for example and re-load the page.*/
(function(){
var calendar = new Date(), day = calendar.getDay(), month = calendar.getMonth(), date = calendar.getDate(), year = calendar.getFullYear(),
f = Math.floor, cent = f(year / 100), g = year % 19, k = f((cent - 17) / 25), i = (cent - f(cent / 4) - f((cent - k) / 3) + 19 * g + 15) % 30,
i = i - f(i / 28) * (1 - f(i / 28) * f(29 / (i+1)) * f((21-g) / 11)), j = (year + f(year / 4) + i + 2 - cent + f(cent / 4)) % 7, l = i - j,
emonth = 3 + f((l + 40) / 44), edate = l + 28 - 31 * f((emonth / 4)), gfwmcal, gfmonth, gfdate, wmmonth, wmdate,
dayname = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"],
html = [dayname[day], ", ", monthname[month], " ", date < 10? "0" : "", date, ", ", year, " "];
--emonth;
gfwmcal = new Date();
gfwmcal.setMonth(emonth);
gfwmcal.setDate(edate - 2);
gfmonth = gfwmcal.getMonth();
gfdate = gfwmcal.getDate();
gfwmcal.setDate(gfdate + 52);
wmmonth = gfwmcal.getMonth();
wmdate = gfwmcal.getDate();
// Easter and Related
if ((month == emonth) && (date == edate)) html.push("Easter Sunday (Western) ");
if ((month == gfmonth) && (date == gfdate)) html.push("Good Friday (Western) ");
if ((month == wmmonth) && (date == wmdate)) html.push("Whit Monday ");
// January
if ((month == 0) && (date == 1)) html.push("New Year's Day");
if ((month == 0) && (date == 15)) html.push("Adults Day (Japan)");
if ((month == 0) && (date == 27)) html.push("Wolfgang Amadeus Mozart born (1756)");
if ((month == 0) && (day == 1) && (date > 14) && (date< 22)) html.push("Martin Luther King's Birthday");
// February
if ((month == 1) && (date == 2)) html.push("Groundhog Day");
if ((month == 1) && (date == 8)) html.push("Jules Verne born (1828)");
if ((month == 1) && (date == 11)) html.push("National Foundation Day (Japan)");
if ((month == 1) && (date== 12)) html.push("Lincoln's Birthday");
if((month == 1) && (date == 14)) html.push("St. Valentine's Day");
if ((month == 1) && (date == 15)) html.push("Galileo Galilei born (1564)");
if ((month == 1) && (date == 22)) html.push("Washington's Birthday");
if ((month == 1) && (date == 29)) html.push("Leap Day");
// March
if ((month == 2) && (date == 3)) html.push("Girl's Day (Japan)");
if ((month == 2) && (date == 17)) html.push("St. Patrick's Day");
if ((month == 2) && (date == 21)) html.push("J.S. Bach born (1685)");
// April
if ((month == 3) && (date == 1)) html.push("April Fools' Day");
if ((month == 3) && (date == 8)) html.push("Buddha born");
if ((month == 3) && (date == 15) && (day != 0)) html.push("Income Tax Day (USA), ");
if ((month == 3) && (date == 16) && (day == 1)) html.push("Income Tax Day (USA) ");
if ((month == 3) && (date == 15)) html.push("Leonardo da Vinci born (1452)");
if ((month == 3) && (date == 22)) html.push("Earth Day");
if ((month == 3) && (date == 29)) html.push("Emperor's Birthday (Japan)");
if ((month == 3) && (day == 0) && (date > 0) && (date< 8)) html.push("Daylight Savings Time Begins");
// May
if ((month == 4) && (date == 1)) html.push("May Day, Boy's Day (Japan)");
if ((month == 4) && (date == 2)) html.push("Constitution Day (Japan)");
if ((month == 4) && (date == 5)) html.push("Cinco de Mayo (Mexico), Children's Day (Japan)");
if ((month == 4) && (date == 14)) html.push("Independence Day (Paraguay)");
if ((month == 4) && (day == 0) && (date > 7) && (date< 16)) html.push("Mother's Day");
if ((month == 4) && (day == 1) && (date > 24)) html.push("Memorial Day");
// June
if ((month == 5) && (date == 5)) html.push("Constitution Day (Denmark)");
if ((month == 5) && (date == 6)) html.push("D-Day (USA)");
if ((month == 5) && (date == 11)) html.push("Kamehameha (Hawaii)");
if ((month == 5) && (date == 14)) html.push("FlagDay (USA)");
if ((month == 5) && (date == 21)) html.push("Summer Solstice");
if((month == 5) && (date == 24)) html.push("St. Jean Baptiste Day (Canada)");
if ((month == 5) && (date == 30)) html.push("Independence Day (Zaire)");
if ((month == 5) && (day == 0) && (date > 15) && (date< 24)) html.push("Father's Day");
// July
if ((month == 6) && (date == 1)) html.push("Independence Day (Canada)");
if ((month == 6) && (date == 4)) html.push("Independence Day (USA)");
if ((month == 6) && (date == 14)) html.push("Bastille Day (France)");
// August
if ((month == 7) && (date == 1)) html.push("Confederation Day (Switzerland)");
if ((month == 7) && (date == 10)) html.push("Independence Day (Ecuador)");
if ((month == 7) && (date == 15)) html.push("Independence Day (India)");
// September
if ((month == 8) && (date == 7)) html.push("Independence Day (Brazil)");
if ((month == 8) && (date == 15)) html.push("Respect for the Aged Day (Japan)");
if ((month == 8) && (date == 16)) html.push("Independence Day (Mexico)");
if ((month == 8) && (day== 1)&& (date > 0) && (date< 8)) html.push("Labor Day (USA)");
// October
if ((month == 9) && (date == 1)) html.push("German Reunufication (1990)");
if ((month == 9) && (date == 10)) html.push("Health-Sports Day (Japan)");
if ((month == 9) && (day == 1) && (date > 7) && (date< 16)) html.push("Columbus Day (USA)");
if ((month == 9) && (day == 0) && (date > 24) && (date< 31)) html.push("Daylight Savings Time Ends");
if ((month == 9) && (day == 0) && (date == 31)) html.push("Daylight Savings Time Ends<BR>");
if ((month == 9) && (date == 24)) html.push("United Nations Day");
if ((month == 9) && (date == 31)) html.push("Halloween");
// November
if ((month == 10) && (date == 1)) html.push("All Saints Day");
if ((month == 10) && (date == 2)) html.push("All Souls Day");
if ((month == 10) && (date == 3)) html.push("Culture Day (Japan)");
if ((month == 10) && (date == 11)) html.push("Veteran's Day (USA), Remembrance Day (Canada)");
if ((month == 10) && (date ==20)) html.push("Revolution Day (Mexico)");
if ((month == 10) && (date == 23)) html.push("Labor Thanksgiving Day (Japan)");
if ((month == 10) && (day == 4) && (date > 23) && (date< 30)) html.push("Thanksgiving (USA)");
if ((month == 10) && (date == 30) && (day == 4)) html.push("Thanksgiving (USA)");
// December
if ((month == 11) && (date == 10)) html.push("Human Rights Day");
if ((month == 11) && (date == 21)) html.push("Winter Solstice");
if ((month == 11) && (date == 24)) html.push("Christmas Eve");
if ((month == 11) && (date == 25)) html.push("Christmas");
if ((month == 11) && (date == 26)) html.push("Boxing Day");
if ((month == 11) && (date == 31)) html.push("New Year's Eve");
html.push("<br>");
document.getElementById('datecontainer').innerHTML = html.join('');
})();
</script>

</body>
</html>

leccie
12-06-2017, 10:34 AM
Hi John, I find this all very challenging, and very fascinating, to say the least. I have studied how you have set the dates to be called up, and have attempted to replicate what you have done so that I can also call up the first day of Advent. There must be 4 Sundays before Christmas. Therefore, Advent could occur in the last week of November or the first week of December. If you would be kind enough to look at what I have tried to do would you explain what I have done wrong, and how to do it correctly? This is what I have done. but it does not work.

(function(){
var calendar = new Date(), day = calendar.getDay(), month = calendar.getMonth(), date = calendar.getDate(), year = calendar.getFullYear(),
f = Math.floor, cent = f(year / 100), g = year % 19, k = f((cent - 17) / 25), i = (cent - f(cent / 4) - f((cent - k) / 3) + 19 * g + 15) % 30,
i = i - f(i / 28) * (1 - f(i / 28) * f(29 / (i+1)) * f((21-g) / 11)), j = (year + f(year / 4) + i + 2 - cent + f(cent / 4)) % 7, l = i - j,
emonth = 3 + f((l + 40) / 44), edate = l + 28 - 31 * f((emonth / 4)), gfwmcal, gfmonth, gfdate, wmmonth, wmdate, advmonth,
dayname = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"],
html = [dayname[day], ", ", monthname[month], " ", date < 10? "0" : "", date, ", ", year, " "];
--emonth;
gfwmcal = new Date();
gfwmcal.setMonth(emonth);
gfwmcal.setDate(edate - 2);
gfmonth = gfwmcal.getMonth();
gfdate = gfwmcal.getDate();
gfwmcal.setDate(gfdate + 52);
wmmonth = gfwmcal.getMonth();
wmdate = gfwmcal.getDate();
gfwmcal.setDate (gfdate + 236);
// Easter and Related
if ((month == emonth) && (date == edate)) html.push("Easter Sunday (Western) ");
if ((month == gfmonth) && (date == gfdate)) html.push("Good Friday (Western) ");
if ((month == wmmonth) && (date == wmdate)) html.push("Whit Monday ");
if ((month == advmonth) && (date == adate)) html.push("First day of Advent" );

leccie
12-06-2017, 11:06 AM
I have referenced what I am was trying to do here: https://www.staff.science.uu.nl/~gent0113/easter/easter_text2c.htm But because the amount of days between Easter Sunday and Advent are not fixed it would seem that there is no datum to work from.
John

leccie
12-06-2017, 12:29 PM
A thought occurs to me. Christmas day is a fixed date, so could Advent Sunday be calculated from the 25th of December?

jscheuer1
12-06-2017, 02:18 PM
Sure, it can be easily worked out from Christmas:

var adcal = new Date(), cd = 25; //Xmas day
while(adcal.getDay()){ //while not a Sunday add a day
}
adcal.setDate(cd - 28); // go back 4 weeks
}

That's the basic idea. Here it is integrated into the calendar function:

<!DOCTYPE html>
<html>
<title>Java Script Calendar - demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<body>
<span id="datecontainer"></span>
<script>
'use strict';
/* Adapted from Java Script Calendar the credit for which is preserved here - adaptation (c)2017 John Davenport Scheuer
as first seen in http://www.dynamicdrive.com/forums/
username: jscheuer1 - This Notice Must Remain for Legal Use */
/* Original script: http://www.javascriptkit.com/script/script2/chdate.shtml
Java Script Calendar is a small script for web pages which displays current Day of the week, Month, Date and Year along with Holidays notification. Just like this working demo below. It will work with Netscape 2++, Microsoft 3++ and Opera 3++ web browsers.

Tuesday, November 24, 1998

About 70 holidays from all over the world are displayed by Calendar (if you know other ones, let me know, I will add them). It even calculates Easter Sunday date! To see how it works change the date on your computer to January, 1,
for example and re-load the page.*/
(function(){
var calendar = new Date(), day = calendar.getDay(), month = calendar.getMonth(), date = calendar.getDate(), year = calendar.getFullYear(),
f = Math.floor, cent = f(year / 100), g = year % 19, k = f((cent - 17) / 25), i = (cent - f(cent / 4) - f((cent - k) / 3) + 19 * g + 15) % 30,
i = i - f(i / 28) * (1 - f(i / 28) * f(29 / (i+1)) * f((21-g) / 11)), j = (year + f(year / 4) + i + 2 - cent + f(cent / 4)) % 7, l = i - j,
emonth = 3 + f((l + 40) / 44), edate = l + 28 - 31 * f((emonth / 4)), gfwmcal, gfmonth, gfdate, wmmonth, wmdate, adcal, admonth, addate,
dayname = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], cd = 25,
monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"],
html = [dayname[day], ", ", monthname[month], " ", date < 10? "0" : "", date, ", ", year, " "];
--emonth;
gfwmcal = new Date();
gfwmcal.setMonth(emonth);
gfwmcal.setDate(edate - 2);
gfmonth = gfwmcal.getMonth();
gfdate = gfwmcal.getDate();
gfwmcal.setDate(gfdate + 52);
wmmonth = gfwmcal.getMonth();
wmdate = gfwmcal.getDate();
adcal = new Date();
}
// Easter and Related
if ((month == emonth) && (date == edate)) html.push("Easter Sunday (Western) ");
if ((month == gfmonth) && (date == gfdate)) html.push("Good Friday (Western) ");
if ((month == wmmonth) && (date == wmdate)) html.push("Whit Monday ");
if ((month == admonth) && (date == addate)) html.push("Advent Sunday ");
// January
if ((month == 0) && (date == 1)) html.push("New Year's Day");
if ((month == 0) && (date == 15)) html.push("Adults Day (Japan)");
if ((month == 0) && (date == 27)) html.push("Wolfgang Amadeus Mozart born (1756)");
if ((month == 0) && (day == 1) && (date > 14) && (date< 22)) html.push("Martin Luther King's Birthday");
// February
if ((month == 1) && (date == 2)) html.push("Groundhog Day");
if ((month == 1) && (date == 8)) html.push("Jules Verne born (1828)");
if ((month == 1) && (date == 11)) html.push("National Foundation Day (Japan)");
if ((month == 1) && (date== 12)) html.push("Lincoln's Birthday");
if((month == 1) && (date == 14)) html.push("St. Valentine's Day");
if ((month == 1) && (date == 15)) html.push("Galileo Galilei born (1564)");
if ((month == 1) && (date == 22)) html.push("Washington's Birthday");
if ((month == 1) && (date == 29)) html.push("Leap Day");
// March
if ((month == 2) && (date == 3)) html.push("Girl's Day (Japan)");
if ((month == 2) && (date == 17)) html.push("St. Patrick's Day");
if ((month == 2) && (date == 21)) html.push("J.S. Bach born (1685)");
// April
if ((month == 3) && (date == 1)) html.push("April Fools' Day");
if ((month == 3) && (date == 8)) html.push("Buddha born");
if ((month == 3) && (date == 15) && (day != 0)) html.push("Income Tax Day (USA), ");
if ((month == 3) && (date == 16) && (day == 1)) html.push("Income Tax Day (USA) ");
if ((month == 3) && (date == 15)) html.push("Leonardo da Vinci born (1452)");
if ((month == 3) && (date == 22)) html.push("Earth Day");
if ((month == 3) && (date == 29)) html.push("Emperor's Birthday (Japan)");
if ((month == 3) && (day == 0) && (date > 0) && (date< 8)) html.push("Daylight Savings Time Begins");
// May
if ((month == 4) && (date == 1)) html.push("May Day, Boy's Day (Japan)");
if ((month == 4) && (date == 2)) html.push("Constitution Day (Japan)");
if ((month == 4) && (date == 5)) html.push("Cinco de Mayo (Mexico), Children's Day (Japan)");
if ((month == 4) && (date == 14)) html.push("Independence Day (Paraguay)");
if ((month == 4) && (day == 0) && (date > 7) && (date< 16)) html.push("Mother's Day");
if ((month == 4) && (day == 1) && (date > 24)) html.push("Memorial Day");
// June
if ((month == 5) && (date == 5)) html.push("Constitution Day (Denmark)");
if ((month == 5) && (date == 6)) html.push("D-Day (USA)");
if ((month == 5) && (date == 11)) html.push("Kamehameha (Hawaii)");
if ((month == 5) && (date == 14)) html.push("FlagDay (USA)");
if ((month == 5) && (date == 21)) html.push("Summer Solstice");
if((month == 5) && (date == 24)) html.push("St. Jean Baptiste Day (Canada)");
if ((month == 5) && (date == 30)) html.push("Independence Day (Zaire)");
if ((month == 5) && (day == 0) && (date > 15) && (date< 24)) html.push("Father's Day");
// July
if ((month == 6) && (date == 1)) html.push("Independence Day (Canada)");
if ((month == 6) && (date == 4)) html.push("Independence Day (USA)");
if ((month == 6) && (date == 14)) html.push("Bastille Day (France)");
// August
if ((month == 7) && (date == 1)) html.push("Confederation Day (Switzerland)");
if ((month == 7) && (date == 10)) html.push("Independence Day (Ecuador)");
if ((month == 7) && (date == 15)) html.push("Independence Day (India)");
// September
if ((month == 8) && (date == 7)) html.push("Independence Day (Brazil)");
if ((month == 8) && (date == 15)) html.push("Respect for the Aged Day (Japan)");
if ((month == 8) && (date == 16)) html.push("Independence Day (Mexico)");
if ((month == 8) && (day== 1)&& (date > 0) && (date< 8)) html.push("Labor Day (USA)");
// October
if ((month == 9) && (date == 1)) html.push("German Reunufication (1990)");
if ((month == 9) && (date == 10)) html.push("Health-Sports Day (Japan)");
if ((month == 9) && (day == 1) && (date > 7) && (date< 16)) html.push("Columbus Day (USA)");
if ((month == 9) && (day == 0) && (date > 24) && (date< 31)) html.push("Daylight Savings Time Ends");
if ((month == 9) && (day == 0) && (date == 31)) html.push("Daylight Savings Time Ends<BR>");
if ((month == 9) && (date == 24)) html.push("United Nations Day");
if ((month == 9) && (date == 31)) html.push("Halloween");
// November
if ((month == 10) && (date == 1)) html.push("All Saints Day");
if ((month == 10) && (date == 2)) html.push("All Souls Day");
if ((month == 10) && (date == 3)) html.push("Culture Day (Japan)");
if ((month == 10) && (date == 11)) html.push("Veteran's Day (USA), Remembrance Day (Canada)");
if ((month == 10) && (date ==20)) html.push("Revolution Day (Mexico)");
if ((month == 10) && (date == 23)) html.push("Labor Thanksgiving Day (Japan)");
if ((month == 10) && (day == 4) && (date > 23) && (date< 30)) html.push("Thanksgiving (USA)");
if ((month == 10) && (date == 30) && (day == 4)) html.push("Thanksgiving (USA)");
// December
if ((month == 11) && (date == 10)) html.push("Human Rights Day");
if ((month == 11) && (date == 21)) html.push("Winter Solstice");
if ((month == 11) && (date == 24)) html.push("Christmas Eve");
if ((month == 11) && (date == 25)) html.push("Christmas");
if ((month == 11) && (date == 26)) html.push("Boxing Day");
if ((month == 11) && (date == 31)) html.push("New Year's Eve");
html.push("<br>");
document.getElementById('datecontainer').innerHTML = html.join('');
})();
</script>

</body>
</html>

leccie
12-06-2017, 06:54 PM
Well, another issue has arisen. When your revised script is added to the page nothing appears! Having spent a while looking at what could be the cause of this, it is, I suspect because the font description is not referenced. This how it appears it the original Script:

new Array ("January","February","March","April","May","June","July","August","September","October","November","December" );

document.write("<b><font face=Arial size=3 font color=white> ");
// Easter
if ((month == emonth) && (date == edate)) document.write("Easter Sunday (Western) ");
// January

Now am I right in thinking this is due to the document.write function being replaced by html.push? So, how should the font be referenced in the re-coded version. I have tried several different approaches but without success.

jscheuer1
12-06-2017, 07:23 PM
Font is deprecated. document.write is deprecated. I'm using innerHTML, which requires a receiving element*:

<span id="datecontainer"></span>

Make sure that appears on your page before this script. Place it where you want the date to appear.

Working demo:

http://jscheuer1.com/demos/tidbits/dates.htm

If you want to modify the appearance of the text of the date, you can do it using style (any questions on that part, let me know).

If it's still not working, please post a link to the page on your site that shows the problem.

The page may need to be reloaded, and/or the browser cache cleared to see changes.

* I mentioned this before, but didn't stress it. I thought you would just follow the example I provided. Sorry.

The more I look at this, the more I see issues. I've just updated it to accurately reflect current DST changes, Tax day and Thanksgiving, and make it more consistent syntactically, changes also uploaded to my live demo:

<!DOCTYPE html>
<html>
<title>Java Script Calendar - demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<body>
<span id="datecontainer"></span>
<script>
'use strict';
/* Adapted from Java Script Calendar the credit for which is preserved here - adaptation (c)2017 John Davenport Scheuer
as first seen in http://www.dynamicdrive.com/forums/
username: jscheuer1 - This Notice Must Remain for Legal Use */
/* Original script: http://www.javascriptkit.com/script/script2/chdate.shtml
Java Script Calendar is a small script for web pages which displays current Day of the week, Month, Date and Year along with Holidays notification. Just like this working demo below. It will work with Netscape 2++, Microsoft 3++ and Opera 3++ web browsers.

Tuesday, November 24, 1998

About 70 holidays from all over the world are displayed by Calendar (if you know other ones, let me know, I will add them). It even calculates Easter Sunday date! To see how it works change the date on your computer to January, 1,
for example and re-load the page.*/
(function(){
var linebreak = true; // should line break be added after date and holidays (if any) (true/false)
var calendar = new Date(), day = calendar.getDay(), month = calendar.getMonth(), date = calendar.getDate(), year = calendar.getFullYear(),
f = Math.floor, cent = f(year / 100), g = year % 19, k = f((cent - 17) / 25), i = (cent - f(cent / 4) - f((cent - k) / 3) + 19 * g + 15) % 30,
i = i - f(i / 28) * (1 - f(i / 28) * f(29 / (i+1)) * f((21-g) / 11)), j = (year + f(year / 4) + i + 2 - cent + f(cent / 4)) % 7, l = i - j,
emonth = 3 + f((l + 40) / 44), edate = l + 28 - 31 * f((emonth / 4)), gfwmcal = new Date(), adcal = new Date(), cd = 25, gfmonth, dhtml = [],
dayname = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], gfdate, wmmonth, wmdate, admonth, addate,
monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"], td = 1,
html = [dayname[day], ", ", monthname[month], " ", date < 10? "0" : "", date, ", ", year], thanksdate = new Date(), thanks = 0;
--emonth;
gfwmcal.setMonth(emonth);
gfwmcal.setDate(edate - 2);
gfmonth = gfwmcal.getMonth();
gfdate = gfwmcal.getDate();
gfwmcal.setDate(gfdate + 52);
wmmonth = gfwmcal.getMonth();
wmdate = gfwmcal.getDate();
thanksdate.setMonth(10);
thanksdate.setDate(1);
if(thanksdate.getDay() === 4) {++thanks;}
while(thanks !== 4){thanksdate.setDate(++td); if(thanksdate.getDay() === 4){++thanks;}}
thanksdate = thanksdate.getDate();
// Easter and Related
if (month === emonth && date === edate) dhtml.push("Easter Sunday (Western)");
if (month === gfmonth && date === gfdate) dhtml.push("Good Friday (Western)");
if (month === wmmonth && date === wmdate) dhtml.push("Whit Monday");
if (month === admonth && date === addate) dhtml.push("Advent Sunday");
if (month === 0){ // January
if (date === 1) dhtml.push("New Year's Day");
if (date === 15) dhtml.push("Adults Day (Japan)");
if (date === 27) dhtml.push("Wolfgang Amadeus Mozart born (1756)");
if (day === 1 && date > 14 && date < 22) dhtml.push("Martin Luther King's Birthday");
}
if (month === 1){ // February
if (date === 2) dhtml.push("Groundhog Day");
if (date === 8) dhtml.push("Jules Verne born (1828)");
if (date === 11) dhtml.push("National Foundation Day (Japan)");
if (date === 12) dhtml.push("Lincoln's Birthday");
if (date === 14) dhtml.push("St. Valentine's Day");
if (date === 15) dhtml.push("Galileo Galilei born (1564)");
if (date === 22) dhtml.push("Washington's Birthday");
if (date === 29) dhtml.push("Leap Day");
}
if (month === 2){ // March
if (date === 3) dhtml.push("Girl's Day (Japan)");
if (day === 0 && date > 7 && date < 15) dhtml.push("Daylight Saving Time Begins (most of USA)");
if (date === 17) dhtml.push("St. Patrick's Day");
if (date === 21) dhtml.push("J.S. Bach born (1685)");
}
if (month === 3){ // April
if (date === 15 && day !== 0 && day !== 6) dhtml.push("Income Tax Day (USA)");
if ((date === 16 || date === 17) && day === 1) dhtml.push("Income Tax Day (USA)");
if (date === 1) dhtml.push("April Fools' Day");
if (date === 8) dhtml.push("Buddha born");
if (date === 15) dhtml.push("Leonardo da Vinci born (1452)");
if (date === 22) dhtml.push("Earth Day");
if (date === 29) dhtml.push("Emperor's Birthday (Japan)");
}
if (month === 4){ // May
if (date === 1) dhtml.push("May Day, Boy's Day (Japan)");
if (date === 2) dhtml.push("Constitution Day (Japan)");
if (date === 5) dhtml.push("Cinco de Mayo (Mexico), Children's Day (Japan)");
if (date === 14) dhtml.push("Independence Day (Paraguay)");
if (day === 0 && date > 7 && date < 16) dhtml.push("Mother's Day");
if (day === 1 && date > 24) dhtml.push("Memorial Day");
}
if (month === 5){ // June
if (date === 5) dhtml.push("Constitution Day (Denmark)");
if (date === 6) dhtml.push("D-Day (USA)");
if (date === 11) dhtml.push("Kamehameha (Hawaii)");
if (date === 14) dhtml.push("FlagDay (USA)");
if (date === 21) dhtml.push("Summer Solstice");
if (date === 24) dhtml.push("St. Jean Baptiste Day (Canada)");
if (date === 30) dhtml.push("Independence Day (Zaire)");
if (day === 0 && date > 15 && date < 24) dhtml.push("Father's Day");
}
if (month === 6){ // July
if (date === 1) dhtml.push("Independence Day (Canada)");
if (date === 4) dhtml.push("Independence Day (USA)");
if (date === 14) dhtml.push("Bastille Day (France)");
}
if (month === 7){ // August
if (date === 1) dhtml.push("Confederation Day (Switzerland)");
if (date === 10) dhtml.push("Independence Day (Ecuador)");
if (date === 15) dhtml.push("Independence Day (India)");
}
if (month === 8){ // September
if (date === 7) dhtml.push("Independence Day (Brazil)");
if (date === 15) dhtml.push("Respect for the Aged Day (Japan)");
if (date === 16) dhtml.push("Independence Day (Mexico)");
if (day === 1 && date > 0 && date < 8) dhtml.push("Labor Day (USA)");
}
if (month === 9){ // October
if (date === 1) dhtml.push("German Reunufication (1990)");
if (date === 10) dhtml.push("Health-Sports Day (Japan)");
if (day === 1 && date > 7 && date < 16) dhtml.push("Columbus Day (USA)");
if (date === 24) dhtml.push("United Nations Day");
if (date === 31) dhtml.push("Halloween");
}
if (month === 10){ // November
if (day === 0 && date < 8) dhtml.push("Daylight Saving Time Ends (most of USA)");
if (date === 1) dhtml.push("All Saints Day");
if (date === 2) dhtml.push("All Souls Day");
if (date === 3) dhtml.push("Culture Day (Japan)");
if (date === 11) dhtml.push("Veteran's Day (USA), Remembrance Day (Canada)");
if (date === 20) dhtml.push("Revolution Day (Mexico)");
if (date === thanksdate) dhtml.push("Thanksgiving (USA)");
if (date === 23) dhtml.push("Labor Thanksgiving Day (Japan)");
}
if (month === 11){ // December
if (date === 10) dhtml.push("Human Rights Day");
if (date === 21) dhtml.push("Winter Solstice");
if (date === 24) dhtml.push("Christmas Eve");
if (date === 25) dhtml.push("Christmas");
if (date === 26) dhtml.push("Boxing Day");
if (date === 31) dhtml.push("New Year's Eve");
}
document.getElementById('datecontainer').innerHTML = html.join('') + (dhtml.length? ' - ' + dhtml.join(', ') : '');
if(linebreak){document.getElementById('datecontainer').appendChild(document.createElement('br'));}
})();
</script>

</body>
</html>

leccie
12-07-2017, 11:55 AM
Just tried to submit page code but it was rejected because it was to many characters. Unfortunately it is still not working. Right now the site is not up on the web because my ISP has just discontinued hosting. So, before going to a new host I thought I would take the opportunity to to some major updating.

jscheuer1
12-07-2017, 12:49 PM
That's OK. The main thing is that you include the target element as I've explained. Do you understand what I said about that? Assuming there's nothing else causing the problem, that will fix it.

In any case, I've been tweaking the code some more, and probably will continue to do so. You can always see my latest version here:

http://jscheuer1.com/demos/tidbits/dates.htm

Use the browser's "view source" (usually CTRL + U) to see the code. And if you have any further questions, or requests for dates, just let me know. This is still a very simple script to use. So even if I cannot see your page, we can probably get it working for you.

You could attach a zip version of your file to a message here, or if you prefer, I can PM you my email address and you could attach it to an email message. Don't put code directly into an email though, it will get messed up.

leccie
12-07-2017, 01:52 PM
Not quite sure about how to attach file. It would be more simple for me if you sent me your PM.

leccie
12-07-2017, 03:24 PM
The attached file is the code for the web page in its original form.

jscheuer1
12-07-2017, 08:56 PM
OK, looks like a ton of stuff you got there, especially in the first of the two of the calendar scripts. Anyways, I've updated you to the latest code, so should make any future changes you'd like easier for us to work out between us:

6236

I've got a question though, you have (October):

if ((month == 9) && (day == 0) && (date > 24) && (date< 31)) document.write("GMT begins today");
if ((month == 9) && (day == 0) && (date == 31)) document.write("GMT begins today<BR>");

What is that supposed to mean? GMT is always on, or are you in Europe somewhere near the prime meridian and you are trying to say it's the end of Daylight Saving Time? If so, I'm not sure that's accurate. At least in the US, we keep it much longer than that now, not sure what they do in other places. I've left it in for October (converted to the new way of showing things like that):

if (day === 0 && date > 24 && date < 31) dhtml.push("GMT begins today");
if (day === 0 && date === 31) dhtml.push("GMT begins today<BR>");

But I'd like to know your thinking on this. I also removed from April:

if ((month == 3) && (day == 0) && (date > 0) && (date< 8)) document.write("Daylight Saving Time Begins (North America)");

Because, here at least we do it earlier, I think all of North America does, not sure. Replacing it with, for March (again, in the new syntax):

if (day === 0 && date > 7 && date < 15) dhtml.push("Daylight Saving Time Begins (most of USA)");

Where are you? That would help me figure this out, but at the same time, if your users are from all over the world, it might be best to skip announcements of time changes altogether, as they vary depending upon location, even within the US, and certainly by hemisphere as well as by nation. Then again, if you expect your users to be mostly from a certain locale, we could do the one for it and note it as such.

Any other new dates, questions, or problems, let me know.

Oh, and I think your nth Day of Advent might be off. We can fix that. Is Advent Sunday considered the 1st Day of Advent? And do you only want to cover the first 12 days (as in the 12 days of Christmas, perhaps) of Advent? I ask because that's the latest day of Advent you have featured in the code you sent me. I have to admit not being up on Advent and how it may be viewed by anyone with more specific knowledge of it than I have.

leccie
12-08-2017, 10:23 AM
John

leccie
12-08-2017, 11:41 AM
Not sure how complex this makes it, but I came across this on the internet. Shrove Tuesday is linked to Easter, so its date changes on an annual basis. The date can vary from as early as February 3rd to as late as March 9th. So, it seems I was yet again wrong in my presumption that Shrove Tuesday always falls on the last Tuesday of February.

jscheuer1
12-08-2017, 01:45 PM

leccie
12-08-2017, 02:56 PM
I think that an advent count down in days will be difficult to achieve, impossible in fact I would say, because Advent Sunday varies if I have interpreted it correctly, irrespective of which Sunday Advent is. Advent finishes on Christmas so the amount of days in Advent will be different each year. Take a look here http://catholic-resources.org/Lectionary/Overview-Advent.htm I think that will give a much clearer explanation than I can. If it is to complex don't bother. Advent Sunday will be just fine. If the US day light saving is the same as the UK then it would be nice to display that too. If it is different it would still be good to include US day light saving.

jscheuer1
12-08-2017, 04:03 PM
Advent is easy to do, I've already done it. It's just a matter of how many days of it you want. Right now I have twelve. If you stop at twelve, there's no danger of running over. I suppose one could have 28 though (the maximum), but then you would have to break out of the loop on Christmas, so as not to go over. I have it set as a loop, tested and it works:

if (month === admonth && date === addate) dhtml.push("Advent Sunday");
adnames = ['Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth'];
for(i = 0; i < adnames.length; ++i){
if (month === adcal.getMonth() && date === (addate = adcal.getDate())) dhtml.push("Today is the " + adnames[i] + " Day of Advent");
}

This works off the fact that we already calculated Advent for the current year. If one wanted to run all the way to Christmas, one could just make testing for the month being equal to 11 and the date being equal to 25 as a signal to break out of the loop. If you want to have the maximum, the question arises as to whether or not Christmas is the nth day of Advent, or if Advent is over on Christmas. Let me know if you want the max, it will be easy to add, and, if so, if Christmas (the 25th) is included or if the 24th of Dec is the last Advent day.

I've added Shrove Tuesday as well, that was actually a little harder. Since you only want these for the second date thing on that page, I've updated that for you and switched it back to UK time changes (also only involved in this second date feature):

<script>
'use strict';
/* Adapted from Java Script Calendar the credit for which is preserved here - adaptation (c)2017 John Davenport Scheuer
as first seen in http://www.dynamicdrive.com/forums/
username: jscheuer1 - This Notice Must Remain for Legal Use */
/* Original script: http://www.javascriptkit.com/script/script2/chdate.shtml
Java Script Calendar is a small script for web pages which displays current Day of the week, Month, Date and Year along with Holidays notification. Just like this working demo below. It will work with Netscape 2++, Microsoft 3++ and Opera 3++ web browsers.

Tuesday, November 24, 1998

About 70 holidays from all over the world are displayed by Calendar (if you know other ones, let me know, I will add them). It even calculates Easter Sunday date! To see how it works change the date on your computer to January, 1,
for example and re-load the page.*/
(function(){
var linebreak = true, // should line break be added after date and holidays (if any) (true/false)
calendar = new Date(), day = calendar.getDay(), month = calendar.getMonth(), date = calendar.getDate(), year = calendar.getFullYear(),
f = Math.floor, cent = f(year / 100), g = year % 19, k = f((cent - 17) / 25), i = (cent - f(cent / 4) - f((cent - k) / 3) + 19 * g + 15) % 30,
i = i - f(i / 28) * (1 - f(i / 28) * f(29 / (i+1)) * f((21-g) / 11)), j = (year + f(year / 4) + i + 2 - cent + f(cent / 4)) % 7, l = i - j,
emonth = 3 + f((l + 40) / 44), edate = l + 28 - 31 * f((emonth / 4)), gfwmcal = new Date(), adcal = new Date(), cd = 25, gfmonth, dhtml = [],
dayname = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], gfdate, wmmonth, wmdate, admonth, addate, sd,
monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"], stcal = new Date(),
html = [dayname[day], ", ", monthname[month], " ", date < 10? "0" : "", date, ", ", year], thanksdate = new Date(), stmonth, stdate, adnames;
gfwmcal.setMonth(--emonth);
gfwmcal.setDate(edate - 2);
gfmonth = gfwmcal.getMonth();
gfdate = gfwmcal.getDate();
gfwmcal.setDate(gfdate + 52);
wmmonth = gfwmcal.getMonth();
wmdate = gfwmcal.getDate();
stcal.setMonth(emonth);
stcal.setDate(edate - 49);
sd = stcal.getDate();
stcal.setDate(sd + 2 - stcal.getDay());
stmonth = stcal.getMonth();
stdate = stcal.getDate();
thanksdate.setMonth(10);
thanksdate.setDate(1);
thanksdate = 5 - thanksdate.getDay();
thanksdate += (thanksdate < 1? 28 : 21);
// Easter and Related
if (month === emonth && date === edate) dhtml.push("Easter Sunday (Western)");
if (month === gfmonth && date === gfdate) dhtml.push("Good Friday (Western)");
if (month === wmmonth && date === wmdate) dhtml.push("Whit Monday");
if (month === stmonth && date === stdate) dhtml.push("Shrove Tuesday");
if (month === admonth && date === addate) dhtml.push("Advent Sunday");
adnames = ['Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth'];
for(i = 0; i < adnames.length; ++i){
if (month === adcal.getMonth() && date === (addate = adcal.getDate())) dhtml.push("Today is the " + adnames[i] + " Day of Advent");
}
[function(){ // January
if (date === 1) dhtml.push("New Year's Day");
if (date === 27) dhtml.push("Wolfgang Amadeus Mozart born (1756)");
if (day === 1 && date > 14 && date < 22) dhtml.push("Martin Luther King's Birthday");
},
function(){ // February
if (date === 2) dhtml.push("Groundhog Day");
if (date === 8) dhtml.push("Jules Verne born (1828)");
if (date === 11) dhtml.push("National Foundation Day (Japan)");
if (date === 12) dhtml.push("Lincoln's Birthday");
if (date === 14) dhtml.push("St. Valentine's Day");
if (date === 15) dhtml.push("Galileo Galilei born (1564)");
if (date === 22) dhtml.push("Washington's Birthday");
if (day == 0 && date > 0 && date < 8) document.write("Daylight Saving Time Begins (UK)");
if (date === 29) dhtml.push("Leap Day");
},
function(){ // March
if (date === 1) dhtml.push("St Davids Day");
if (date === 17) dhtml.push("St. Patrick's Day");
if (date === 21) dhtml.push("First day of Spring");
},
function(){ // April
if (date === 1) dhtml.push("April Fools' Day");
if (date === 15 && day !== 0 && day !== 6) dhtml.push("Income Tax Day (USA)");
if ((date === 16 || date === 17) && day === 1) dhtml.push("Income Tax Day (USA)");
if (date === 15) dhtml.push("Leonardo da Vinci born (1452)");
if (date === 23) dhtml.push("St Georges day");
},
function(){ // May
if (date === 1) dhtml.push("May Day");
if (day === 1 && date > 24) dhtml.push("Memorial Day");
},
function(){ // June
if (date === 21) dhtml.push("Summer Solstice");
if (day === 0 && date > 15 && date < 24) dhtml.push("Father's Day");
},
function(){ // July
if (date === 1) dhtml.push("Independence Day (Canada)");
if (date === 4) dhtml.push("Independence Day (USA)");
},
function(){ // August

},
function(){ // September
if (date === 16) dhtml.push("Independence Day (Mexico)");
if (day== 1 && date > 0 && date < 8) dhtml.push("Labor Day (USA)");
},
function(){ // October
if (date === 1) dhtml.push("4 weeks to Halloween");
if (date === 8) dhtml.push("It's 23 days to Halloween");
if (date === 9) dhtml.push("It's 22 days to Halloween");
if (day === 0 && date > 24 && date < 31) dhtml.push("GMT begins today");
if (day === 0 && date === 31) dhtml.push("GMT begins today<BR>");
if (date === 10) dhtml.push("It's 21 days to Halloween");
if (date === 11) dhtml.push("It's 20 days to Halloween");
if (date === 12) dhtml.push("It's 19 days to Halloween");
if (date === 13) dhtml.push("It's 18 days to Halloween");
if (date === 14) dhtml.push("It's 17 days to Halloween");
if (date === 15) dhtml.push("It's 16 days to Halloween");
if (date === 16) dhtml.push("It's 15 days to Halloween");
if (date === 17) dhtml.push("It's 14 days to Halloween");
if (date === 18) dhtml.push("It's 13 days to Halloween");
if (date === 19) dhtml.push("It's 12 days to Halloween");
if (date === 20) dhtml.push("It's 11 days to Halloween");
if (date === 21) dhtml.push("It's 10 days to Halloween");
if (date === 22) dhtml.push("It's 9 days to Halloween");
if (date === 23) dhtml.push("It's 8 days to Halloween");
if (date === 24) dhtml.push("It's 7 days to Halloween");
if (date === 25) dhtml.push("It's 6 days to Halloween");
if (date === 26) dhtml.push("It's 5 days to Halloween");
if (date === 27) dhtml.push("It's 4 days to Halloween");
if (date === 28) dhtml.push("It's 3 days to Halloween");
if (date === 29) dhtml.push("It's 2 days to Halloween");
if (date === 30) dhtml.push("1 day to go it's Halloween tomorrow");
if (date === 31) dhtml.push("It's Halloween");
},
function(){ // November
if (day === 0 && date < 8) dhtml.push("Daylight Saving Time Ends (most of USA)");
if (date === 1) dhtml.push("All Saints Day");
if (date === 2) dhtml.push("All Souls Day");
if (date === 5) dhtml.push("Guy Fawkes day");
if (date === 11) dhtml.push("Armistice Day");
if (date === 24) dhtml.push("It will Christmas Eve four weeks from today");
if (date === 25) dhtml.push("It will be Christmas Day four weeks from today");
if (date === 27) dhtml.push ("Christmas is coming!");
if (date === thanksdate) dhtml.push("Thanksgiving (USA)");
},
function(){ // December
if (date === 9) dhtml.push("Today is Human Rights Day");
if (date === 13) dhtml.push("It's 12 days to Christmas");
if (date === 14) dhtml.push("It's 11 days to Christmas");
if (date === 15) dhtml.push("It's 10 days to Christmas");
if (date === 16) dhtml.push("It's 9 days to Christmas");
if (date === 17) dhtml.push("It's 8 days to Christmas");
if (date === 18) dhtml.push("It's 7 days to Christmas");
if (date === 19) dhtml.push("It's 6 days to Christmas");
if (date === 20) dhtml.push("It's just 5 days to Christmas");
if (date === 21) dhtml.push("Winter Solstice the shortest day and 4 days to Christmas");
if (date === 22) dhtml.push("Christmas is nearly here, just 2 more days");
if (date === 23) dhtml.push("It's Christmas Eve tommorrow almost time to party!");
if (date === 24) dhtml.push("Christmas Eve a Merry Christmas from Wytoretro");
if (date === 25) dhtml.push("Christmas Day a Merry Christmas from Wytonsite");
if (date === 26) dhtml.push("Boxing Day a Merry Christmas from the Wytonsite");
if (date === 27) dhtml.push("Saturday");
if (date === 31) dhtml.push("Today is New Year's Eve Happy New Year");
}][month]();
document.getElementById('datecontainer2').innerHTML = dhtml.join('<br>');
if(linebreak){document.getElementById('datecontainer2').appendChild(document.createElement('br'));}
})();
</script>

I've also set it up, so that if there's more than one event, any additional events for a given day will have a linebreak first, as I think that's what you want with this particular feature. The other one (first one with all those long events), just adds a comma and a space before additional events, which seems right for it. In fact, you might want to consider removing Christmas, Easter, etc. from the first version of the script on the page there as those events will only be repeated in the second date feature.

Let me know about Advent - if you want more than 12 days of it, and, if so, when it should stop. One other thing, if Advent and its days are to be the last of two or more events if more than one occur on a given day, I can arrange that. Right now the Advent events will always come before others if there are more than one on a given day.

styxlawyer
12-08-2017, 05:25 PM
Advent in the Church calendar only consists of the four Sundays leading up to Christmas. They should be referred to as the "First Sunday In Advent", "Second Sunday..." etc.

"Advent Calendars" are a Victorian invention and comprise the 24 days from December 1st to Christmas Eve.

The "12 days of Christmas" are the 12 days of celebration between Christmas Day and Epiphany (Twelfth Night). See the following links:

http://www.christianitytoday.com/history/2008/august/real-twelve-days-of-christmas.html

Hope that helps.

leccie
12-08-2017, 05:40 PM
By way of explanation, the first version performs a different function. There is a header panel at the top of the page that tells what happened on any particular day and date in the 1960s. It changes every day, and there is information about events for every single day of the year that is why there is so much stuff. The second version is to call up and display holidays, and similar information at the bottom of the screen and does not show a message every single day of the year. A message will only display if the day is a holiday or similar event such as day light saving. By the way I did not include the date in the second version because it is already displayed at the top of the page in the header panel where the 1960s material is displayed. The message is all that is required. Advent should stop (last day to display Advent to be December 24th). In effect the Advent feature needs to start 4 Sundays before Christmas and the final display to appear on Christmas Eve. Christmas Eve being the last day before Christmas.

jscheuer1
12-08-2017, 06:04 PM
Advent in the Church calendar only consists of the four Sundays leading up to Christmas. They should be referred to as the "First Sunday In Advent", "Second Sunday..." etc.

"Advent Calendars" are a Victorian invention and comprise the 24 days from December 1st to Christmas Eve.

The "12 days of Christmas" are the 12 days of celebration between Christmas Day and Epiphany (Twelfth Night). See the following links:

Then that makes it easier, if a bit confusing. Replace:

if (month === admonth && date === addate) dhtml.push("Advent Sunday");
adnames = ['Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth'];
for(i = 0; i < adnames.length; ++i){
if (month === adcal.getMonth() && date === (addate = adcal.getDate())) dhtml.push("Today is the " + adnames[i] + " Day of Advent");
}

with:

if (month === admonth && date === addate) dhtml.push("Advent Sunday");
adnames = ['Second', 'Third', 'Fourth'];
for(i = 0; i < adnames.length; ++i){
if (month === 11 && date >= 25){break;}
}

And if you want to list the days of advent as Dec 1, Dec 2, and so on. But I'd do only one or the other since one is based upon Advent Sunday, and the other is based upon the tradition of advent calendars. If you try to represent both, it will likely look odd and/or be confusing. So, you could leave that part as it was before the looping, and add back your original days of advent based on Dec 1st.

jscheuer1
12-08-2017, 06:07 PM
By way of explanation, the first version performs a different function. There is a header panel at the top of the page that tells what happened on any particular day and date in the 1960s. It changes every day, and there is information about events for every single day of the year that is why there is so much stuff. The second version is to call up and display holidays, and similar information at the bottom of the screen and does not show a message every single day of the year. A message will only display if the day is a holiday or similar event such as day light saving. By the way I did not include the date in the second version because it is already displayed at the top of the page in the header panel where the 1960s material is displayed. The message is all that is required. Advent should stop (last day to display Advent to be December 24th). In effect the Advent feature needs to start 4 Sundays before Christmas and the final display to appear on Christmas Eve. Christmas Eve being the last day before Christmas.

Right, that's why I would recommend removing:

// Easter and Related
if (month === emonth && date === edate) dhtml.push("Easter Sunday (Western)");
if (month === gfmonth && date === gfdate) dhtml.push("Good Friday (Western)");
if (month === wmmonth && date === wmdate) dhtml.push("Whit Monday");
if (month === admonth && date === addate) dhtml.push("Advent Sunday");

from the first version of this script on the page.

leccie
12-08-2017, 06:39 PM
John, I am more than happy to be guided by your advice. Clearly you have a great deal of knowledge and expertise. By the way would you mind explaining the differences, and advantages of using dhtml.push instead of the document.write protocol. I find that very interesting.

jscheuer1
12-08-2017, 08:50 PM
First, there's no specific such thing as dhtml.push. In this particular code I created an array named dhtml, I just made up the name and was thinking it stood for dates HTML. The .push() is a method for adding to an array. Once everything that's been configured for a given date has been added to the array (usually only one thing, but for some dates it can be two or more things), I use the innerHTML property of the target element to populate it with the date html (stored in this code in an array called html, and the dates html from the dhtml array.

So really the difference is between using document.write and using the innerHTML property of a target element. Generally, if everything you're doing is happening as the page is loading, one can use either method. However, once code makes it out into the wild, people will often try to execute it after the page has loaded. If you do this with document.write it will obliterate everything that went before, the entire page, leaving only the new content. If you use injection to an element via its innerHTML property, only that one element is changed. Odd situations can arise with document.write where even if you think it's executing as the page is loading, some other code on the page might delay it, once that happens, your page is wiped out, even if you were using document.write "correctly". That's why it's been deprecated. It still works (within the limitations described), but it's strongly advised to get rid of it when updating code and to not use it in new code. I actually once used it to intentionally obliterate a page and replace it with other content without having to load a different page (that was for a quiz script, to load the results once the quiz was complete). But I doubt I would ever do that now because it breaks the back button, thereby making it possible for the user to lose content.

leccie
12-08-2017, 09:39 PM
Thanks for explaining that. No doubt you have deduced long since that I am not very conversant with the dynamics of script protocols. I do have a book (SAMS teach yourself) but despite having spent many hours pouring over its contents I have never really made much progress. That is why cut and paste scripts are so appealing. I am very grateful for your input. So, how do I incorperate the revised code into my page? The one thing that I have learned is that you have to be very careful because is so easy to screw everything up. I tend to back up all my code in a Word document so that if a major disaster happen I can recover it, and that has happened a few times I can tell you! I have certainly learned a lot from your observations on good practice.

styxlawyer
12-08-2017, 11:09 PM
.
.
.
I tend to back up all my code in a Word document so that if a major disaster happen I can recover it, and that has happened a few times I can tell you!
.
.

Word is probably not the best way to backup HTML pages as it can add all sorts of hidden undesirable stuff! What I do is just save a copy of the file adding the date and time of saving at the end of the filename in the form "yyyymmddHHMM" (eg "201712082306". That way you can quickly go back to a known working version created at a particular time on a particular day.

jscheuer1
12-08-2017, 11:23 PM
Well if you're just cutting and pasting, Word is probably OK. However, the best backups for html pages is just a plain copy of them, preferably of the same name in a different folder, or numbered backup copies in the same folder.

As for:

So, how do I incorperate the revised code into my page?

I thought I gave you a completely revised page. Didn't you get it? As for any revisions since then, If you don't know where which go, assuming you decide to use any of them, they're all optional - just talk it out here. I'm sure we can get it sorted.

jscheuer1
12-09-2017, 03:21 PM
Well, anyways, I've been messing with the code some more, hopefully making it easier to use. So I will update your page using the new code and attach it here when it's done. I think a stripped down version of the script without any but the listed content from each month is right for the first one. For the second, I think I see what to do there as well, we can tweak either one later if you want.

Also, for Advent, I' see that some Advent calendars follow the liturgical Advent, so there is at least the option of throwing out all mention of Advent in the December section, and using this code:

if(month > admonth - 1){
if (month === admonth && date === addate) dhtml.push("Advent Sunday");
else if((month < 11 && date > addate) || date < 25){
adnames = ['Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth', '13th',
'14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th'];
for(i = 0; i < adnames.length; ++i){
if (month === adcal.getMonth() && date === (addate = adcal.getDate())) dhtml.push(
(adcal.getDay()? '' : adnames[f(i / 6 - 1)] + " Sunday, ") + adnames[i] + " Day of Advent (Liturgical)"
);
}
}
}

That's what I'm including in the update anyway. It gives output like:

Seventh Day of Advent (Liturgical)

or on a Sunday during Advent:

Second Sunday, Eighth Day of Advent (Liturgical)

jscheuer1
12-09-2017, 05:44 PM
OK, here's the latest update for your page:

6239

Hopefully you can take it from here. But any questions, etc., just let me know.