MOBILE-3784 time: Fix time zone usage in ion-datetime
This commit is contained in:
		
							parent
							
								
									f172f9d8b6
								
							
						
					
					
						commit
						1a1e03bdd4
					
				| @ -31,7 +31,7 @@ | ||||
|                     <p class="item-heading" [core-mark-required]="true">{{ 'core.date' | translate }}</p> | ||||
|                 </ion-label> | ||||
|                 <ion-datetime formControlName="timestart" [placeholder]="'core.date' | translate" [displayFormat]="dateFormat" | ||||
|                     [max]="maxDate" [min]="minDate" display-timezone="utc"> | ||||
|                     [max]="maxDate" [min]="minDate"> | ||||
|                 </ion-datetime> | ||||
|                 <core-input-errors [control]="form.controls.timestart" [errorMessages]="errors"></core-input-errors> | ||||
|             </ion-item> | ||||
| @ -156,7 +156,7 @@ | ||||
|                     <ion-item *ngIf="form.controls.duration.value === 1"> | ||||
|                         <ion-label position="stacked"></ion-label> | ||||
|                         <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-item> | ||||
|                     <ion-item> | ||||
|  | ||||
| @ -45,6 +45,7 @@ import { CanLeave } from '@guards/can-leave'; | ||||
| import { CoreForms } from '@singletons/form'; | ||||
| import { CoreReminders, CoreRemindersService, CoreRemindersUnits } from '@features/reminders/services/reminders'; | ||||
| 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. | ||||
| @ -454,8 +455,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { | ||||
|     async submit(): Promise<void> { | ||||
|         // Validate data.
 | ||||
|         const formData = this.form.value; | ||||
|         const timeStartDate = CoreTimeUtils.convertToTimestamp(formData.timestart, true); | ||||
|         const timeUntilDate = CoreTimeUtils.convertToTimestamp(formData.timedurationuntil, true); | ||||
|         const timeStartDate = moment(formData.timestart).unix(); | ||||
|         const timeUntilDate = moment(formData.timedurationuntil).unix(); | ||||
|         const timeDurationMinutes = parseInt(formData.timedurationminutes || '', 10); | ||||
|         let error: string | undefined; | ||||
| 
 | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| <span *ngIf="inputMode && form" [formGroup]="form"> | ||||
|     <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" | ||||
|         [disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format" display-timezone="utc"> | ||||
|         [disabled]="searchMode && !searchFields!['f_'+field.id+'_z']" [displayFormat]="format"> | ||||
|     </ion-datetime> | ||||
|     <core-input-errors *ngIf="error && editMode" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors> | ||||
| 
 | ||||
|  | ||||
| @ -18,9 +18,9 @@ import { AuthEmailSignupProfileField } from '@features/login/services/login-help | ||||
| import { CoreUserProfileField } from '@features/user/services/user'; | ||||
| import { CoreUserProfileFieldHandler, CoreUserProfileFieldHandlerData } from '@features/user/services/user-profile-field-delegate'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { CoreTimeUtils } from '@services/utils/time'; | ||||
| import { makeSingleton } from '@singletons'; | ||||
| import { AddonUserProfileFieldDatetimeComponent } from '../../component/datetime'; | ||||
| import moment from 'moment-timezone'; | ||||
| 
 | ||||
| /** | ||||
|  * Datetime user profile field handlers. | ||||
| @ -61,7 +61,7 @@ export class AddonUserProfileFieldDatetimeHandlerService implements CoreUserProf | ||||
|             return { | ||||
|                 type: 'datetime', | ||||
|                 name: 'profile_field_' + field.shortname, | ||||
|                 value: CoreTimeUtils.convertToTimestamp(<string> formValues[name]), | ||||
|                 value: moment(<string> formValues[name]).unix(), | ||||
|             }; | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -261,23 +261,14 @@ export class CoreTimeUtilsProvider { | ||||
|     /** | ||||
|      * 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 applyOffset Whether to apply offset to date or not. | ||||
|      * @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 { | ||||
|         const timestamp = 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; | ||||
|         return moment(date).unix(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user