Holiday Calculator Function - JavaScript
(A free script from MRE Software)

 

     I needed a JavaScript function that would tell me whether the stock market was open or closed for a holiday so a page could decide whether to run a stock ticker or financial news ticker.  I wound up piecing together two nice code snippets and adding some code of my own to create a function.  This was originally based on a function to return Federal Holidays.  I added the Easter (Good Friday) algorithm and the block which moves some holidays to Friday-before and Monday-after if the holiday occurs on the weekend.

     I did NOT write 90% of this code so I certainly don't claim credit for doing much more than assembling it.  The two main functions were both found as snippets on coding websites and neither listed an original author.  That said, feel free to use, modify, and distribute this as you wish.  Note that I have commented out a few Federal holidays that are not stock market holidays.  The user can easily re-enable these and modify, delete, or add new ones.

Call this function by passing a valid date to it.  It returns the holiday name if the date is a holiday or false if not.
When you loaded the page this function was called and returned:


To download this script as a file

USE AT YOUR OWN RISK!




 
If you find this code of value, donate a little to the cause.  Think of the time you just saved!
USE AT YOUR OWN RISK!

Questions / Comments?  Email me.

MRE Logo