Icontem

File: getHoliday-fr.html

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

Contents

Class file image Download
<html>

<head>
<title>DateObj.getFerie()</title>

<script language="javascript" type="text/javascript">
// Pour utilisateurs français:
Date.prototype.getFerie=function(v){var Y,y,a,b,c,D,d,e,f,g,M,m,p,v,s;var i=new Array(-45,-41,0,39,49);var s="cencarpaqascpen";var p=s.indexOf(v.substring(0,3).toLowerCase())/3;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);h=new Date(Y,2,g+i[p],0,0,0);d=h.getDate();D=(d<10)?'0'+d:d;m=h.getMonth()+1;M=(m<10)?'0'+m:m;return D+'/'+M+'/'+Y;};
</script>

<script language="javascript" type="text/javascript">
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Teste la validité d'une date au format français (JJ/MM/AAAA).
// Retourne "OK" ou un message d'erreur
// Vous pouvez intervertir les lignes A et B (en corrigeant les indices) pour un format tel que MM/JJ/AAAA
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 "Jour incorrect"; }  // A
		if((tab[1]*1)<1 || (tab[1]*1)>12) { return "Mois incorrect"; }  // B
		return "OK";
	}
	return "Format date incorrect";
}

function showHoliday() {

	var holiday, vacation, date, tab, j, m, a, thedate, msg;

	holiday = document.test.holiday.options[document.test.holiday.options.selectedIndex].value;
	vacation = document.test.holiday.options[document.test.holiday.options.selectedIndex].text;
	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  = vacation+' '+thedate.getFullYear()+' tombe le '+thedate.getFerie(holiday);
	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>Fêtes mobiles</h3>

<form name="test" method="post" action="javascript:showHoliday()" onsubmit="return verif()">
Saisissez une date quelconque (JJ/MM/AAAA) <input type="text" name="date" size="10"><br/>
Pour cette année, quelle fête mobile voulez-vous ?
<select name="holiday">
  <option value="Cendres">Cendres</option>
  <option value="Careme">Carême</option>
  <option value="Paques">Pâques</option>
  <option value="Ascension">Ascension</option>
  <option value="Pentecote">Pentecôte</option>
</select><br/>
<input type="submit" name="submit" value="Valider">
</form>

</body>

</html>