Commit 2dc5346a authored by Farid Neshat's avatar Farid Neshat

Backport more fixes

parent a5af8833
...@@ -97,17 +97,20 @@ module.exports = function(robot) { ...@@ -97,17 +97,20 @@ module.exports = function(robot) {
result.end = new Date(options.end + timestring(args[key], 'ms')); result.end = new Date(options.end + timestring(args[key], 'ms'));
} }
} }
}
if (args.on) { if (args.on) {
query.push('on', utils.formatDate(options.start)); query.push('on', utils.formatDate(options.start));
} else { options.start = options.end = utils.serializeDate(options.start);
if (options.start) { } else {
query.push('from', utils.formatDate(options.from)); if (options.start) {
} query.push('from', utils.formatDate(options.from));
options.start = utils.serializeDate(options.start);
}
if (options.end) { if (options.end) {
query.push('to', utils.formatDate(options.from)); query.push('to', utils.formatDate(options.from));
} options.end = utils.serializeDate(options.end);
} }
} }
......
...@@ -14,11 +14,18 @@ exports.formatTimeOff = ({type, start, end, amount, unit, amountUnit, id}) => { ...@@ -14,11 +14,18 @@ exports.formatTimeOff = ({type, start, end, amount, unit, amountUnit, id}) => {
return result; return result;
}; };
exports.parseDate = date => moment(date, 'YYYY-MM-DD');
exports.serializeDate = date =>
((typeof date === 'string') ? exports.parseDate(date) : moment(date)).format('YYYY-MM-DD');
exports.formatDate = (date, withYear, format = HUMAN_DATE_FORMAT) => exports.formatDate = (date, withYear, format = HUMAN_DATE_FORMAT) =>
moment(date).format(format + (withYear ? ' YYYY' : '')); moment(date).format(format + (withYear ? ' YYYY' : ''));
exports.errorHandler = msg => err => { exports.errorHandler = msg => err => {
msg.reply('I\'m sorry, something went wrong: ' + err.message || err); const message = 'I\'m sorry, something went wrong: ' + err.message || err;
if (msg) {
msg.reply(message);
}
console.error(err); console.error(err);
console.error(err.stack); console.error(err.stack);
return message;
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment