📄 date.js
字号:
// In any case, the parseInt is rendered unnecessary by the 'isA.Number' check below. month = results[monthIndex +1] -1; day = results[dayIndex+1]; year = results[yearIndex +1]; // Note - results[4] is the whole time string (if present) // Zero out any time fields that are not present - this may happen if // - time has invalid format (could check by examining results[4] too) // - time not included in dateString (could check by examining results[4] too) // - time has no seconds (legal - just zero out the seconds) hour = results[5] || 0; minute = results[6] || 0; second = results[7] || 0; //>Safari12 } //<Safari12 // If they all are numbers, this was a valid date string // NOTE: If year - month - day gives a number then they // are all numbers, or strings that implicitly convert to numbers. // We could also use this syntax: // if(parseInt(year) == year && parseInt(month) == month ...) // but this is slower in both Moz and IE if (isc.isA.Number(year - month - day - hour - minute - second)) return ([year,month,day,hour,minute,second]); else return null}, //> @type DateDisplayFormat// Valid display formats for dates. These strings are the names of formatters which can be // passed to <code>Date.setNormalDisplayFormat()</code> or <code>Date.setShortDisplayFormat()</code>// and will be subsequently used as default long or short formatters for date objects by// SmartClient components.<br>// Default set of valid display formats is as follows:<br><br>//// @value toString // Default native browser 'toString()' implementation. May vary by browser.<br>// <i>Example</i>: <code>Fri Nov 04 2005 11:03:00 GMT-0800 (Pacific Standard Time)</code>// @value toLocaleString// Default native browser 'toLocaleString()' implementation. May vary by browser.// <i>Example</i>: <code>Friday, November 04, 2005 11:03:00 AM</code>// @value toUSShortDate Short date in format MM/DD/YYYY.<br>// <i>Example</i>: <code>11/4/2005</code>// @value toUSShortDateTime Short date with time in format MM/DD/YYYY HH:MM<br>// <i>Example</i>: <code>11/4/2005 11:03</code>// @value toEuropeanShortDate Short date in format DD/MM/YYYY.<br>// <i>Example</i>: <code>4/11/2005</code>// @value toEuropeanShortDateTime Short date with time in format DD/MM/YYYY HH:MM<br>// <i>Example</i>: <code>4/11/2005 11:03</code>// @value toJapanShortDate Short date in format YYYY/MM/DD.<br>// <i>Example</i>: <code>2005/11/4</code>// @value toJapanShortDateTime Short date with time in format YYYY/MM/DD HH:MM<br>// <i>Example</i>: <code>2005/11/4 11:03</code>// @value toSerializeableDate Date in the format YYYY-MM-DD HH:MM:SS<br>// <i>Example</i>: <code>2005-11-04 11:09:15</code>// @value toDateStamp Date in the format <YYYYMMDD>T<HHMMSS>Z// <i>Example</i>: <code>20051104T111001Z</code>// <br>// <br>// Note: In addition to these standard formats, custom formatting can be set by passing// a function directly to +link{Date.setNormalDisplayFormat()} et al. This // function will then be executed whenever the appropriate formatter method is called [eg // +link{date.toNormalDate()}], in the scope of the date instance in question.//// @visibility external//< //> @classMethod Date.setNormalDisplayFormat()// Set the default formatter for date objects to the method name passed in. After calling this// method, subsequent calls to +link{Date.toNormalDate()} will return a string formatted// according to this format specification. Note: this will be the standard long date format used // by SmartClient components.<br>// The <code>format</code> parameter may be either a +link{DateDisplayFormat} string, or // a function. If passed a function, this function will be executed in the scope of the Date// and should return the formatted string.<br>// Initial default normalDisplayFormat is <code>"toLocaleString"</code>// @group dateFormatting// @param format (DateDisplayFormat | function) new formatter// @visibility external//<setNormalDisplayFormat : function (format) { // if a valid formatter was passed in, set our .formatter property if (isc.isA.Function(Date.prototype[format]) || isc.isA.Function(format)) { Date.prototype.formatter = format; }},//> @classMethod Date.setShortDisplayFormat()// Set the default short format for dates. After calling this method, subsequent calls to // +link{Date.toShortDate()} will returna string formatted according to this format // specification. Note that this will be the standard short date format used by// SmartClient components.<br>// The <code>format</code> parameter may be either a +link{DateDisplayFormat} string, or // a function. If passed a function, this function will be executed in the scope of the Date// and should return the formatted string.<br>// Initial default shortDateFormat is <code>"toUSShortDate"</code>.//// @group dateFormatting// @param format (DateDisplayFormat | function) new formatter// @visibility external//<setShortDisplayFormat : function (format) { if (isc.isA.Function(Date.prototype[format]) || isc.isA.Function(format)) { Date.prototype._shortFormat = format; }},//>!BackCompat 2005.11.3// -- Older depracated synonym of setNormalDisplayFormat //> @classMethod Date.setFormatter()// Set the formatter for all date objects to the method name passed in. After this call// all <code>theDate.toNormalDate()</code> calls will fall through to this formatter function to // return the date as a string.// @group dateFormatting// @param functionName (string) name of a date formatter method on this Date // @visibility internal//<setFormatter : function (formatter) { Date.setNormalDisplayFormat(formatter);},//<!BackCompat//> @classMethod Date.setLocaleStringFormatter() (A)// Set default the +link{Date.iscToLocaleString()} formatter for all date instances.//// @param format (DateDisplayFormat | function) new formatter for iscToLocaleString()// @group dateFormatting// @visibility internal//<setLocaleStringFormatter : function (functionName) { if (isc.isA.Function(Date.prototype[functionName]) || isc.isA.Function(functionName)) Date.prototype.localeStringFormatter = functionName;}// Localizing dayName / monthNames//> @classAttr Date.shortDayNames (Array : null : IRWA)// This property may be set to an array of names of days of the week. <br>// For example:// <pre>// ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]// </pre>// The appropriate day name will then be returned from +link{date.getShortDayName()}, and may // be used whenever SmartClient components display day-names (for example in the // +link{class:DateItem, DateItem class}).<br>// Note: For US based applications the first item in the array should be the name for Sunday, // then Monday, Tuesday, etc. For browsers with different locales this may vary. // To determine the first day for some locale, you can run the following code:// <pre>// alert(new Date(2000, 0, 2).getDay());// </pre>// You should see an alert with a number between zero and 6. This represents the numerical// 'day' value for Sunday for your browser's locale, since Jan 2nd 2000 was a Sunday. // Therefore if this code alerted the number 6, Sunday should appear last in your list // of day-names, and Monday first.// @group i18nMessages// @visibility external//<//> @classAttr Date.shortMonthNames (Array : null : IRWA)// This property may be set to an array of names of months.<br>// For example:// <pre>// ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]// </pre>// The appropriate month name will then be returned from +link{date.getShortMonthName()}, // and may be used whenever SmartClient components display month-names (for example in the // +link{class:DateItem, DateItem class}).// @group i18nMessages// @visibility external//<//> @classAttr Date.weekendDays (Array of int : [0, 6] : IR)// Days that are considered "weekend" days. Values should be the integers returned by the// JavaScript built-in Date.getDay(), eg, 0 in Sunday and 6 is Saturday. Override to// accomodate different workweeks such as Saudi Arabia (Saturday -> Wednesday) or Israel // (Sunday -> Thurday).//<//> @classMethod Date.getWeekendDays() // Return an array of days that are considered "weekend" days. Values will be the integers // returned by the JavaScript built-in Date.getDay(), eg, 0 in Sunday and 6 is Saturday. // Override +link{date.weekendDays} to accomodate different workweeks such as Saudi Arabia // (Saturday -> Wednesday) or Israel (Sunday -> Thurday).// @group dateFormatting // // @return (int[]) array of weekend days//<getWeekendDays : function () { var daysArr = Date.weekendDays; if (daysArr == null) daysArr = Date._derivedWeekendDays; if (daysArr == null) { daysArr = Date._derivedWeekendDays = [0, 6]; } return daysArr;}});//// add methods to the Date.prototype for additional formatting options//isc.addMethods(Date.prototype, {//> @method date.duplicate() (A)// Copy the value of this date into a new Date() object for independant manipulation// @visibility external//<duplicate : function () { var newDate = new Date(); newDate.setTime(this.getTime()); return newDate;},//> @method date.clearTimeFields() (A)// Zero-out the time fields for a date.// @group dateFormatting//<clearTimeFields : function () { this.setHours(0); this.setMinutes(0); this.setSeconds(0); this.setMilliseconds(0); return this;},// Determine the day name from this.toString()deriveShortDayName : function (length) { var string = this.toString(); if (length == null || length <=0 || length > 3) length = 3; return string.substring(0,length);},//> @method date.getShortDayName() // Return the abbreviated (up to 3 chars) day of week name for this date (Mon, Tue, etc).// To modify the value returned by this method, set +link{Date.shortDayNames}//// @group dateFormatting// @param length (number) Number of characters to return (Defaults to 3, can't be // longer than 3)// @return (string) Abbreviated day name// @visibility external//<getShortDayName : function () { return this.getShortDayNames()[this.getDay()];},//> @method date.getShortDayNames() (A)// Return an array of the short names of each day, suitable for us in a selection list, etc.// Day names will be picked up from +link{Date.shortDayNames} if specified - otherwise derived// from the native browser date string.// @group dateFormatting//// @param length (number) Number of characters for each day (Defaults to 3, can't be // longer than 3)// @return (string[]) array of short day names//<getShortDayNames : function (length) { length = length || 3; var rawNames = Date.shortDayNames; if (rawNames == null) rawNames = Date._derivedShortDayNames; if (rawNames == null) { Date._derivedShortDayNames = []; var dateObj = new Date(); dateObj.setDate(1); if (dateObj.getDay() > 0) dateObj.setDate(dateObj.getDate() + (7-dateObj.getDay())); var startDate = dateObj.getDate(); for (var i = 0; i < 7; i++) { dateObj.setDate(startDate + i); Date._derivedShortDayNames[i] = dateObj.deriveShortDayName(); } rawNames = Date._derivedShortDayNames; } var names = []; for (var i = 0; i < 7; i++) { names[i] = rawNames[i].substring(0,length); } return names;},// deriveShortMonthNames() - figure out the names of months from the native browser// date formatting methods.deriveShortMonthName : function (length) { var string = this.toString(); if (length == null || length < 0 || length > 3) length = 3; return string.substring(4, (4+length));},//> @method date.getShortMonthName() // Return the abbreviated (up to 3 chars) name of the month for this date (Jan, Feb, etc)// To modify the value returned by this method, set +link{Date.shortMonthNames}// @group dateFormatting// @param length (number) Number of characters to return (Defaults to 3, can't be// longer than 3)// @return (string) Abbreviated month name (3 character string)// @visibility external//<getShortMonthName : function () { return this.getShortMonthNames()[this.getMonth()];},//> @method date.getShortMonthNames() (A)// Return an array of the short names of each month, suitable for us in a selection list, etc.// If +link{Date.shortMonthNames} is specified, this list will be used. Otherwise the value// will be derived from the native browser date formatters.// @group dateFormatting//// @param length (number) Number of characters for each day (Defaults to 3, can't be // longer than 3)// @return (string[]) array of short month names//<getShortMonthNames : function (length) { length = length || 3; var rawNames = Date.shortMonthNames; if (rawNames == null) rawNames = Date._derivedShortMonthNames; if (rawNames == null) { var list = Date._derivedShortMonthNames = []; for (var i = 0; i < 12; i++) { var date = new Date(2000,i,1); list[i] = date.deriveShortMonthName(); } rawNames = Date._derivedShortMonthNames; } var names = []; for (var i =0; i< 12; i++) { names[i] = rawNames[i].substring(0,length);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -