lastCron: set as midnight using new Date().toDateString()

This commit is contained in:
Tyler Renelle 2012-07-11 15:24:23 -04:00
parent 8f43f7d0c7
commit 095865ff2e
2 changed files with 9 additions and 22 deletions

View file

@ -299,7 +299,7 @@ ready(function(model) {
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
obj = _ref3[_k];
date = new Date(obj.date);
readableDate = "" + (date.getMonth()) + "/" + (date.getDate()) + "/" + (date.getFullYear());
readableDate = "" + (date.getMonth()) + "+1/" + (date.getDate()) + "/" + (date.getFullYear());
matrix.push([readableDate, obj.value]);
}
data = google.visualization.arrayToDataTable(matrix);
@ -511,18 +511,11 @@ ready(function(model) {
};
poormanscron = function() {
var DAY, daysPassed, lastCron, today;
lastCron = model.get('_user.lastCron');
if (lastCron) {
lastCron = new Date(model.get('_user.lastCron'));
} else {
lastCron = new Date();
model.set('_user.lastCron', lastCron);
}
lastCron = new Date("" + (lastCron.getMonth()) + "/" + (lastCron.getDate()) + "/" + (lastCron.getFullYear()));
model.setNull('_user.lastCron', new Date());
lastCron = new Date(new Date(model.get('_user.lastCron')).toDateString());
console.log(lastCron);
DAY = 1000 * 60 * 60 * 24;
today = new Date();
today = new Date("" + (today.getMonth()) + "/" + (today.getDate()) + "/" + (today.getFullYear()));
today = new Date(new Date().toDateString());
daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY);
if (daysPassed > 0) {
_(daysPassed).times(function() {

View file

@ -196,7 +196,7 @@ ready (model) ->
matrix = [['Date', 'Score']]
for obj in model.get(historyPath)
date = new Date(obj.date)
readableDate = "#{date.getMonth()}/#{date.getDate()}/#{date.getFullYear()}"
readableDate = "#{date.getMonth()}+1/#{date.getDate()}/#{date.getFullYear()}"
matrix.push [ readableDate, obj.value ]
data = google.visualization.arrayToDataTable matrix
@ -385,18 +385,12 @@ ready (model) ->
#TODO: remove when cron implemented
poormanscron = ->
lastCron = model.get('_user.lastCron')
if lastCron
# need to do date calculation, seems it's stored in db as string
lastCron = new Date(model.get('_user.lastCron'))
else
lastCron = new Date()
model.set('_user.lastCron', lastCron)
lastCron = new Date("#{lastCron.getMonth()}/#{lastCron.getDate()}/#{lastCron.getFullYear()}") # calculate as midnight
model.setNull('_user.lastCron', new Date())
# need to do date calculation, seems it's stored in db as string
lastCron = new Date(new Date(model.get('_user.lastCron')).toDateString()) # calculate as midnight
console.log lastCron
DAY = 1000 * 60 * 60 * 24
today = new Date()
today = new Date("#{today.getMonth()}/#{today.getDate()}/#{today.getFullYear()}") # calculate as midnight
today = new Date(new Date().toDateString()) # calculate as midnight
daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY)
if daysPassed > 0
_(daysPassed).times ->