diff --git a/modules/profile/config.json b/modules/profile/config.json index 70b7210..7a9dbec 100644 --- a/modules/profile/config.json +++ b/modules/profile/config.json @@ -10,10 +10,7 @@ "bio": null, "favourites": { "colour": null - } - }, - "preferences": { - "timezone": null + }, } }, "dependencies": [ "web", "quotes", "users" ] diff --git a/modules/report/pages.js b/modules/report/pages.js index 7b0e308..5953474 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -1,5 +1,6 @@ var _ = require('underscore')._, - async = require('async'); + async = require('async'), + moment = require('moment-timezone'); var pages = function(dbot) { var pages = { @@ -55,9 +56,16 @@ var pages = function(dbot) { user = req.user, notifies = this.pending[user.id]; + notifies = _.sortBy(notifies, 'time').reverse(); + if(req.user.timezone) { + _.each(notifies, function(v, k) { + v.time = moment(v.time).tz(req.user.timezone); + }); + } + res.render('missing_notifies', { 'user': user.primaryNick, - 'notifies': _.sortBy(notifies, 'time') + 'notifies': notifies }); if(_.has(dbot.modules, 'log')) { @@ -92,9 +100,16 @@ var pages = function(dbot) { next(); } }, function() { + notifies = _.sortBy(notifies, 'time').reverse(); + if(req.user.timezone) { + _.each(notifies, function(v, k) { + v.time = moment(v.time).tz(req.user.timezone); + }); + } + res.render('notifies', { 'server': server, - 'notifies': _.sortBy(notifies, 'time').reverse() + 'notifies': notifies }); }); }); @@ -108,9 +123,16 @@ var pages = function(dbot) { notify.user = user.primaryNick; notifies.push(notify); }, function() { + notifies = _.sortBy(notifies, 'time').reverse(); + if(req.user.timezone) { + _.each(notifies, function(v, k) { + v.time = moment(v.time).tz(req.user.timezone); + }); + } + res.render('notifies', { 'server': server, - 'notifies': _.sortBy(notifies, 'time').reverse() + 'notifies': notifies }); }); }.bind(this)); diff --git a/modules/users/commands.js b/modules/users/commands.js index a347064..420e274 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -1,4 +1,5 @@ -var _ = require('underscore')._; +var _ = require('underscore')._, + moment = require('moment-timezone'); var commands = function(dbot) { var commands = { @@ -34,6 +35,23 @@ var commands = function(dbot) { } }); }, + + '~timezone': function(event) { + if(event.params[1]) { + try { + moment().tz(event.params[1]); + } catch(err) { + return event.reply('Invalid timezone. See http://momentjs.com/timezone/'); + } + + event.rUser.timezone = event.params[1]; + this.db.save('users', event.rUser.id, event.rUser, function() { + event.reply('Timezone updated.'); + }); + } else { + event.reply('Current timezone: ' + event.rUser.timezone); + } + }, '~setmobilealias': function(event) { if(_.include(event.rUser.aliases, event.params[1])) { diff --git a/views/report/missing_notifies.jade b/views/report/missing_notifies.jade index 79cdf3f..c21181c 100644 --- a/views/report/missing_notifies.jade +++ b/views/report/missing_notifies.jade @@ -15,5 +15,5 @@ block content tbody each notify in notifies tr - td #{new Date(notify.time)} + td #{notify.time} td #{notify.message} diff --git a/views/report/notifies.jade b/views/report/notifies.jade index 2fd9a6f..b988872 100644 --- a/views/report/notifies.jade +++ b/views/report/notifies.jade @@ -18,7 +18,7 @@ block content tbody for notify in notifies tr - td #{new Date(notify.time)} + td #{notify.time} td #{notify.channel} td #{notify.type} td #{notify.user}