Below you can find the text of the snippet you want to read, and the list of the other snippets by this author if available. What are snippets?
Snippets are texts you edited that either you or other Full Poster members may reuse elsewhere on Full Poster, for instance inside blogs, as if they were quotations. Publishing a snippet implicitly means you accept it will be available to other members too for inclusion. If your snippets are included in the texts of other members, it will be printed a link that credits you as the author of the included snippet. Snippets are very useful in case of long quotes, exemplary descriptions or codes that you plan to use often, because they spare you the need to type their texts again, and they increase your visibility via the products of other members. If a member has banned you from his/her friends you will not be able to include his/her snippets as long as the ban is active. To Insert a snippet you must know its unique Identification Number, and then use the following syntax: either a white space or a new line, then an exclamation mark immediately followed by the identification number of the snippet to import, and then again either a white space or a new line: !1234567 You can't insert snippets within other snippets. See the list of the snippets by all authors.
INPUTS: first argument a date object representing the date to check (if passed as boolean false, defaults to the current date).
Second argument, a reference date object which poses as the date before which and after which the allowed time range has to span (if passed as boolean false, defaults to the current date).
Third argument a number representing the amount of time of the future edge of the allowed range time.
Fourth argument an unsigned (that is, with no minus - sign before it, unless as documented later on you want to set a time range all placed within the future) number representing the amount of time of the past edge of the allowed range time.
Last argument a number (defaults to zero) indicating the time unit (days? hours? months?) that the previous two arguments represent, and it allows the following numerical values:
0=days
1=months
2=years
3=hours
4=minutes
5=seconds
RETURNS: boolean false if the date to test is out of the given range, or boolean true otherwise.
Caveats: javascript months start counting from zero, so January=0, February=1 ... December=11
The constructor of the javascript object Date already takes care of calculating the right year month and day given any time addition or subtraction. It is much safer to rely on this capacity of the constructor, than on manually setting time additions or subtractions via further calls to methods such as (for instance) setDate(), setMonth(), etc.
Whoever envisions using the methods instead than the constructor of the Date object in order to add or to subtract time units, may incur sooner or later into the notion that the chosen method typecasts exceeding time units by looping recursively through the method's own time unit, never involving any other time unit.
Thence, subtracting (for instance) days via setDate() rather than via the constructor new Date() may shift the day of the given amount of days indeed, but may never affect months and years; thus, from say January 1 2000 you may subtract 1000 days only to find yourself still in January 2000, because the method keeps subtracting days over and over again, but always within the same month, recursively.
Example of such wrong code:
If you want to place a time range in the future, pass the argument rangeMinus as a negative number: it will denote the time span (say: days) in the future from which the range starts. Then pass rangePlus as a number always positiveyet bigger than the passed rangeMinus: that will set the amount of time units (say: days) in the future that represent where the range ends.
If you plan on setting ranges in the future, it is your responsibility to be sure that these conditions are met: rangeMinus passed as negative, rangePlus as positive and higher than rangeMinus.
Example of correct use:
<script>//include your setDateRange function here, then:var referenceDate=new Date(2011, 0/*=January*/, 1, 0, 0, 0);
//var dateToTestExample=new Date(2010, 11/*=December*/, 25, 0, 0, 0);/*from 25 to reference:
dec 26 one day,
dec 27 two days,
dec 28 three days,
dec 29 four days,
dec 30 five days,
dec 31 six days,
jan 1 seven days
condition of range within 7 days more or less: TRUE
*///var check=setDateRange(dateToTestExample, referenceDate, 7, 7, 0);
alert(check);
//another test:var referenceDate=new Date(2011, 4, 5, 7/*hours*/, 30/*minutes*/, 0);
//var dateToTestExample=new Date(2011, 4, 5, 8/*hours*/, 0/*minutes: make this 1,and will returnfalse*/, 0);
//var check=setDateRange(dateToTestExample, referenceDate, 30, 30, 4/*MINUTES*/);
alert(check);
/*another test: a range in the future: pass rangeMinus as negative, rangePlus as positive AND higher of the desired amount of days*/var referenceDate=new Date(2011, 1, 12, 0, 0, 0);
//var dateToTestExample=new Date(2011, 1, 20/*set this to 19 or 27 and shall returnfalse*/, 0, 0, 0);
//var check=setDateRange(dateToTestExample,false, 14/*7+7, placing the ending edge*/,-7/*7 to get a week from now, placing the starting edge*/, 0);/*Checked date must be in the future: 7 days from reference date at least, 7 more days from thence at most*/
alert(check);
</script>