#328128 Add the user's datetime offset to their profile. Use it to format the date in event-related emails.

This commit is contained in:
Georgi Prodanov 2017-02-14 15:59:53 +02:00
Родитель 34123b5030
Коммит 72fcc8521e
2 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -37,7 +37,9 @@ export class UsersService {
}
register(username: string, password: string, displayName: string) {
return this._users.register(username, password, { Email: username, DisplayName: displayName });
let attrs: any = { Email: username, DisplayName: displayName };
attrs.TimezoneOffset = (new Date()).getTimezoneOffset();
return this._users.register(username, password, attrs);
}
resetUserPassword(identifier: string) {

Просмотреть файл

@ -111,8 +111,22 @@ function getDataForUserRegisteredForEvent (context) {
});
}
function _offsetDate (dateIsoString, offset) {
var oneHour = 3600000;
var msInMinute = 60000;
var d = new Date(dateIsoString);
var offsetDateInMs = d.getTime() + (d.getTimezoneOffset() * msInMinute);
return new Date(offsetDateInMs + (oneHour * offset));
}
function _formatDate (dateIsoString, offset) {
var dateStr = _offsetDate(dateIsoString, offset).toString();
var ind = dateStr.indexOf(' GMT');
return dateStr.substring(0, ind);
}
function getDataForEventRelated (templateName, context) {
var event, group, members;
var event, group, members, organizer;
return Promise.all([getEvent(context.eventId), getGroup(context.groupId), getGroupMembers(context.groupId)])
.then(function(results) {
event = results[0].result;
@ -122,6 +136,15 @@ function getDataForEventRelated (templateName, context) {
})
.then(function(organizerRes) {
var organizer = organizerRes.result;
var offset = organizer.TimezoneOffset;
if (event.EventDate) {
event.EventDate = _formatDate(event.EventDate, offset);
} else {
event.EventDateChoices = event.EventDateChoices.map(function(dateOption) {
return _formatDate(dateOption, offset);
});
}
var userData = filterForNotification(members);
var emailContext = {
Event: event,