mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[HXCS-2988] fix dates in CardViweDateItemComponent (#9276)
* [HXCS-2988] fix dates in CardViweDateItemComponent * [HXCS-2988] remove utc conversion + refactoring * [HXCS-2988] force property.value to be Date object(s) * [HXCS-2988] format dates * [HXCS-2988] revert last commit * [HXCS-2988] update date-only tests --------- Co-authored-by: Adriano Costa <Adriano.Costa@hyland.comgit>
This commit is contained in:
@@ -24,7 +24,7 @@ import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { AppConfigService } from '../../../app-config/app-config.service';
|
||||
import { MatDatetimepickerInputEvent } from '@mat-datetimepicker/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
|
@@ -26,7 +26,6 @@ import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
import { TranslationService } from '../../../translation/translation.service';
|
||||
import { ADF_DATE_FORMATS, AdfDateFnsAdapter } from '../../../common/utils/date-fns-adapter';
|
||||
import { ADF_DATETIME_FORMATS, AdfDateTimeFnsAdapter } from '../../../common/utils/datetime-fns-adapter';
|
||||
import { DateFnsUtils } from '../../../common';
|
||||
import { isValid } from 'date-fns';
|
||||
|
||||
@Component({
|
||||
@@ -74,13 +73,9 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
|
||||
(this.dateAdapter as AdfDateFnsAdapter).displayFormat = 'MMM DD';
|
||||
|
||||
if (this.property.multivalued) {
|
||||
if (!this.property.value) {
|
||||
this.property.value = [];
|
||||
}
|
||||
this.initMultivaluedProperty();
|
||||
} else {
|
||||
if (this.property.value && !Array.isArray(this.property.value)) {
|
||||
this.valueDate = DateFnsUtils.localToUtc(new Date(this.property.value));
|
||||
}
|
||||
this.initSingleValueProperty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +98,11 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
|
||||
onDateChanged(event: MatDatetimepickerInputEvent<Date>) {
|
||||
if (event.value) {
|
||||
if (isValid(event.value)) {
|
||||
this.property.value = new Date(event.value);
|
||||
if (this.property.type === 'date') {
|
||||
this.property.value.setHours(0, 0, 0, 0);
|
||||
}
|
||||
this.valueDate = event.value;
|
||||
this.property.value = DateFnsUtils.utcToLocal(event.value);
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
@@ -127,7 +125,11 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
|
||||
addDateToList(event: MatDatetimepickerInputEvent<Date>) {
|
||||
if (event.value) {
|
||||
if (isValid(event.value) && this.property.multivalued && Array.isArray(this.property.value)) {
|
||||
this.property.value.push(DateFnsUtils.utcToLocal(event.value));
|
||||
const localDate = event.value;
|
||||
if (this.property.type === 'date') {
|
||||
localDate.setHours(0, 0, 0, 0);
|
||||
}
|
||||
this.property.value.push(localDate);
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
@@ -143,4 +145,30 @@ export class CardViewDateItemComponent extends BaseCardView<CardViewDateItemMode
|
||||
update() {
|
||||
this.cardViewUpdateService.update({ ...this.property } as CardViewDateItemModel, this.property.value);
|
||||
}
|
||||
|
||||
private initSingleValueProperty() {
|
||||
if (this.property.value && !Array.isArray(this.property.value)) {
|
||||
this.property.value = new Date(this.property.value);
|
||||
if (this.property.type === 'date') {
|
||||
this.property.value.setHours(0, 0, 0, 0);
|
||||
}
|
||||
this.valueDate = this.property.value;
|
||||
}
|
||||
}
|
||||
|
||||
private initMultivaluedProperty() {
|
||||
if (!this.property.value) {
|
||||
this.property.value = [];
|
||||
}
|
||||
if (Array.isArray(this.property.value) && this.property.value.length > 0) {
|
||||
this.property.value = this.property.value.map((date: Date) => {
|
||||
const localDate = new Date(date);
|
||||
if (this.property.type === 'date') {
|
||||
localDate.setHours(0, 0, 0, 0);
|
||||
}
|
||||
return localDate;
|
||||
});
|
||||
this.valueDate = this.property.value[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -225,8 +225,8 @@ describe('ProcessHeaderCloudComponent', () => {
|
||||
const lastModifiedElement = fixture.debugElement.query(By.css('[data-automation-id="header-lastModified"] .adf-property-value'));
|
||||
|
||||
expect(component.dateFormat).toEqual('full');
|
||||
expect(startedDateElement.nativeElement.innerText.trim()).toBe('Saturday, March 9, 2019 at 5:23:07 PM GMT+00:00');
|
||||
expect(lastModifiedElement.nativeElement.innerText.trim()).toBe('Saturday, March 9, 2019 at 5:23:07 PM GMT+00:00');
|
||||
expect(startedDateElement.nativeElement.innerText.trim()).toBe('Saturday, March 9, 2019 at 12:00:00 AM GMT+00:00');
|
||||
expect(lastModifiedElement.nativeElement.innerText.trim()).toBe('Saturday, March 9, 2019 at 12:00:00 AM GMT+00:00');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -503,7 +503,7 @@ describe('TaskHeaderCloudComponent', () => {
|
||||
const createdDateElement = fixture.debugElement.query(By.css('[data-automation-id="header-created"] .adf-property-value'));
|
||||
|
||||
expect(component.dateFormat).toEqual('full');
|
||||
expect(createdDateElement.nativeElement.innerText.trim()).toBe('Monday, December 17, 2018 at 12:00:55 PM GMT+00:00');
|
||||
expect(createdDateElement.nativeElement.innerText.trim()).toBe('Monday, December 17, 2018 at 12:00:00 AM GMT+00:00');
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user