My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 1076 attachment: parseDate.js (1.2 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function parseDate(s, ignoreTimezone) { // ignoreTimezone defaults to true
if (typeof s == 'object') { // already a Date object
return s;
}
if (typeof s == 'number') { // a UNIX timestamp
if( ignoreTimezone == true ){
var lclDate = new Date(s * 1000);
return new Date( lclDate.valueOf() + ( lclDate.getTimezoneOffset() * 60 *1000 ) );
}
else{
return new Date(s * 1000);
}
}
if (typeof s == 'string') {
if (s.match(/^\d+(\.\d+)?$/)) { // a UNIX timestamp
if( ignoreTimezone == true ){
var lclDate = new Date(parseFloat(s) * 1000);
return new Date( lclDate.valueOf() + ( lclDate.getTimezoneOffset() * 60 *1000 ) );
}
else{
return new Date(parseFloat(s) * 1000);
}
}
if (ignoreTimezone === undefined) {
ignoreTimezone = true;
}
return parseISO8601(s, ignoreTimezone) || (s ? new Date(s) : null);
}
// TODO: never return invalid dates (like from new Date(<string>)), return null instead
return null;
}
Powered by Google Project Hosting