MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / parseDate

Function parseDate

libs/echarts/echarts.simple.js:19113–19172  ·  view source on GitHub ↗

* @param {string|Date|number} value These values can be accepted: * + An instance of Date, represent a time in its own time zone. * + Or string in a subset of ISO 8601, only including: * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06', * + separ

(value)

Source from the content-addressed store, hash-verified

19111 * @return {Date} date
19112 */
19113function parseDate(value) {
19114 if (value instanceof Date) {
19115 return value;
19116 }
19117 else if (typeof value === 'string') {
19118 // Different browsers parse date in different way, so we parse it manually.
19119 // Some other issues:
19120 // new Date('1970-01-01') is UTC,
19121 // new Date('1970/01/01') and new Date('1970-1-01') is local.
19122 // See issue #3623
19123 var match = TIME_REG.exec(value);
19124
19125 if (!match) {
19126 // return Invalid Date.
19127 return new Date(NaN);
19128 }
19129
19130 // Use local time when no timezone offset specifed.
19131 if (!match[8]) {
19132 // match[n] can only be string or undefined.
19133 // But take care of '12' + 1 => '121'.
19134 return new Date(
19135 +match[1],
19136 +(match[2] || 1) - 1,
19137 +match[3] || 1,
19138 +match[4] || 0,
19139 +(match[5] || 0),
19140 +match[6] || 0,
19141 +match[7] || 0
19142 );
19143 }
19144 // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
19145 // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
19146 // For example, system timezone is set as "Time Zone: America/Toronto",
19147 // then these code will get different result:
19148 // `new Date(1478411999999).getTimezoneOffset(); // get 240`
19149 // `new Date(1478412000000).getTimezoneOffset(); // get 300`
19150 // So we should not use `new Date`, but use `Date.UTC`.
19151 else {
19152 var hour = +match[4] || 0;
19153 if (match[8].toUpperCase() !== 'Z') {
19154 hour -= match[8].slice(0, 3);
19155 }
19156 return new Date(Date.UTC(
19157 +match[1],
19158 +(match[2] || 1) - 1,
19159 +match[3] || 1,
19160 hour,
19161 +(match[5] || 0),
19162 +match[6] || 0,
19163 +match[7] || 0
19164 ));
19165 }
19166 }
19167 else if (value == null) {
19168 return new Date(NaN);
19169 }
19170

Callers 3

formatTimeFunction · 0.70
converDataValueFunction · 0.70
echarts.simple.jsFile · 0.70

Calls 2

roundMethod · 0.80
execMethod · 0.45

Tested by

no test coverage detected