#328128 Format dates according to event or user timezone. Fallback is UTC.

This commit is contained in:
Georgi Prodanov 2017-02-23 17:23:28 +02:00
Родитель 3fb9f7e316
Коммит db0aba6cf8
4 изменённых файлов: 15 добавлений и 16 удалений

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

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Data } from '../../node_modules/everlive-sdk/dist/declarations/everlive/types/Data';
import { Query } from '../../node_modules/everlive-sdk/dist/declarations/everlive/query/Query';
import * as jstz from 'jstz';
import { EverliveProvider } from './everlive-provider.service';
import { EventRegistrationsService } from './event-registrations.service';
@ -45,6 +46,7 @@ export class EventsService {
create(event: Event) {
this._clearExpandedFields(event);
(event as any).Timezone = jstz.determine().name();
return this._data.create(event);
}

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

@ -4,6 +4,7 @@ import { Users } from '../../node_modules/everlive-sdk/dist/declarations/everliv
import { User as ServerUser } from '../../node_modules/everlive-sdk/dist/declarations/everlive/interfaces/User';
import { User } from '../shared'
import { Observable, BehaviorSubject } from 'rxjs';
import * as jstz from 'jstz';
import { utilities } from '../shared';
@ -38,7 +39,7 @@ export class UsersService {
register(username: string, password: string, displayName: string) {
let attrs: any = { Email: username, DisplayName: displayName };
attrs.TimezoneOffset = (new Date()).getTimezoneOffset();
attrs.Timezone = jstz.determine().name();
return this._users.register(username, password, attrs);
}

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

@ -125,18 +125,13 @@ 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 || 0)));
}
function _formatDate (dateIsoString, offset) {
var dateStr = _offsetDate(dateIsoString, offset).toString();
var ind = dateStr.indexOf(' GMT');
return dateStr.substring(0, ind);
function _formatDate (dateIsoString, timezoneName) {
var moment = require('moment-timezone');
var result;
if (dateIsoString) {
result = moment.tz(dateIsoString, timezoneName).format('dddd, MMMM Do YYYY, h:mm:ss A');
}
return result;
}
function getDataForEventRelated (templateName, context) {
@ -151,12 +146,12 @@ function getDataForEventRelated (templateName, context) {
.then(function(organizerRes) {
var organizer = organizerRes.result;
event.Organizer = organizer.DisplayName;
var offset = organizer.TimezoneOffset;
var timezoneName = event.Timezone || organizer.Timezone;
if (event.EventDate) {
event.EventDate = _formatDate(event.EventDate, offset);
event.EventDate = _formatDate(event.EventDate, timezoneName);
} else {
event.EventDateChoices = event.EventDateChoices.map(function(dateOption) {
return _formatDate(dateOption, offset);
return _formatDate(dateOption, timezoneName);
});
}

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

@ -22,6 +22,7 @@
"@angular/platform-browser-dynamic": "2.4.6",
"@angular/router": "3.4.6",
"everlive-sdk": "1.9.2",
"jstz": "1.0.9",
"nativescript-angular": "1.4.0",
"nativescript-imagepicker": "~2.5.1",
"nativescript-permissions": "^1.2.0",