File: getEaster.html

Recommend this page to a friend!
  Classes of Pierre FAUQUE   JavaScript Holiday Dates   getEaster.html   Download  
File: getEaster.html
Role: Example script
Content type: text/plain
Description: Example of use (getEaster)
Class: JavaScript Holiday Dates
Calculator for the dates of different holidays
Author: By
Last change:
Date: 9 years ago
Size: 2,545 bytes
 

Contents

Class file image Download
<html> <head> <title>DateObj.getEaster()</title> <script language="javascript" type="text/javascript"> // For French users : getPaques() Date.prototype.getPaques=function(){var Y,y,a,b,c,D,d,e,f,g,M,m,p;Y=''+this.getFullYear();y=Y.substr(2,2);a=Y%19;b=Y%4;c=Y%7;e=((19*a)+24)%30;f=((2*b)+(4*c)+(6*e)+5)%7;g=(22+e+f);p=new Date(Y,2,g,0,0,0);d=p.getDate();D=(d<10)?'0'+d:d;m=p.getMonth()+1;M=(m<10)?'0'+m:m;return D+'/'+M+'/'+Y;}; // For English users: getEaster() Date.prototype.getEaster=function(){var Y,y,a,b,c,D,d,e,f,g,M,m,p;Y=''+this.getFullYear();y=Y.substr(2,2);a=Y%19;b=Y%4;c=Y%7;e=((19*a)+24)%30;f=((2*b)+(4*c)+(6*e)+5)%7;g=(22+e+f);p=new Date(Y,2,g,0,0,0);d=p.getDate();D=(d<10)?'0'+d:d;m=p.getMonth()+1;M=(m<10)?'0'+m:m;return M+'/'+D+'/'+Y;}; </script> <script language="javascript" type="text/javascript"> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Test the validity of a French date (DD/MM/YYYY). // Return "OK" or an error message // You can interchange the lines A and B (with indices correction) for a format such as MM/DD/YYYY function isValidDate(date) { var date, tab, reg = new RegExp("^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}$","g"); if(reg.test(date)) { tab=date.split('/'); if((tab[0]*1)<1 || (tab[0]*1)>31) { return "Incorrect day"; } // A if((tab[1]*1)<1 || (tab[1]*1)>12) { return "Incorrect month"; } // B return "OK"; } return "Incorrect format date"; } function showEaster() { var date, tab, j, m, a, thedate, msg; date = document.test.date.value; tab = date.split('/'); j=tab[0]*1; m=tab[1]-1; a=tab[2]*1; thedate = new Date(a, m, j); msg = 'En '+thedate.getFullYear()+' P‚ques tombe le '+thedate.getPaques(); msg += '\n' msg += 'In '+thedate.getFullYear()+' Easter arrives on '+thedate.getEaster(); alert(msg); } function verif() { var thedate, msg; // get the values of the form thedate = document.test.date.value; if(!thedate) { alert('Date is missing'); document.test.date.focus(); return false; } msg = isValidDate(thedate); if(msg != "OK") { alert("Date :\n"+msg); document.test.date.focus(); return false; } return true; } </script> </head> <body> <h3>P&acirc;ques / Easter</h3> <form name="test" method="post" action="javascript:showEaster()" onsubmit="return verif()"> Write a date (DD/MM/YYYY) <input type="text" name="date" size="10"><input type="submit" name="submit" value="Validate"> </form> </body> </html>