MOBILE-3784 time: Fix time zone usage in ion-datetime

main
Dani Palou 2022-11-11 08:40:09 +01:00
parent f172f9d8b6
commit 1a1e03bdd4
5 changed files with 11 additions and 19 deletions

View File

@ -31,7 +31,7 @@
<p class="item-heading" [core-mark-required]="true">{{ 'core.date' | translate }}</p> <p class="item-heading" [core-mark-required]="true">{{ 'core.date' | translate }}</p>
</ion-label> </ion-label>
<ion-datetime formControlName="timestart" [placeholder]="'core.date' | translate" [displayFormat]="dateFormat" <ion-datetime formControlName="timestart" [placeholder]="'core.date' | translate" [displayFormat]="dateFormat"
[max]="maxDate" [min]="minDate" display-timezone="utc"> [max]="maxDate" [min]="minDate">
</ion-datetime> </ion-datetime>
<core-input-errors [control]="form.controls.timestart" [errorMessages]="errors"></core-input-errors> <core-input-errors [control]="form.controls.timestart" [errorMessages]="errors"></core-input-errors>
</ion-item> </ion-item>
@ -156,7 +156,7 @@
<ion-item *ngIf="form.controls.duration.value === 1"> <ion-item *ngIf="form.controls.duration.value === 1">
<ion-label position="stacked"></ion-label> <ion-label position="stacked"></ion-label>
<ion-datetime formControlName="timedurationuntil" [max]="maxDate" [min]="minDate" <ion-datetime formControlName="timedurationuntil" [max]="maxDate" [min]="minDate"
[placeholder]="'addon.calendar.durationuntil' | translate" [displayFormat]="dateFormat" display-timezone="utc"> [placeholder]="'addon.calendar.durationuntil' | translate" [displayFormat]="dateFormat">
</ion-datetime> </ion-datetime>
</ion-item> </ion-item>
<ion-item> <ion-item>

View File

@ -45,6 +45,7 @@ import { CanLeave } from '@guards/can-leave';
import { CoreForms } from '@singletons/form'; import { CoreForms } from '@singletons/form';
import { CoreReminders, CoreRemindersService, CoreRemindersUnits } from '@features/reminders/services/reminders'; import { CoreReminders, CoreRemindersService, CoreRemindersUnits } from '@features/reminders/services/reminders';
import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu'; import { CoreRemindersSetReminderMenuComponent } from '@features/reminders/components/set-reminder-menu/set-reminder-menu';
import moment from 'moment-timezone';
/** /**
* Page that displays a form to create/edit an event. * Page that displays a form to create/edit an event.
@ -454,8 +455,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave {
async submit(): Promise<void> { async submit(): Promise<void> {
// Validate data. // Validate data.
const formData = this.form.value; const formData = this.form.value;
const timeStartDate = CoreTimeUtils.convertToTimestamp(formData.timestart, true); const timeStartDate = moment(formData.timestart).unix();
const timeUntilDate = CoreTimeUtils.convertToTimestamp(formData.timedurationuntil, true); const timeUntilDate = moment(formData.timedurationuntil).unix();
const timeDurationMinutes = parseInt(formData.timedurationminutes || '', 10); const timeDurationMinutes = parseInt(formData.timedurationminutes || '', 10);
let error: string | undefined; let error: string | undefined;

View File

@ -1,7 +1,7 @@
<span *ngIf="inputMode && form" [formGroup]="form"> <span *ngIf="inputMode && form" [formGroup]="form">
<span *ngIf="editMode" [core-mark-required]="field.required" class="core-mark-required"></span> <span *ngIf="editMode" [core-mark-required]="field.required" class="core-mark-required"></span>
<ion-datetime [formControlName]="'f_'+field.id" [placeholder]="'core.date' | translate" [max]="maxDate" [min]="minDate" <ion-datetime [formControlName]="'f_'+field.id" [placeholder]="'core.date' | translate" [max]="maxDate" [min]="minDate"
[disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format" display-timezone="utc"> [disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format">
</ion-datetime> </ion-datetime>
<core-input-errors *ngIf="error && editMode" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors> <core-input-errors *ngIf="error && editMode" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>

View File

@ -18,9 +18,9 @@ import { AuthEmailSignupProfileField } from '@features/login/services/login-help
import { CoreUserProfileField } from '@features/user/services/user'; import { CoreUserProfileField } from '@features/user/services/user';
import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@features/user/services/user-profile-field-delegate'; import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@features/user/services/user-profile-field-delegate';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreTimeUtils } from '@services/utils/time';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonUserProfileFieldDatetimeComponent } from '../../component/datetime'; import { AddonUserProfileFieldDatetimeComponent } from '../../component/datetime';
import moment from 'moment-timezone';
/** /**
* Datetime user profile field handlers. * Datetime user profile field handlers.
@ -61,7 +61,7 @@ export class AddonUserProfileFieldDatetimeHandlerService implements CoreUserProf
return { return {
type: 'datetime', type: 'datetime',
name: 'profile_field_' + field.shortname, name: 'profile_field_' + field.shortname,
value: CoreTimeUtils.convertToTimestamp(<string> formValues[name]), value: moment(<string> formValues[name]).unix(),
}; };
} }
} }

View File

@ -261,23 +261,14 @@ export class CoreTimeUtilsProvider {
/** /**
* Convert a text into user timezone timestamp. * Convert a text into user timezone timestamp.
* *
* @todo The `applyOffset` argument is only used as a workaround, it should be removed once
* MOBILE-3784 is resolved.
*
* @param date To convert to timestamp. * @param date To convert to timestamp.
* @param applyOffset Whether to apply offset to date or not. * @param applyOffset Whether to apply offset to date or not.
* @return Converted timestamp. * @return Converted timestamp.
* @deprecated since 4.1. Use moment(date).unix() instead.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
convertToTimestamp(date: string, applyOffset?: boolean): number { convertToTimestamp(date: string, applyOffset?: boolean): number {
const timestamp = moment(date).unix(); return moment(date).unix();
if (applyOffset !== undefined) {
return applyOffset ? timestamp - moment().utcOffset() * 60 : timestamp;
}
return typeof date == 'string' && date.slice(-1) == 'Z'
? timestamp - moment().utcOffset() * 60
: timestamp;
} }
/** /**