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:

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):

</head>
<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.

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.

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?

</head>
<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.

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:

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:

</head>
<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.

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:

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):

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

Hi John I live in the UK. O.K. to answer some of you questions. Advent as far as I am aware always starts on a Sunday, and there are 4 Sundays in Advent, so depending on what day Christmas day falls the first Sunday of Advent could occur in either November or December. Because of the influence of Advent calenders I always assumed that Advent started on the first day of December and that it was a fixed date, I have since discovered that this is not so. The start of Advent is in fact a moveable event and is 4 Sundays. I am not really concerned about when it ends only with being able to set when it starts. I would guess that Advent finishes on the fourth Sunday. British daylight saving begins on the last Sunday of March and ends on the last Sunday of October. I would also like to include Shrove Tuesday (pancake day) which is a pretty big deal over here. Shrove Tuesday is seven weeks before Easter Sunday which falls on the last Tuesday in February I think. Any how it is a moveable date that is tied in to when Easter Sunday occurs. I think that it signifies the beginning of Lent but I am not to sure about that. None of this is essential, but I think that it adds a nice touch to the opening page.
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

In that case you may want to put things back the way they were with the beginning of Daylight Saving Time, except label it as UK instead of as US or whatever (think you had it as North America in what you sent me, I changed it to US). As long as Shrove Tuesday works off of Easter, we can put it in the Easter and Related section, I'll have that in a few minutes. I'm still not clear about Advent. You could have it so that the first day of Advent gets mentioned as Advent Sunday (we already have that), and we could each subsequent day of Advent, up to 12? gets mentioned as Second Day of Advent, Third Day of Advent, and so on instead of how you have it now, which you say was assuming Dec 1st as the First Day. That won't take long to do, but if you want that, I need to know how many Days of Advent to go up to, 12? More?

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:

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.

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:

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:

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.

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: