mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ACA-4213] - Fix search datetime range in different timezones (#6732)
* Fix search datetime range in different timezones * Add unit test checking the conversion from GMT to UTC
This commit is contained in:
@@ -124,7 +124,7 @@ describe('SearchDatetimeRangeComponent', () => {
|
|||||||
expect(context.update).toHaveBeenCalled();
|
expect(context.update).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update query builder on value changes', () => {
|
it('should update the query in UTC format when values change', () => {
|
||||||
const context: any = {
|
const context: any = {
|
||||||
queryFragments: {},
|
queryFragments: {},
|
||||||
update() {
|
update() {
|
||||||
@@ -143,10 +143,34 @@ describe('SearchDatetimeRangeComponent', () => {
|
|||||||
to: toDatetime
|
to: toDatetime
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
const startDate = moment(fromDatetime).startOf('minute').format();
|
const expectedQuery = `cm:created:['2016-10-16T12:30:00Z' TO '2017-10-16T20:00:59Z']`;
|
||||||
const endDate = moment(toDatetime).endOf('minute').format();
|
|
||||||
|
|
||||||
const expectedQuery = `cm:created:['${startDate}' TO '${endDate}']`;
|
expect(context.queryFragments[component.id]).toEqual(expectedQuery);
|
||||||
|
expect(context.update).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to update the query in UTC format from a GMT format', () => {
|
||||||
|
const context: any = {
|
||||||
|
queryFragments: {},
|
||||||
|
update() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const fromInGmt = '2021-02-24T17:00:00+02:00';
|
||||||
|
const toInGmt = '2021-02-28T15:00:00+02:00';
|
||||||
|
|
||||||
|
component.id = 'createdDateRange';
|
||||||
|
component.context = context;
|
||||||
|
component.settings = { field: 'cm:created' };
|
||||||
|
|
||||||
|
spyOn(context, 'update').and.stub();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.apply({
|
||||||
|
from: fromInGmt,
|
||||||
|
to: toInGmt
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
const expectedQuery = `cm:created:['2021-02-24T15:00:00Z' TO '2021-02-28T13:00:59Z']`;
|
||||||
|
|
||||||
expect(context.queryFragments[component.id]).toEqual(expectedQuery);
|
expect(context.queryFragments[component.id]).toEqual(expectedQuery);
|
||||||
expect(context.update).toHaveBeenCalled();
|
expect(context.update).toHaveBeenCalled();
|
||||||
|
@@ -130,8 +130,8 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
|
|||||||
if (isValid && this.id && this.context && this.settings && this.settings.field) {
|
if (isValid && this.id && this.context && this.settings && this.settings.field) {
|
||||||
this.isActive = true;
|
this.isActive = true;
|
||||||
|
|
||||||
const start = moment(model.from).startOf('minute').format();
|
const start = moment.utc(model.from).startOf('minute').format();
|
||||||
const end = moment(model.to).endOf('minute').format();
|
const end = moment.utc(model.to).endOf('minute').format();
|
||||||
|
|
||||||
this.context.queryFragments[this.id] = `${this.settings.field}:['${start}' TO '${end}']`;
|
this.context.queryFragments[this.id] = `${this.settings.field}:['${start}' TO '${end}']`;
|
||||||
this.context.update();
|
this.context.update();
|
||||||
|
Reference in New Issue
Block a user