Merge pull request #2058 from crazyserver/MOBILE-3068

MOBILE-1927 calendar: Fix timezone when adding events
main
Juan Leyva 2019-08-19 13:00:50 +01:00 committed by GitHub
commit 687c0d4e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 27 deletions

View File

@ -423,8 +423,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
submit(): void {
// Validate data.
const formData = this.eventForm.value,
timeStartDate = new Date(formData.timestart),
timeUntilDate = this.timeUtils.datetimeToDate(formData.timedurationuntil),
timeStartDate = this.timeUtils.convertToTimestamp(formData.timestart),
timeUntilDate = this.timeUtils.convertToTimestamp(formData.timedurationuntil),
timeDurationMinutes = parseInt(formData.timedurationminutes || '', 10);
let error;
@ -436,7 +436,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
error = 'core.selectagroup';
} else if (formData.eventtype == AddonCalendarProvider.TYPE_CATEGORY && !formData.categoryid) {
error = 'core.selectacategory';
} else if (formData.duration == 1 && timeStartDate.getTime() > timeUntilDate.getTime()) {
} else if (formData.duration == 1 && timeStartDate > timeUntilDate) {
error = 'addon.calendar.invalidtimedurationuntil';
} else if (formData.duration == 2 && (isNaN(timeDurationMinutes) || timeDurationMinutes < 1)) {
error = 'addon.calendar.invalidtimedurationminutes';
@ -453,7 +453,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
const data: any = {
name: formData.name,
eventtype: formData.eventtype,
timestart: Math.floor(timeStartDate.getTime() / 1000),
timestart: timeStartDate,
description: {
text: formData.description,
format: 1
@ -473,7 +473,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
}
if (formData.duration == 1) {
data.timedurationuntil = Math.floor(timeUntilDate.getTime() / 1000);
data.timedurationuntil = timeUntilDate;
} else if (formData.duration == 2) {
data.timedurationminutes = formData.timedurationminutes;
}

View File

@ -14,6 +14,7 @@
// limitations under the License.
import { Injectable, Injector } from '@angular/core';
import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@core/user/providers/user-profile-field-delegate';
import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { AddonUserProfileFieldDatetimeComponent } from '../component/datetime';
/**
@ -24,7 +25,7 @@ export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFiel
name = 'AddonUserProfileFieldDatetime';
type = 'datetime';
constructor() {
constructor(protected timeUtils: CoreTimeUtilsProvider) {
// Nothing to do.
}
@ -50,12 +51,10 @@ export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFiel
const name = 'profile_field_' + field.shortname;
if (formValues[name]) {
const milliseconds = new Date(formValues[name]).getTime();
return {
type: 'datetime',
name: 'profile_field_' + field.shortname,
value: Math.round(milliseconds / 1000)
value: this.timeUtils.convertToTimestamp(formValues[name])
};
}
}

View File

@ -3,7 +3,6 @@ $core-sidetab-size: 60px !default;
ion-app.app-root core-ion-tabs {
.tabbar {
z-index: 101; // For some reason, the regular z-index isn't enough with our tabs, use a higher one.
height: 56px;
.core-ion-tabs-loading {
height: 100%;

View File

@ -308,22 +308,7 @@ export class CoreTimeUtilsProvider {
toDatetimeFormat(timestamp?: number): string {
timestamp = timestamp || Date.now();
return this.userDate(timestamp, 'YYYY-MM-DDTHH:mm:ss.SSS', false);
}
/**
* Convert the value of a ion-datetime to a Date.
*
* @param {string} value Value of ion-datetime.
* @return {Date} Date.
*/
datetimeToDate(value: string): Date {
if (typeof value == 'string' && value.slice(-1) == 'Z') {
// The value shoudln't have the timezone because it causes problems, remove it.
value = value.substr(0, value.length - 1);
}
return new Date(value);
return this.userDate(timestamp, 'YYYY-MM-DDTHH:mm:ss.SSS', false) + 'Z';
}
/**
@ -333,7 +318,11 @@ export class CoreTimeUtilsProvider {
* @return {number} Converted timestamp.
*/
convertToTimestamp(date: string): number {
return moment(date).unix() - (moment().utcOffset() * 60);
if (typeof date == 'string' && date.slice(-1) == 'Z') {
return moment(date).unix() - (moment().utcOffset() * 60);
}
return moment(date).unix();
}
/**