Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Check for value in milliseconds

  • Loading branch information...
commit 1a3f48877807bfe261bef1a8494955b8e48f706c 1 parent f0adf66
@maketolearn maketolearn authored
View
7 lib/persistence.js
@@ -1016,7 +1016,12 @@ persistence.get = function(arg1, arg2) {
switch(type) {
case 'DATE':
if(typeof value === 'number') {
- return new Date(value * 1000);
+ if (value > 1000000000000) {
+ // it's in milliseconds
+ return new Date(value);
+ } else {
+ return new Date(value * 1000);
+ }
} else {
return null;
}
View
7 lib/persistence.store.appengine.js
@@ -32,7 +32,12 @@ exports.config = function(persistence) {
switch (type) {
case 'DATE':
// SQL is in seconds and JS in miliseconds
- return new Date(parseInt(val, 10) * 1000);
+ if (val > 1000000000000) {
+ // usually in seconds, but sometimes it's milliseconds
+ return new Date(parseInt(val, 10));
+ } else {
+ return new Date(parseInt(val, 10) * 1000);
+ }
case 'BOOL':
return val === 1 || val === '1';
break;
View
7 lib/persistence.store.sql.js
@@ -44,7 +44,12 @@ var defaultTypeMapper = {
switch (type) {
case 'DATE':
// SQL is in seconds and JS in miliseconds
- return new Date(parseInt(val, 10) * 1000);
+ if (val > 1000000000000) {
+ // usually in seconds, but sometimes it's milliseconds
+ return new Date(parseInt(val, 10));
+ } else {
+ return new Date(parseInt(val, 10) * 1000);
+ }
case 'BOOL':
return val === 1 || val === '1';
break;
View
7 lib/persistence.sync.server.js
@@ -38,7 +38,12 @@ function jsonToEntityVal(value, type) {
if(type) {
switch(type) {
case 'DATE':
- return new Date(value * 1000);
+ if (value > 1000000000000) {
+ // it's in milliseconds
+ return new Date(value);
+ } else {
+ return new Date(value * 1000);
+ }
break;
default:
return value;
Please sign in to comment.
Something went wrong with that request. Please try again.