fixed dates
This commit is contained in:
parent
eda6ab76e0
commit
d4949326e3
39
lib/today.js
39
lib/today.js
@ -16,6 +16,9 @@ var mdMailer = require('./today/mailer');
|
||||
var mdFitbit = require('./today/fitbit');
|
||||
var db_name = 'silvrgit';
|
||||
var dbCouch = nano.use(db_name);
|
||||
|
||||
require('sugar-date');
|
||||
|
||||
var todayCache = {
|
||||
last: 0, data: {
|
||||
trains: {last: 0, data: []}, weather: {}, history: [], today: '', tv: {entries: []}, cal: {entries: []}, swedish: {}, fitbit:{}
|
||||
@ -40,8 +43,18 @@ function saveToDB(data) {
|
||||
}
|
||||
|
||||
function nth(d) {
|
||||
if (d > 3 && d < 21) {return 'th';} // Thanks kennebec
|
||||
if (d % 10 === 1) {return 'st';} else if (d % 10 === 2) {return 'nd';} else if (d % 10 === 3) {return 'rd';} else {return 'th';}
|
||||
// if (d > 3 && d < 21) {return 'th';} // Thanks kennebec
|
||||
// if (d % 10 === 1) {return 'st';} else if (d % 10 === 2) {return 'nd';} else if (d % 10 === 3) {return 'rd';} else {return 'th';}
|
||||
var n= d;
|
||||
return Math.floor(n / 10) === 1
|
||||
? 'th'
|
||||
: (n % 10 === 1
|
||||
? 'st'
|
||||
: (n % 10 === 2
|
||||
? 'nd'
|
||||
: (n % 10 === 3
|
||||
? 'rd'
|
||||
: 'th')));
|
||||
}
|
||||
|
||||
function dayNumber() {
|
||||
@ -66,6 +79,9 @@ function DayDiff(CurrentDate) {
|
||||
TDay.getFullYear(TYear);
|
||||
var DayCount = (TDay - CurrentDate) / (1000 * 60 * 60 * 24);
|
||||
DayCount = Math.round(DayCount);
|
||||
|
||||
var d = new Date();
|
||||
DayCount = d.daysSince('beginning of this year');
|
||||
return (DayCount);
|
||||
}
|
||||
|
||||
@ -78,7 +94,7 @@ Array.prototype.indexOf = function(e, fn) {
|
||||
var att = fn;
|
||||
fn = function(e) {
|
||||
return e[att];
|
||||
}
|
||||
};
|
||||
}
|
||||
return this.map(fn).indexOfOld(e);
|
||||
}
|
||||
@ -95,11 +111,24 @@ module.exports = {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(todayCache));
|
||||
}, getTodayDate: function() {
|
||||
var s, d = new Date();
|
||||
var s, d = new Date(), nextYear = (parseInt(d.getFullYear()) + 1).toString() + '-01-01';
|
||||
|
||||
console.log(d.daysUntil('beginning of next year'));
|
||||
var daysSinceStart = d.daysSince('beginning of this year');
|
||||
var daysRemaining = d.daysUntil('beginning of next year');
|
||||
|
||||
todayCache.data.history = [];
|
||||
s = '<strong>' + dateFormat(d, 'mmmm d') + '</strong> - ';
|
||||
s = '<strong>' + d.format('{Weekday} {Month} {dd}, {yyyy}') + '</strong> - ';
|
||||
/*
|
||||
s = s + 'The ' + dayNumber() + nth(dayNumber) + ' day of ' + dateFormat(d,
|
||||
'yyyy') + ', and there are ' + DayDiff(d) + ' days left until the end of the year.';
|
||||
*/
|
||||
|
||||
s = s + 'The ' + daysSinceStart + nth(daysSinceStart) + ' day of ' + dateFormat(d,
|
||||
'yyyy') + ', and there are ' + daysRemaining + ' days left until the end of the year.';
|
||||
|
||||
|
||||
|
||||
logger.debug(s);
|
||||
todayCache.data.today = s;
|
||||
}, refreshTrainAndWeather: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user