Merge pull request #2058 from crazyserver/MOBILE-3068
MOBILE-1927 calendar: Fix timezone when adding eventsmain
commit
687c0d4e41
|
@ -423,8 +423,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
|
||||||
submit(): void {
|
submit(): void {
|
||||||
// Validate data.
|
// Validate data.
|
||||||
const formData = this.eventForm.value,
|
const formData = this.eventForm.value,
|
||||||
timeStartDate = new Date(formData.timestart),
|
timeStartDate = this.timeUtils.convertToTimestamp(formData.timestart),
|
||||||
timeUntilDate = this.timeUtils.datetimeToDate(formData.timedurationuntil),
|
timeUntilDate = this.timeUtils.convertToTimestamp(formData.timedurationuntil),
|
||||||
timeDurationMinutes = parseInt(formData.timedurationminutes || '', 10);
|
timeDurationMinutes = parseInt(formData.timedurationminutes || '', 10);
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
|
||||||
error = 'core.selectagroup';
|
error = 'core.selectagroup';
|
||||||
} else if (formData.eventtype == AddonCalendarProvider.TYPE_CATEGORY && !formData.categoryid) {
|
} else if (formData.eventtype == AddonCalendarProvider.TYPE_CATEGORY && !formData.categoryid) {
|
||||||
error = 'core.selectacategory';
|
error = 'core.selectacategory';
|
||||||
} else if (formData.duration == 1 && timeStartDate.getTime() > timeUntilDate.getTime()) {
|
} else if (formData.duration == 1 && timeStartDate > timeUntilDate) {
|
||||||
error = 'addon.calendar.invalidtimedurationuntil';
|
error = 'addon.calendar.invalidtimedurationuntil';
|
||||||
} else if (formData.duration == 2 && (isNaN(timeDurationMinutes) || timeDurationMinutes < 1)) {
|
} else if (formData.duration == 2 && (isNaN(timeDurationMinutes) || timeDurationMinutes < 1)) {
|
||||||
error = 'addon.calendar.invalidtimedurationminutes';
|
error = 'addon.calendar.invalidtimedurationminutes';
|
||||||
|
@ -453,7 +453,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
|
||||||
const data: any = {
|
const data: any = {
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
eventtype: formData.eventtype,
|
eventtype: formData.eventtype,
|
||||||
timestart: Math.floor(timeStartDate.getTime() / 1000),
|
timestart: timeStartDate,
|
||||||
description: {
|
description: {
|
||||||
text: formData.description,
|
text: formData.description,
|
||||||
format: 1
|
format: 1
|
||||||
|
@ -473,7 +473,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formData.duration == 1) {
|
if (formData.duration == 1) {
|
||||||
data.timedurationuntil = Math.floor(timeUntilDate.getTime() / 1000);
|
data.timedurationuntil = timeUntilDate;
|
||||||
} else if (formData.duration == 2) {
|
} else if (formData.duration == 2) {
|
||||||
data.timedurationminutes = formData.timedurationminutes;
|
data.timedurationminutes = formData.timedurationminutes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
import { Injectable, Injector } from '@angular/core';
|
import { Injectable, Injector } from '@angular/core';
|
||||||
import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@core/user/providers/user-profile-field-delegate';
|
import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@core/user/providers/user-profile-field-delegate';
|
||||||
|
import { CoreTimeUtilsProvider } from '@providers/utils/time';
|
||||||
import { AddonUserProfileFieldDatetimeComponent } from '../component/datetime';
|
import { AddonUserProfileFieldDatetimeComponent } from '../component/datetime';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +25,7 @@ export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFiel
|
||||||
name = 'AddonUserProfileFieldDatetime';
|
name = 'AddonUserProfileFieldDatetime';
|
||||||
type = 'datetime';
|
type = 'datetime';
|
||||||
|
|
||||||
constructor() {
|
constructor(protected timeUtils: CoreTimeUtilsProvider) {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,12 +51,10 @@ export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFiel
|
||||||
const name = 'profile_field_' + field.shortname;
|
const name = 'profile_field_' + field.shortname;
|
||||||
|
|
||||||
if (formValues[name]) {
|
if (formValues[name]) {
|
||||||
const milliseconds = new Date(formValues[name]).getTime();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
name: 'profile_field_' + field.shortname,
|
name: 'profile_field_' + field.shortname,
|
||||||
value: Math.round(milliseconds / 1000)
|
value: this.timeUtils.convertToTimestamp(formValues[name])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ $core-sidetab-size: 60px !default;
|
||||||
ion-app.app-root core-ion-tabs {
|
ion-app.app-root core-ion-tabs {
|
||||||
.tabbar {
|
.tabbar {
|
||||||
z-index: 101; // For some reason, the regular z-index isn't enough with our tabs, use a higher one.
|
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 {
|
.core-ion-tabs-loading {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
|
@ -308,22 +308,7 @@ export class CoreTimeUtilsProvider {
|
||||||
toDatetimeFormat(timestamp?: number): string {
|
toDatetimeFormat(timestamp?: number): string {
|
||||||
timestamp = timestamp || Date.now();
|
timestamp = timestamp || Date.now();
|
||||||
|
|
||||||
return this.userDate(timestamp, 'YYYY-MM-DDTHH:mm:ss.SSS', false);
|
return this.userDate(timestamp, 'YYYY-MM-DDTHH:mm:ss.SSS', false) + 'Z';
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -333,7 +318,11 @@ export class CoreTimeUtilsProvider {
|
||||||
* @return {number} Converted timestamp.
|
* @return {number} Converted timestamp.
|
||||||
*/
|
*/
|
||||||
convertToTimestamp(date: string): number {
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue