📄 date.js
字号:
// @group dateFormatting// @visibility internal// @deprecated As of SmartClient 5.5 use the static method // +link{classMethod:Date.setLocaleStringFormatter} instead//<setLocaleStringFormatter : function (functionName) { if (isc.isA.Function(this[functionName]) || isc.isA.Function(functionName)) this.localeStringFormatter = functionName;}});//> @method date.toBrowserString()// Native <code>date.toString()</code> provided by the browser for Date objects// @group dateFormatting// @visibility internal// @deprecated As of SmartClient 5.5//<// Note that the default formatter varies by browser/platform so it's not that useful.// This was exposed in 5.2 so we're keeping it around for back-compat onlyDate.prototype.toBrowserString = Date.prototype.toString;//> @method date.toBrowserLocaleString() (A)// Synonym for <code>date.toLocaleString()</code> provided by the browser for Date objects// @group dateFormatting// @visibility internal// @deprecated As of SmartClient 5.5//<Date.prototype.toBrowserLocaleString = Date.prototype.toLocaleString;// set the standard formatter for the date prototype to the native browser string// so everything works as normal until it is overridden.if (!Date.prototype.formatter) Date.prototype.formatter = "toLocaleString"// set the standard toShortDate() formatter to US Short Dateif (!Date.prototype._shortFormat) Date.setShortDisplayFormat("toUSShortDate");//> @method date.iscToLocaleString() (A)// Customizeable toLocaleString() type method.// This method is called when isc.iscToLocaleString(date) is called.//// @group dateFormatting// @return (string) formatted date string// @visibility internal//<// Leave this internal - we don't really expect this to be called directly or overridden by// the developerDate.prototype.iscToLocaleString = function () { var formatter = this.localeStringFormatter; if (isc.isA.Function(formatter)) return formatter.apply(this); else if (this[formatter]) return this[formatter]();}// By default have iscToLocaleString() call date.toLocaleString()if (!Date.prototype.localeStringFormatter) Date.prototype.localeStringFormatter = "toLocaleString";// Explicitly set the default date input format to "MDY" (standard US format)Date.setInputFormat("MDY"); //>Safari12isc.addMethods(Date, { // Simple substring matching for splitting up a date string to avoid using unsupported // string.match() method in early Safari // Note - somewhat flawed: we're assuming well never be handed a single digit month or day _splitDateViaSubstring : function (string, monthIndex, dayIndex, yearIndex) { // We know that year may be after month and/or day - allow 3 chars ("DD/") for each var yearCharIndex = yearIndex * 3, year = string.substring(yearCharIndex, yearCharIndex +4) ; // If we have a 2 char year, this may effect the position of the day/month in the string var twoCharYear = (parseInt(year) != year); if (twoCharYear) year = year.substring(0,2); var monthCharIndex = 0, dayCharIndex = 0; if (monthIndex > dayIndex) monthCharIndex += 3; else dayCharIndex += 3; if (monthIndex > yearIndex) monthCharIndex += (twoCharYear?3 : 5); if (dayIndex > yearIndex) dayCharIndex += (twoCharYear ? 3 : 5); // Note: Month is zero based rather than 1 based. var month = string.substring(monthCharIndex, monthCharIndex + 2) -1; var day = string.substring(dayCharIndex, dayCharIndex +2); // Hour minute second are not expected to change orders var hourCharIndex = twoCharYear ? 9 : 11, hour = (string.substring(hourCharIndex,hourCharIndex + 2) || 0), minute = (string.substring(hourCharIndex + 3, hourCharIndex + 5) || 0), second = (string.substring(hourCharIndex + 6, hourCharIndex + 8) || 0); return[year,month,day,hour,minute,second]; }});//<Safari12//>!BackCompat 2005.11.3isc.addMethods(Date.prototype, {//> @method date.toPrettyString()// Return this date in the format: <code>MM/DD/YY HH:MM</code>// @group dateFormatting// @return (string) formatted date string// @visibility external// @deprecated As of SmartClient 5.5 use +link{date.toShortDate()} instead //<toPrettyString : function () { return this.toUSShortDateTime();} });isc.addMethods(Date, {// --- Parsing functions --- :// In 5.2 the paradigm was to provide formatters and complimentary parsers, like // 'toEuropeanShortDate' and 'parseEuropeanShortDate'.// We've moved away from this to instead use a single 'parseInput' function which takes a // 'format' parameter specifying "MDY" / "DMY", etc.// This is appropriate since we do not plan to provide parsing functions for every date formatter// format.// Leaving the older explicit parsing functions in place for back-compat only.//> @classMethod Date.parseStandardDate()// Parse a date passed in as a string of format:// <code>YYYY-MM-DD HH:MM:SS</code> or <code>YYYY-MM-DD</code>// Returning a new <code>Date</code> object with the appropriate value.// // @group dateFormatting//// @param dateString (string) date value as a string//// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseStandardDate : function (dateString) { if (!isc.isA.String(dateString)) return null; // Note: we could be using a regexp here rather than substring matches var year = dateString.substring(0,4), month = dateString.substring(5,7)-1, day = dateString.substring(8,10), hour = dateString.substring(11, 13), minute = dateString.substring(14, 16), second = dateString.substring(17, 19); // If they all are numbers, construct a new date // 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 (dateString.length < 19) { if (!isc.isA.Number(year - month - day)) return null; } else { if (!isc.isA.Number(year - month - day - hour - minute - second)) return null; } return new Date(year, month, day, hour, minute, second);},//> @classMethod Date.parseSerializeableDate()// Parse a date passed in as a string of format:// <code>YYYY-MM-DD HH:MM:SS</code> or <code>YYYY-MM-DD</code>// Returning a new <code>Date</code> object with the appropriate value.// <i>This is a synonym for </i><code>Date.parseStandardDate()</code>// // @group dateFormatting// @param dateString (string) date value as a string// @return (Date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseSerializeableDate : function (dateString) { // synonym for parseStandardDate return this.parseStandardDate(dateString);},//> @classMethod Date.parseDBDate()// Parse a date passed in as a string of format: // <code>$$DATE$$:<i>YYYY-MM-DD HH:MM:SS</i></code>// Returning a new <code>Date</code> object with the appropriate value.//// @group dateFormatting// @param dateString (string) date value as a string// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseDBDate : function (dateString) { // remove the leading "$$DATE$$:" if (isc.isA.String(dateString) && dateString.startsWith("$$DATE$$:")) { dateString = dateString.substring(9) return this.parseStandardDate(dateString); } return null;},//> @classMethod Date.parseDateStamp()// // Parse a dateStamp of the format: <code><i>YYYYMMDD</i>T<i>HHMMSS</i>[Z]</code><br><br>//// @group dateFormatting// @param dateString (string) String to parse// @return (Date) Date object, or null if not parsed correctly.//// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseDateStamp : function (string) { if (string == null || isc.isA.Date(string)) return string; var date = new Date( Date.UTC( string.substring(0,4), // year parseInt(string.substring(4,6), 10)-1, // mon string.substring(6,8), // day // omit this character (T) string.substring(9,11), // hour string.substring(11,13), // min string.substring(13,15) // Technically we should look at the last character - if its something other // than "z" the timezone would be something other than UTC. )); if (isc.isA.Date(date)) return date; else return null;},//> @classMethod Date.parseShortDate()// Parse a date passed in as a string of format: <code>MM/DD/YYYY</code>//// @group dateFormatting// @param dateString (string) date value as a string// @param [centuryThreshold] (number) if parsed year is 2 digits and less than this// number, assume year to be 20xx//// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseShortDate : function (string, centuryThreshold) { return this.parseInput(string, "MDY", centuryThreshold);},//> @classMethod Date.parseShortDateTime()// Parse a date passed in as a string of format: <code>MM/DD/YYYY HH:MM:SS</code>//// @group dateFormatting// @param dateString (string) date value as a string// @param [centuryThreshold] (number) if parsed year is 2 digits and less than this// number, assume year to be 20xx//// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseShortDateTime : function (string, centuryThreshold) { // synonym for parseShortDate - included for completeness and to provide the appropriate // compliment to date.toShortDateTime() return this.parseShortDate(string, centuryThreshold);},//> @classMethod Date.parsePrettyString()// Parse a date passed in as a string of format: <code>MM/DD/YY HH:MM:SS</code>//// @group dateFormatting// @param dateString (string) date value as a string// @param [centuryThreshold] (number) if parsed year is less than this// number, assume year to be 20xx rather than 19xx//// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parsePrettyString : function (string, centuryThreshold) { // this is just the same as a short date with a 2 digit year. return this.parseShortDate(string, centuryThreshold);},//> @classMethod Date.parseEuropeanShortDate()// parse a date passed in as a string of format: <code>DD/MM/YYYY</code>// @group dateFormatting// @param dateString (string) date value as a string// @param [centuryThreshold] (number) if parsed year is 2 digits and less than this// number, assume year to be 20xx//// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseEuropeanShortDate : function (string, centuryThreshold) { return this.parseInput(string, "DMY", centuryThreshold);},//> @classMethod Date.parseEuropeanShortDateTime()// parse a date passed in as a string of format: <code>DD/MM/YYYY HH:MM:SS</code>// @group dateFormatting// @param dateString (string) date value as a string// @param [centuryThreshold] (number) if parsed year is 2 digits and less than this// number, assume year to be 20xx//// @return (date) date value// @visibility internal// @deprecated As of SmartClient 5.5 use +link{date.parseInput} instead//<parseEuropeanShortDateTime : function (string, centuryThreshold) { return this.parseInput(string, "DMY", centuryThreshold);} });//<!BackCompat
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -