mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-7072] - added utc time for date time widget to avoid changing ti… (#7469)
* [AAE-7072] - added utc time for date time widget to avoid changing time on different timezones * [AAE-7072] - fixed parsing when override is not added
This commit is contained in:
@@ -305,7 +305,7 @@ describe('FormFieldModel', () => {
|
||||
});
|
||||
|
||||
const currentDateTime = moment(new Date());
|
||||
const expectedDateTime = moment(currentDateTime).format('YYYY-MM-DD HH:mm');
|
||||
const expectedDateTime = moment.utc(currentDateTime).format('YYYY-MM-DD HH:mm');
|
||||
const expectedDateTimeFormat = `${currentDateTime.utc().format('YYYY-MM-DDTHH:mm:00')}.000Z`;
|
||||
|
||||
expect(field.value).toBe(expectedDateTime);
|
||||
|
@@ -335,10 +335,10 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
if (NumberFieldValidator.isNumber(value)) {
|
||||
dateValue = moment(value);
|
||||
} else {
|
||||
dateValue = this.isDateTimeField(json) ? moment(value, 'YYYY-MM-DD hh:mm A') : moment(value.split('T')[0], 'YYYY-M-D');
|
||||
dateValue = this.isDateTimeField(json) ? moment.utc(value, 'YYYY-MM-DD hh:mm A') : moment.utc(value.split('T')[0], 'YYYY-M-D');
|
||||
}
|
||||
if (dateValue && dateValue.isValid()) {
|
||||
value = dateValue.format(this.dateDisplayFormat);
|
||||
value = dateValue.utc().format(this.dateDisplayFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,13 +415,13 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
break;
|
||||
case FormFieldTypes.DATETIME:
|
||||
if (typeof this.value === 'string' && this.value === 'now') {
|
||||
this.value = moment(new Date()).format(this.dateDisplayFormat);
|
||||
this.value = moment(new Date()).utc().format(this.dateDisplayFormat);
|
||||
}
|
||||
|
||||
const dateTimeValue = moment(this.value, this.dateDisplayFormat, true).utc();
|
||||
const dateTimeValue = moment.utc(this.value, this.dateDisplayFormat, true);
|
||||
if (dateTimeValue && dateTimeValue.isValid()) {
|
||||
/* cspell:disable-next-line */
|
||||
this.form.values[this.id] = `${dateTimeValue.format('YYYY-MM-DDTHH:mm:ss')}.000Z`;
|
||||
this.form.values[this.id] = `${dateTimeValue.utc().format('YYYY-MM-DDTHH:mm:ss')}.000Z`;
|
||||
} else {
|
||||
this.form.values[this.id] = null;
|
||||
this._value = this.value;
|
||||
|
@@ -67,11 +67,11 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
|
||||
|
||||
if (this.field) {
|
||||
if (this.field.minValue) {
|
||||
this.minDate = moment(this.field.minValue, 'YYYY-MM-DDTHH:mm:ssZ');
|
||||
this.minDate = moment.utc(this.field.minValue, 'YYYY-MM-DDTHH:mm:ssZ');
|
||||
}
|
||||
|
||||
if (this.field.maxValue) {
|
||||
this.maxDate = moment(this.field.maxValue, 'YYYY-MM-DDTHH:mm:ssZ');
|
||||
this.maxDate = moment.utc(this.field.maxValue, 'YYYY-MM-DDTHH:mm:ssZ');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
|
||||
onDateChanged(newDateValue) {
|
||||
const date = moment(newDateValue, this.field.dateDisplayFormat, true);
|
||||
if (date.isValid()) {
|
||||
this.field.value = date.format(this.field.dateDisplayFormat);
|
||||
this.field.value = moment(date).utc().local().format(this.field.dateDisplayFormat);
|
||||
} else {
|
||||
this.field.value = newDateValue;
|
||||
}
|
||||
|
@@ -136,7 +136,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
|
||||
displayFormat = this.overrideDisplayFormat ? this.overrideDisplayFormat : displayFormat;
|
||||
|
||||
if (date && date.format) {
|
||||
return date.format(displayFormat);
|
||||
return date.utc().local().format(displayFormat);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
@@ -44,7 +44,6 @@
|
||||
<mat-form-field fxFlex>
|
||||
<input matInput
|
||||
[matDatepicker]="taskDatePicker"
|
||||
(keydown)="true"
|
||||
(focusout)="onDateChanged($any($event).srcElement.value)"
|
||||
placeholder="{{'ADF_CLOUD_TASK_LIST.START_TASK.FORM.LABEL.DATE'|translate}}"
|
||||
[(ngModel)]="dueDate"
|
||||
|
Reference in New Issue
Block a user