[ Mini Kiebo ]
Server: Windows NT DESKTOP-5B8S0D4 6.2 build 9200 (Windows 8 Professional Edition) i586
Path:
D:
/
xampp182
/
htdocs
/
simpeg
/
zapatec
/
zpcal
/
zpcal
/
jsdocs
/
[
Home
]
File: overview-summary-calendar-date-core.js.html
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"> <html> <head> <title> Zapatec Calendar Overview </title> <link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style"> <script> function asd() { parent.document.title="calendar-date-core.js Overview"; } </script> </head> <body bgcolor="white" onload="asd();"> <!-- ========== START OF NAVBAR ========== --> <a name="navbar_top"><!-- --></a> <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1"> <a name="navbar_top_firstrow"><!-- --></a> <table border="0" cellpadding="0" cellspacing="3"> <tr align="center" valign="top"> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td> <td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td> <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td> </tr> </table> </td> <td bgcolor="#EEEEFF" align="right" valign="top"> <em> <b>Zapatec Calendar</b></em> </td> </tr> <tr> <td bgcolor="white" class="NavBarCell2"><font size="-2"> PREV NEXT</font></td> <td bgcolor="white" class="NavBarCell2"><font size="-2"> <a href="index.html" target="_top"><b>FRAMES</b></a> <a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a> <script> <!-- if(window==top) { document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--> </script> <noscript> <a href="allclasses-noframe.html" target=""><b>All Classes</b></a> </noscript> </font></td> </tr> </table> <!-- =========== END OF NAVBAR =========== --> <hr> <center> <h2>calendar-date-core.js</h2> </center> <h4>Summary</h4> <p> No overview generated for 'calendar-date-core.js'<BR/><BR/> </p> <hr> <!-- ========== METHOD SUMMARY =========== --> <!-- ========== END METHOD SUMMARY =========== --> <pre class="sourceview"><span class="comment">/* $Id: calendar-date-core.js 6805 2007-03-30 12:36:39Z slip $ */</span> <span class="comment">/** * * Copyright (c) 2004-2006 by Zapatec, Inc. * http://www.zapatec.com * 1700 MLK Way, Berkeley, California, * 94709, U.S.A. * All rights reserved. */</span> <span class="comment">// BEGIN: DATE OBJECT PATCHES</span> <span class="comment">/** \defgroup DateExtras Augmenting the Date object with some utility functions * and variables. */</span> <span class="comment">//@{</span> Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; <span class="comment">/**< Number of days in each month */</span> Date.SECOND = 1000; <span class="comment">/**< One second has 1000 milliseconds. */</span> Date.MINUTE = 60 * Date.SECOND; <span class="comment">/**< One minute has 60 seconds. */</span> Date.HOUR = 60 * Date.MINUTE; <span class="comment">/**< One hour has 60 minutes. */</span> Date.DAY = 24 * Date.HOUR; <span class="comment">/**< One day has 24 hours. */</span> Date.WEEK = 7 * Date.DAY; <span class="comment">/**< One week has 7 days. */</span> <span class="comment">/** Returns the number of days in the month. The \em month parameter is * optional; if not passed, the current month of \b this Date object is * assumed. * * <span class="attrib">@param</span> month [int, optional] the month number, 0 for January. */</span> Date.<span class="reserved">prototype</span>.getMonthDays = <span class="reserved">function</span>(month) { var year = <span class="reserved">this</span>.getFullYear(); <span class="reserved">if</span> (typeof month == <span class="literal">"undefined"</span>) { month = <span class="reserved">this</span>.getMonth(); } <span class="reserved">if</span> (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) { <span class="reserved">return</span> 29; } <span class="reserved">else</span> { <span class="reserved">return</span> Date._MD[month]; } }; <span class="comment">/** Returns the number of the current day in the current year. */</span> Date.<span class="reserved">prototype</span>.getDayOfYear = <span class="reserved">function</span>() { var now = new Date(<span class="reserved">this</span>.getFullYear(), <span class="reserved">this</span>.getMonth(), <span class="reserved">this</span>.getDate(), 0, 0, 0); var then = new Date(<span class="reserved">this</span>.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; <span class="reserved">return</span> Math.round(time / Date.DAY); }; <span class="comment">/** Returns the number of the week in year, as defined in ISO 8601. */</span> Date.<span class="reserved">prototype</span>.getWeekNumber = <span class="reserved">function</span>() { var d = new Date(<span class="reserved">this</span>.getFullYear(), <span class="reserved">this</span>.getMonth(), <span class="reserved">this</span>.getDate(), 0, 0, 0); var DoW = d.getDay(); d.setDate(d.getDate() - (DoW + 6) % 7 + 3); <span class="comment">// Nearest Thu</span> var ms = d.valueOf(); <span class="comment">// GMT</span> d.setMonth(0); d.setDate(4); <span class="comment">// Thu in Week 1</span> <span class="reserved">return</span> Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; }; <span class="comment">/** Checks dates equality. Checks time too. */</span> Date.<span class="reserved">prototype</span>.equalsTo = <span class="reserved">function</span>(date) { <span class="reserved">return</span> ((<span class="reserved">this</span>.getFullYear() == date.getFullYear()) && (<span class="reserved">this</span>.getMonth() == date.getMonth()) && (<span class="reserved">this</span>.getDate() == date.getDate()) && (<span class="reserved">this</span>.getHours() == date.getHours()) && (<span class="reserved">this</span>.getMinutes() == date.getMinutes())); }; <span class="comment">/** Checks dates equality. Ignores time. */</span> Date.<span class="reserved">prototype</span>.dateEqualsTo = <span class="reserved">function</span>(date) { <span class="reserved">return</span> ((<span class="reserved">this</span>.getFullYear() == date.getFullYear()) && (<span class="reserved">this</span>.getMonth() == date.getMonth()) && (<span class="reserved">this</span>.getDate() == date.getDate())); }; <span class="comment">/** Set only the year, month, date parts (keep existing time) */</span> Date.<span class="reserved">prototype</span>.setDateOnly = <span class="reserved">function</span>(date) { var tmp = new Date(date); <span class="reserved">this</span>.setDate(1); <span class="reserved">this</span>.setFullYear(tmp.getFullYear()); <span class="reserved">this</span>.setMonth(tmp.getMonth()); <span class="reserved">this</span>.setDate(tmp.getDate()); }; <span class="comment">/** Prints the date in a string according to the given format. * * The format (\b str) may contain the following specialties: * * - %%a - Abbreviated weekday name * - %%A - Full weekday name * - %%b - Abbreviated month name * - %%B - Full month name * - %%C - Century number * - %%d - The day of the month (00 .. 31) * - %%e - The day of the month (0 .. 31) * - %%H - Hour (00 .. 23) * - %%I - Hour (01 .. 12) * - %%j - The day of the year (000 .. 366) * - %%k - Hour (0 .. 23) * - %%l - Hour (1 .. 12) * - %%m - Month (01 .. 12) * - %%M - Minute (00 .. 59) * - %%n - A newline character * - %%p - "PM" or "AM" * - %%P - "pm" or "am" * - %%S - Second (00 .. 59) * - %%s - Number of seconds since Epoch * - %%t - A tab character * - %%W - The week number (as per ISO 8601) * - %%u - The day of week (1 .. 7, 1 = Monday) * - %%w - The day of week (0 .. 6, 0 = Sunday) * - %%y - Year without the century (00 .. 99) * - %%Y - Year including the century (ex. 1979) * - %%% - A literal %% character * * They are almost the same as for the POSIX strftime function. * * <span class="attrib">@param</span> str [string] the format to print date in. */</span> Date.<span class="reserved">prototype</span>.print = <span class="reserved">function</span> (str) { var m = <span class="reserved">this</span>.getMonth(); var d = <span class="reserved">this</span>.getDate(); var y = <span class="reserved">this</span>.getFullYear(); var wn = <span class="reserved">this</span>.getWeekNumber(); var w = <span class="reserved">this</span>.getDay(); var s = {}; var hr = <span class="reserved">this</span>.getHours(); var pm = (hr >= 12); var ir = (pm) ? (hr - 12) : hr; var dy = <span class="reserved">this</span>.getDayOfYear(); <span class="reserved">if</span> (ir == 0) ir = 12; var min = <span class="reserved">this</span>.getMinutes(); var sec = <span class="reserved">this</span>.getSeconds(); s[<span class="literal">"%a"</span>] = Zapatec.Calendar.i18n(w, <span class="literal">"sdn"</span>); <span class="comment">// abbreviated weekday name [FIXME: I18N]</span> s[<span class="literal">"%A"</span>] = Zapatec.Calendar.i18n(w, <span class="literal">"dn"</span>); <span class="comment">// full weekday name</span> s[<span class="literal">"%b"</span>] = Zapatec.Calendar.i18n(m, <span class="literal">"smn"</span>); <span class="comment">// abbreviated month name [FIXME: I18N]</span> s[<span class="literal">"%B"</span>] = Zapatec.Calendar.i18n(m, <span class="literal">"mn"</span>); <span class="comment">// full month name</span> <span class="comment">// FIXME: %c : preferred date and time representation for the current locale</span> s[<span class="literal">"%C"</span>] = 1 + Math.floor(y / 100); <span class="comment">// the century number</span> s[<span class="literal">"%d"</span>] = (d < 10) ? (<span class="literal">"0"</span> + d) : d; <span class="comment">// the day of the month (range 01 to 31)</span> s[<span class="literal">"%e"</span>] = d; <span class="comment">// the day of the month (range 1 to 31)</span> <span class="comment">// FIXME: %D : american date style: %m/%d/%y</span> <span class="comment">// FIXME: %E, %F, %G, %g, %h (man strftime)</span> s[<span class="literal">"%H"</span>] = (hr < 10) ? (<span class="literal">"0"</span> + hr) : hr; <span class="comment">// hour, range 00 to 23 (24h format)</span> s[<span class="literal">"%I"</span>] = (ir < 10) ? (<span class="literal">"0"</span> + ir) : ir; <span class="comment">// hour, range 01 to 12 (12h format)</span> s[<span class="literal">"%j"</span>] = (dy < 100) ? ((dy < 10) ? (<span class="literal">"00"</span> + dy) : (<span class="literal">"0"</span> + dy)) : dy; <span class="comment">// day of the year (range 001 to 366)</span> s[<span class="literal">"%k"</span>] = hr ? hr : <span class="literal">"0"</span>; <span class="comment">// hour, range 0 to 23 (24h format)</span> s[<span class="literal">"%l"</span>] = ir; <span class="comment">// hour, range 1 to 12 (12h format)</span> s[<span class="literal">"%m"</span>] = (m < 9) ? (<span class="literal">"0"</span> + (1+m)) : (1+m); <span class="comment">// month, range 01 to 12</span> s[<span class="literal">"%M"</span>] = (min < 10) ? (<span class="literal">"0"</span> + min) : min; <span class="comment">// minute, range 00 to 59</span> s[<span class="literal">"%n"</span>] = <span class="literal">"\n"</span>; <span class="comment">// a newline character</span> s[<span class="literal">"%p"</span>] = pm ? <span class="literal">"PM"</span> : <span class="literal">"AM"</span>; s[<span class="literal">"%P"</span>] = pm ? <span class="literal">"pm"</span> : <span class="literal">"am"</span>; <span class="comment">// FIXME: %r : the time in am/pm notation %I:%M:%S %p</span> <span class="comment">// FIXME: %R : the time in 24-hour notation %H:%M</span> s[<span class="literal">"%s"</span>] = Math.floor(<span class="reserved">this</span>.getTime() / 1000); s[<span class="literal">"%S"</span>] = (sec < 10) ? (<span class="literal">"0"</span> + sec) : sec; <span class="comment">// seconds, range 00 to 59</span> s[<span class="literal">"%t"</span>] = <span class="literal">"\t"</span>; <span class="comment">// a tab character</span> <span class="comment">// FIXME: %T : the time in 24-hour notation (%H:%M:%S)</span> s[<span class="literal">"%U"</span>] = s[<span class="literal">"%W"</span>] = s[<span class="literal">"%V"</span>] = (wn < 10) ? (<span class="literal">"0"</span> + wn) : wn; s[<span class="literal">"%u"</span>] = (w == 0) ? 7 : w; <span class="comment">// the day of the week (range 1 to 7, 1 = MON)</span> s[<span class="literal">"%w"</span>] = w ? w : <span class="literal">"0"</span>; <span class="comment">// the day of the week (range 0 to 6, 0 = SUN)</span> <span class="comment">// FIXME: %x : preferred date representation for the current locale without the time</span> <span class="comment">// FIXME: %X : preferred time representation for the current locale without the date</span> s[<span class="literal">"%y"</span>] = <span class="literal">''</span> + y % 100; <span class="comment">// year without the century (range 00 to 99)</span> <span class="reserved">if</span> (s[<span class="literal">"%y"</span>] < 10) { s[<span class="literal">"%y"</span>] = <span class="literal">"0"</span> + s[<span class="literal">"%y"</span>]; } s[<span class="literal">"%Y"</span>] = y; <span class="comment">// year with the century</span> s[<span class="literal">"%%"</span>] = <span class="literal">"%"</span>; <span class="comment">// a literal '%' character</span> var re = /%./g; var a = str.match(re) || []; <span class="reserved">for</span> (var i = 0; i < a.length; i++) { var tmp = s[a[i]]; <span class="reserved">if</span> (tmp) { re = new RegExp(a[i], <span class="literal">'g'</span>); str = str.replace(re, tmp); } } <span class="reserved">return</span> str; }; <span class="comment">/** * Parses a date from a string in the specified format. * This function requires strict following of the string to * the format template, and any difference causes failure * to be returned. Also function refuses to parse formats * which containing number rules that have not fixed length * and are not separated from the next number rule by any * character string, as this requires complication of algorythm * and still sometimes is impossible to parse. * * <span class="attrib">@param</span> str [string] the date as a string * <span class="attrib">@param</span> format [string] the format to try to parse the date in * * <span class="attrib">@return</span> [Date] a date object containing the parsed date or \b null if for * some reason the date couldn't be parsed. */</span> Date.parseDate = <span class="reserved">function</span> (str, format) { var fmt = format, strPointer = 0, token = null, parseFunc = null, valueLength = null, valueRange = null, valueType = null, date = new Date(), values = {}; <span class="comment">//need to have a way to determine whether rule is number</span> var numberRules = [<span class="literal">"%d"</span>, <span class="literal">"%H"</span>, <span class="literal">"%I"</span>, <span class="literal">"%m"</span>, <span class="literal">"%M"</span>, <span class="literal">"%S"</span>, <span class="literal">"%s"</span>, <span class="literal">"%W"</span>, <span class="literal">"%u"</span>, <span class="literal">"%w"</span>, <span class="literal">"%y"</span>, <span class="literal">"%e"</span>, <span class="literal">"%k"</span>, <span class="literal">"%l"</span>, <span class="literal">"%s"</span>, <span class="literal">"%Y"</span>, <span class="literal">"%C"</span>]; <span class="reserved">function</span> isNumberRule(rule) { <span class="reserved">if</span> (Zapatec.Utils.arrIndexOf(numberRules, rule) != -1) { <span class="reserved">return</span> true; } <span class="reserved">return</span> false; } <span class="comment">//parses string value from translation table</span> <span class="reserved">function</span> parseString() { <span class="reserved">for</span>(var iString = valueRange[0]; iString < valueRange[1]; ++iString) { <span class="comment">//checking if there is translation</span> var value = Zapatec.Calendar.i18n(iString, valueType); <span class="reserved">if</span> (!value) { <span class="reserved">return</span> null; } <span class="comment">//comparing with our part of the string</span> <span class="reserved">if</span> (value == str.substr(strPointer, value.length)) { <span class="comment">//increasing string pointer</span> valueLength = value.length; <span class="reserved">return</span> iString; } } <span class="reserved">return</span> null; } <span class="comment">//parses the number from beginning of string</span> <span class="reserved">function</span> parseNumber() { var val = str.substr(strPointer, valueLength); <span class="reserved">if</span> (val.length != valueLength || /$\d+^/.test(val)) { <span class="reserved">return</span> null; } <span class="reserved">return</span> parseInt(val, 10); } <span class="comment">//parses AM PM rule</span> <span class="reserved">function</span> parseAMPM() { var result = (str.substr(strPointer, valueLength).toLowerCase() == Zapatec.Calendar.i18n(<span class="literal">"pm"</span>, <span class="literal">"ampm"</span>)) ? true : false; <span class="reserved">return</span> result || ((str.substr(strPointer, valueLength).toLowerCase() == Zapatec.Calendar.i18n(<span class="literal">"am"</span>, <span class="literal">"ampm"</span>)) ? false : null); } <span class="comment">//parses formating character</span> <span class="reserved">function</span> parseCharacter() { <span class="reserved">return</span> <span class="literal">""</span>; } <span class="comment">//parses the rule to the array</span> <span class="reserved">function</span> parseRule(rule) { <span class="reserved">return</span> (values[rule] = parseFunc()); } <span class="comment">//function determines if rule value was parsed</span> <span class="reserved">function</span> wasParsed(rule) { <span class="reserved">if</span> (typeof rule == <span class="literal">"undefined"</span> || rule === null) { <span class="reserved">return</span> false; } <span class="reserved">return</span> true; } <span class="comment">//gets first defined value or null if no</span> <span class="reserved">function</span> getValue() { <span class="reserved">for</span>(var i = 0; i < arguments.length; ++i) { <span class="reserved">if</span> (arguments[i] !== null && typeof arguments[i] != <span class="literal">"undefined"</span> && !isNaN(arguments[i])) { <span class="reserved">return</span> arguments[i]; } } <span class="reserved">return</span> null; } <span class="reserved">if</span> (typeof fmt != <span class="literal">"string"</span> || typeof str != <span class="literal">"string"</span> || str == <span class="literal">""</span> || fmt == <span class="literal">""</span>) { <span class="reserved">return</span> null; } <span class="comment">//cycle breaks format into tokens and checks or parses them</span> <span class="reserved">while</span>(fmt) { <span class="comment">//this is the default value type</span> parseFunc = parseNumber; <span class="comment">//taking char token(that doesn't hold any information)</span> valueLength = fmt.indexOf(<span class="literal">"%"</span>); valueLength = (valueLength == -1) ? fmt.length : valueLength; token = fmt.slice(0, valueLength); <span class="comment">//checking if we have same token in parsed string</span> <span class="reserved">if</span> (token != str.substr(strPointer, valueLength)) { <span class="reserved">return</span> null; } <span class="comment">//skiping it</span> strPointer += valueLength; fmt = fmt.slice(valueLength); <span class="reserved">if</span> (fmt == <span class="literal">""</span>) { break; } <span class="comment">//taking formating rule</span> token = fmt.slice(0, 2); <span class="comment">//this is the default length of value, as it is very often one for rules</span> valueLength = 2; switch (token) { case <span class="literal">"%A"</span> : case <span class="literal">"%a"</span> : { valueType = (token == <span class="literal">"%A"</span>) ? <span class="literal">"dn"</span> : <span class="literal">"sdn"</span>; valueRange = [0, 7]; parseFunc = parseString; break; } case <span class="literal">"%B"</span> : case <span class="literal">"%b"</span> : { valueType = (token == <span class="literal">"%B"</span>) ? <span class="literal">"mn"</span> : <span class="literal">"smn"</span>; valueRange = [0, 12]; parseFunc = parseString; break; } case <span class="literal">"%p"</span> : case <span class="literal">"%P"</span> : { parseFunc = parseAMPM; break; } case <span class="literal">"%Y"</span> : { valueLength = 4; <span class="reserved">if</span> (isNumberRule(fmt.substr(2, 2))) { <span class="reserved">return</span> null; } <span class="reserved">while</span>(isNaN(parseInt(str.charAt(strPointer + valueLength - 1))) && valueLength > 0) { --valueLength; } <span class="reserved">if</span> (valueLength == 0) {break;} break; } case <span class="literal">"%C"</span> : case <span class="literal">"%s"</span> : { valueLength = 1; <span class="reserved">if</span> (isNumberRule(fmt.substr(2, 2))) { <span class="reserved">return</span> null; } <span class="reserved">while</span>(!isNaN(parseInt(str.charAt(strPointer + valueLength)))) { ++valueLength; } break; } case <span class="literal">"%k"</span> : case <span class="literal">"%l"</span> : case <span class="literal">"%e"</span> : { valueLength = 1; <span class="reserved">if</span> (isNumberRule(fmt.substr(2, 2))) { <span class="reserved">return</span> null; } <span class="reserved">if</span> (!isNaN(parseInt(str.charAt(strPointer + 1)))) { ++valueLength; } break; } case <span class="literal">"%j"</span> : valueLength = 3; break; case <span class="literal">"%u"</span> : case <span class="literal">"%w"</span> : valueLength = 1; case <span class="literal">"%y"</span> : case <span class="literal">"%m"</span> : case <span class="literal">"%d"</span> : case <span class="literal">"%W"</span> : case <span class="literal">"%H"</span> : case <span class="literal">"%I"</span> : case <span class="literal">"%M"</span> : case <span class="literal">"%S"</span> : { break; } } <span class="reserved">if</span> (parseRule(token) === null) { <span class="reserved">return</span> null; } <span class="comment">//increasing pointer</span> strPointer += valueLength; <span class="comment">//skipint it</span> fmt = fmt.slice(2); } <span class="reserved">if</span> (wasParsed(values[<span class="literal">"%s"</span>])) { date.setTime(values[<span class="literal">"%s"</span>] * 1000); } <span class="reserved">else</span> { var year = getValue(values[<span class="literal">"%Y"</span>], values[<span class="literal">"%y"</span>] + --values[<span class="literal">"%C"</span>] * 100, values[<span class="literal">"%y"</span>] + (date.getFullYear() - date.getFullYear() % 100), values[<span class="literal">"%C"</span>] * 100 + date.getFullYear() % 100); var month = getValue(values[<span class="literal">"%m"</span>] - 1, values[<span class="literal">"%b"</span>], values[<span class="literal">"%B"</span>]); var day = getValue(values[<span class="literal">"%d"</span>] || values[<span class="literal">"%e"</span>]); <span class="reserved">if</span> (day === null || month === null) { var dayOfWeek = getValue(values[<span class="literal">"%a"</span>], values[<span class="literal">"%A"</span>], values[<span class="literal">"%u"</span>] == 7 ? 0 : values[<span class="literal">"%u"</span>], values[<span class="literal">"%w"</span>]); } var hour = getValue(values[<span class="literal">"%H"</span>], values[<span class="literal">"%k"</span>]); <span class="reserved">if</span> (hour === null && (wasParsed(values[<span class="literal">"%p"</span>]) || wasParsed(values[<span class="literal">"%P"</span>]))) { var pm = getValue(values[<span class="literal">"%p"</span>], values[<span class="literal">"%P"</span>]); hour = getValue(values[<span class="literal">"%I"</span>], values[<span class="literal">"%l"</span>]); hour = pm ? ((hour == 12) ? 12 : (hour + 12)) : ((hour == 12) ? (0) : hour); } <span class="reserved">if</span> (year || year === 0) { date.setFullYear(year); } <span class="reserved">if</span> (month || month === 0) { date.setMonth(month); } <span class="reserved">if</span> (day || day === 0) { date.setDate(day); } <span class="reserved">if</span> (wasParsed(values[<span class="literal">"%j"</span>])) { date.setMonth(0); date.setDate(1); date.setDate(values[<span class="literal">"%j"</span>]); } <span class="reserved">if</span> (wasParsed(dayOfWeek)) { date.setDate(date.getDate() + (dayOfWeek - date.getDay())); } <span class="reserved">if</span> (wasParsed(values[<span class="literal">"%W"</span>])) { var weekNumber = date.getWeekNumber(); <span class="reserved">if</span> (weekNumber != values[<span class="literal">"%W"</span>]) { date.setDate(date.getDate() + (values[<span class="literal">"%W"</span>] - weekNumber) * 7); } } <span class="reserved">if</span> (hour !== null) { date.setHours(hour); } <span class="reserved">if</span> (wasParsed(values[<span class="literal">"%M"</span>])) { date.setMinutes(values[<span class="literal">"%M"</span>]); } <span class="reserved">if</span> (wasParsed(values[<span class="literal">"%S"</span>])) { date.setSeconds(values[<span class="literal">"%S"</span>]); } } <span class="comment">//printing date in the same format and checking if we'll get the same string</span> <span class="reserved">if</span> (date.print(format) != str) { <span class="comment">//if not returning error</span> <span class="reserved">return</span> null; } <span class="comment">//or returning parsed date</span> <span class="reserved">return</span> date; }; Date.<span class="reserved">prototype</span>.__msh_oldSetFullYear = Date.<span class="reserved">prototype</span>.setFullYear; <span class="comment">/**< save a reference to the original setFullYear function */</span> <span class="comment">/** * This function replaces the original Date.setFullYear() with a "safer" * function which makes sure that the month or date aren't modified (unless in * the exceptional case where the date is February 29 but the new year doesn't * contain it). * * <span class="attrib">@param</span> y [int] the new year to move this date to */</span> Date.<span class="reserved">prototype</span>.setFullYear = <span class="reserved">function</span>(y) { var d = new Date(<span class="reserved">this</span>); d.__msh_oldSetFullYear(y); <span class="reserved">if</span> (d.getMonth() != <span class="reserved">this</span>.getMonth()) <span class="reserved">this</span>.setDate(28); <span class="reserved">this</span>.__msh_oldSetFullYear(y); }; <span class="comment">/** * This function compares only years, months and days of two date objects. * * <span class="attrib">@return</span> [int] -1 if date1>date2, 1 if date2>date1 or 0 if they are equal * * <span class="attrib">@param</span> date1 [Date] first date to compare * <span class="attrib">@param</span> date1 [Date] second date to compare */</span> Date.<span class="reserved">prototype</span>.compareDatesOnly = <span class="reserved">function</span> (date1,date2) { var year1 = date1.getYear(); var year2 = date2.getYear(); var month1 = date1.getMonth(); var month2 = date2.getMonth(); var day1 = date1.getDate(); var day2 = date2.getDate(); <span class="reserved">if</span> (year1 > year2) { <span class="reserved">return</span> -1; } <span class="reserved">if</span> (year2 > year1) { <span class="reserved">return</span> 1; } <span class="comment">//years are equal </span> <span class="reserved">if</span> (month1 > month2) { <span class="reserved">return</span> -1; } <span class="reserved">if</span> (month2 > month1) { <span class="reserved">return</span> 1; } <span class="comment">//years and months are equal </span> <span class="reserved">if</span> (day1 > day2) { <span class="reserved">return</span> -1; } <span class="reserved">if</span> (day2 > day1) { <span class="reserved">return</span> 1; } <span class="comment">//days are equal </span> <span class="reserved">return</span> 0; } <span class="comment">//@}</span> <span class="comment">// END: DATE OBJECT PATCHES</span> </pre> <hr> <!-- ========== START OF NAVBAR ========== --> <a name="navbar_top"><!-- --></a> <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1"> <a name="navbar_top_firstrow"><!-- --></a> <table border="0" cellpadding="0" cellspacing="3"> <tr align="center" valign="top"> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a> </td> <td bgcolor="#FFFFFF" class="NavBarCell1Rev"> <font class="NavBarFont1Rev"><b>File</b></font> </td> <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a> </td> <td bgcolor="#EEEEFF" class="NavBarCell1"> <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a> </td> </tr> </table> </td> <td bgcolor="#EEEEFF" align="right" valign="top"><em> <b>Zapatec Calendar</b></em> </td> </tr> <tr> <td bgcolor="white" class="NavBarCell2"><font size="-2"> PREV NEXT</font></td> <td bgcolor="white" class="NavBarCell2"><font size="-2"> <a href="index.html" target="_top"><b>FRAMES</b></a> <a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a> <script> <!-- if(window==top) { document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--> </script> <noscript> <a href="allclasses-noframe.html" target=""><b>All Classes</b></a> </noscript> </font></td> </tr> </table> <!-- =========== END OF NAVBAR =========== --> <hr> <font size="-1"> </font> <div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Aug 16 12:18:51 2007</div> </body> </html>