PageSourceSearch

https://www.clubepson.com.au/js/DateCheck.js

js clubepson.com.au collected 2026-09-26 05:20:39 UTC 8,069 bytes, 257 lines download raw bytes

1//------------------------------------------------------------------------------------
2// function: isProperDate
3//           Function to tell whether the given date is valid or not
4//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
5//           or mm-dd-yyyy or mm-dd-yy
6//------------------------------------------------------------------------------------
7function isProperDate(argDate) {
8	var tmpDay = getDay(argDate)
9	var tmpMon = getMonth(argDate)
10	var tmpYear = getYear(argDate)
11
12	return isProperDay(tmpDay, tmpMon, tmpYear) && isProperMonth(tmpMon) && isProperYear(tmpYear)
13}
14
15//------------------------------------------------------------------------------------
16// function: isWhiteSpace
17//           Function to check whether the given argument consists of charactes other
18//           than a space and \t
19//------------------------------------------------------------------------------------
20function isWhiteSpace(argWhiteSpace) {
21	argWs = argWhiteSpace.toString()
22	
23	for (var intI=0; intI < argWs.length; intI++)
24		if (argWs.charAt(intI) != ' ' && argWs.charAt(intI) != '\t')
25			return false
26	
27	return true
28}
29
30//------------------------------------------------------------------------------------
31// function: isLeapYear
32//           Function to tell, whether the given year is leap year or not
33//------------------------------------------------------------------------------------
34function isLeapYear(argYear) {
35	return ((argYear % 4 == 0) && (argYear % 100 != 0)) || (argYear % 400 == 0) 
36}
37
38//------------------------------------------------------------------------------------
39// function: daysInMonth
40//           Function to return the maximum number of days in a given month of a
41//           given year
42//------------------------------------------------------------------------------------
43function daysInMonth(argMonth, argYear) {
44	switch (Number(argMonth)) {
45		case 1:		// Jan
46		case 3:		// Mar
47		case 5:		// May
48		case 7:		// Jul
49		case 8:		// Aug
50		case 10:		// Oct
51		case 12:		// Dec
52			return 31;
53			break;
54		
55		case 4:		// Apr
56		case 6:		// Jun
57		case 9:		// Sep
58		case 11:		// Nov
59			return 30;
60			break;
61		
62		case 2:		// Feb
63			if (isLeapYear(argYear))
64				return 29
65			else
66				return 28
67			break;
68		
69		default:
70			return 0;
71	}
72}
73
74//------------------------------------------------------------------------------------
75// function: getDateSeparator
76//           Function to return the date separator
77//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
78//           or mm-dd-yyyy or mm-dd-yy
79//------------------------------------------------------------------------------------
80function getDateSeparator(argDate) {
81	// Are there invalid separators?
82	if ((argDate.indexOf('-') > 0) && (argDate.indexOf('/') > 0))
83		return ' '
84
85	if (argDate.indexOf('-') > 0)
86		return '-'
87	else
88		if (argDate.indexOf('/') > 0)
89			return '/'
90		else
91			return ' '
92}
93
94//------------------------------------------------------------------------------------
95// function: getYear
96//           Function to return the year part of the given date.
97//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
98//           or mm-dd-yyyy or mm-dd-yy
99//------------------------------------------------------------------------------------
100function getYear(argDate) {
101	var dateSep = getDateSeparator(argDate)
102	
103	if (dateSep == ' ')
104		return 0
105
106	if(argDate.split(dateSep).length == 3)
107		return argDate.split(dateSep)[2]
108	else
109		return 0
110}
111
112//------------------------------------------------------------------------------------
113// function: getMonth
114//           Function to return the month part of the given date.
115//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
116//           or mm-dd-yyyy or mm-dd-yy
117//------------------------------------------------------------------------------------
118function getMonth(argDate) {
119	var dateSep = getDateSeparator(argDate)
120	
121	if (dateSep == ' ')
122		return 0
123
124	if(argDate.split(dateSep).length == 3)
125		return argDate.split(dateSep)[1]
126	else
127		return 0
128}
129
130//------------------------------------------------------------------------------------
131// function: getDay
132//           Function to return the day part of the given date.
133//           This function expects date in the format of mm/dd/yyyy or mm/dd/yy
134//           or mm-dd-yyyy or mm-dd-yy
135//------------------------------------------------------------------------------------
136function getDay(argDate) {
137	var dateSep = getDateSeparator(argDate)
138	
139	if (dateSep == ' ')
140		return 0
141
142	if(argDate.split(dateSep).length == 3)
143		return argDate.split(dateSep)[0]
144	else
145		return 0
146}
147
148//------------------------------------------------------------------------------------
149// function: isProperDay
150//           Function to tell whether the given day of the given month is valid
151//------------------------------------------------------------------------------------
152function isProperDay(argDay, argMonth, argYear) {
153	if ((isWhiteSpace(argDay)) || (argDay == 0))
154		return false
155
156	if ((argDay > 0) && (argDay < daysInMonth(argMonth, argYear) + 1))
157		return true
158	else 
159		return false
160}
161
162//------------------------------------------------------------------------------------
163// function: isProperMonth
164//           Function to tell whether the given month is a valid one
165//------------------------------------------------------------------------------------
166function isProperMonth(argMonth) {
167	if ((isWhiteSpace(argMonth)) || (argMonth == 0))
168		return false
169	
170	if ((argMonth > 0) && (argMonth < 13))
171		return true
172	else
173		return false
174}
175
176//------------------------------------------------------------------------------------
177// function: isProperYear
178//           Function to tell whether the given Year is a valid one
179//------------------------------------------------------------------------------------
180function isProperYear(argYear) {
181	if ((isWhiteSpace(argYear)) || (argYear.toString().length > 4) || (argYear.toString().length == 3)) 
182		return false
183	if (argYear.toString().length < 4)
184		return false
185	switch (argYear.toString().length) {
186		case 1:
187			if (argYear >=0 && argYear < 10)
188				return true
189			else
190				return false
191			
192		case 2:
193			if (argYear >=0 && argYear < 100)
194				return true
195			else
196				return false
197			
198		case 4:
199			if (((argYear >=1900) || (argYear >=2000)) && ((argYear < 3000) || (argYear < 2000)))
200				return true
201			else
202				return false
203		
204		default:
205			return false
206	}
207}
208function isDateEmpty(s)
209{   return ((s == null) || (s.length == 0))
210}
211
212function warnInvalidDate(theField)
213{   theField.focus();
214    theField.select();
215    alert('Please Enter a valid Date');
216    return false;
217}
218
219function checkDate(theField, emptyOK)
220{   if (checkDate.arguments.length == 1) emptyOK = false;
221    if ((emptyOK == true) && (isDateEmpty(theField.value))) return true;
222    else if (!isProperDate(theField.value)) 
223       return warnInvalidDate(theField);
224    else return true;
225}
226function checkDate1(theField, emptyOK, msg)
227{   if (checkDate1.arguments.length == 1) emptyOK = false;
228    if ((emptyOK == true) && (isDateEmpty(theField.value))) return true;
229    else if (!isProperDate(theField.value)) 
230       return warnInvalidDate1(theField, msg);
231    else return true;
232}
233
234function warnInvalidDate1(theField, msg)
235{   theField.focus();
236    theField.select();
237    alert(msg);
238    return false;
239}
240
241function isForwardDated(argDate) {
242    var theDay = getDay(argDate);
243    var theMonth = getMonth(argDate);
244    var theYear = getYear(argDate);
245    //Forward dating//
246    if (theDay > curDay && (theMonth == curMonth && theYear == curYear)) {
247        return true;
248    }
249    if (theYear > curYear) {
250        return true;
251    }
252    if (theMonth > curMonth && theYear == curYear) {
253        return true;
254    }
255
256    return false;
257}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.