Skip to content

Commit

Permalink
Check for value in milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanReiter committed Dec 30, 2011
1 parent f0adf66 commit 1a3f488
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/persistence.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1016,7 +1016,12 @@ persistence.get = function(arg1, arg2) {
switch(type) { switch(type) {
case 'DATE': case 'DATE':
if(typeof value === 'number') { 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 { } else {
return null; return null;
} }
Expand Down
7 changes: 6 additions & 1 deletion lib/persistence.store.appengine.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ exports.config = function(persistence) {
switch (type) { switch (type) {
case 'DATE': case 'DATE':
// SQL is in seconds and JS in miliseconds // 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': case 'BOOL':
return val === 1 || val === '1'; return val === 1 || val === '1';
break; break;
Expand Down
7 changes: 6 additions & 1 deletion lib/persistence.store.sql.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ var defaultTypeMapper = {
switch (type) { switch (type) {
case 'DATE': case 'DATE':
// SQL is in seconds and JS in miliseconds // 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': case 'BOOL':
return val === 1 || val === '1'; return val === 1 || val === '1';
break; break;
Expand Down
7 changes: 6 additions & 1 deletion lib/persistence.sync.server.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ function jsonToEntityVal(value, type) {
if(type) { if(type) {
switch(type) { switch(type) {
case 'DATE': 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; break;
default: default:
return value; return value;
Expand Down

0 comments on commit 1a3f488

Please sign in to comment.