Skip to content
Snippets Groups Projects
Commit b9657ca4 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Bugfix: Now handling JSON dates also in Safari

parent a7f9287b
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,7 @@ var currentDateInMillis; ...@@ -64,6 +64,7 @@ var currentDateInMillis;
*/ */
function initFrontpageMap(lonLat, zoomLevel, mapAttribution) function initFrontpageMap(lonLat, zoomLevel, mapAttribution)
{ {
if(settings.vipslogicServerName === undefined) if(settings.vipslogicServerName === undefined)
{ {
alert(gettext("Source hostname not defined.")); alert(gettext("Source hostname not defined."));
......
...@@ -343,9 +343,21 @@ function isDict(v){ ...@@ -343,9 +343,21 @@ function isDict(v){
return typeof v==='object' && v!==null && !(v instanceof Array) && !(v instanceof Date); return typeof v==='object' && v!==null && !(v instanceof Array) && !(v instanceof Date);
} }
/**
* Unfortunately, this method depends on momentjs, since date parsing directly in JavaScript is...hard
*/
function getUnixTimestampFromJSON(ambiguousValue) function getUnixTimestampFromJSON(ambiguousValue)
{ {
var possibleDateObject = new Date(ambiguousValue); var possibleDateObject;
if(!isMomentJSAvailable())
{
possibleDateObject = new Date(ambiguousValue);
console.info("Warning: Parsing date without MomentJS. Can't guarantee correct result.");
}
else
{
possibleDateObject = moment(ambiguousValue).toDate();
}
if(possibleDateObject.getTime() === NaN && typeof parseInt(ambiguousValue) === "number") if(possibleDateObject.getTime() === NaN && typeof parseInt(ambiguousValue) === "number")
{ {
return parseInt(ambiguousValue); return parseInt(ambiguousValue);
...@@ -355,3 +367,16 @@ function getUnixTimestampFromJSON(ambiguousValue) ...@@ -355,3 +367,16 @@ function getUnixTimestampFromJSON(ambiguousValue)
return possibleDateObject.getTime(); return possibleDateObject.getTime();
} }
} }
function isMomentJSAvailable()
{
try {
moment();
return true;
}
catch (err)
{
return false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment