shared helpers.dayMapping

This commit is contained in:
Tyler Renelle 2012-09-24 23:12:13 -04:00
parent f78cd64218
commit b63ac10657
4 changed files with 18 additions and 27 deletions

View file

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.3.3
var moment;
var dayMapping, moment;
moment = require('moment');
@ -7,20 +7,21 @@ module.exports.daysBetween = function(a, b) {
return Math.abs(moment(a).sod().diff(moment(b).sod(), 'days'));
};
module.exports.dayMapping = dayMapping = {
0: 'su',
1: 'm',
2: 't',
3: 'w',
4: 'th',
5: 'f',
6: 's',
7: 'su'
};
module.exports.viewHelpers = function(view) {
view.fn('taskClasses', function(type, completed, value, repeat) {
var classes, dayMapping;
var classes;
classes = type;
dayMapping = {
0: 'su',
1: 'm',
2: 't',
3: 'w',
4: 'th',
5: 'f',
6: 's',
7: 'su'
};
if (completed || (repeat && repeat[dayMapping[moment().day()]] === false)) {
classes += " completed";
}

View file

@ -216,7 +216,7 @@ cron = function() {
todoTally = 0;
hpTally = 0;
tallyTask = function(taskObj, callback) {
var absVal, completed, dayMapping, daysFailed, id, repeat, task, type, value;
var absVal, completed, daysFailed, id, repeat, task, type, value;
id = taskObj.id, type = taskObj.type, completed = taskObj.completed, repeat = taskObj.repeat;
if (id == null) {
return callback('a task had a null id during cron, this should not be happening');
@ -226,21 +226,11 @@ cron = function() {
if (!completed) {
daysFailed = daysPassed;
if (type === 'daily' && repeat) {
dayMapping = {
0: 'su',
1: 'm',
2: 't',
3: 'w',
4: 'th',
5: 'f',
6: 's',
7: 'su'
};
daysFailed = 0;
_.times(daysPassed, function(n) {
var thatDay;
thatDay = moment().subtract('days', n + 1);
if (repeat[dayMapping[thatDay.day()]] === true) {
if (repeat[helpers.dayMapping[thatDay.day()]] === true) {
return daysFailed++;
}
});

View file

@ -3,6 +3,8 @@ moment = require('moment')
# Absolute diff between two dates, based on 12am for both days
module.exports.daysBetween = (a, b) ->
Math.abs(moment(a).sod().diff(moment(b).sod(), 'days'))
module.exports.dayMapping = dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
module.exports.viewHelpers = (view) ->
view.fn 'taskClasses', (type, completed, value, repeat) ->
@ -10,7 +12,6 @@ module.exports.viewHelpers = (view) ->
classes = type
# show as completed if completed (naturally) or not required for today
dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
if completed or (repeat and repeat[dayMapping[moment().day()]]==false)
classes += " completed"

View file

@ -210,11 +210,10 @@ cron = ->
# however, for dailys which have repeat dates, need
# to calculate how many they've missed according to their own schedule
if type=='daily' && repeat
dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
daysFailed = 0
_.times daysPassed, (n) ->
thatDay = moment().subtract('days', n+1)
if repeat[dayMapping[thatDay.day()]]==true
if repeat[helpers.dayMapping[thatDay.day()]]==true
daysFailed++
hpTally += score(id, 'down', {cron:true, times:daysFailed})