[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:
arditdomi
2021-02-25 15:41:05 +00:00
committed by GitHub
parent 4653e10872
commit 42a5102e66
2 changed files with 30 additions and 6 deletions

View File

@@ -124,7 +124,7 @@ describe('SearchDatetimeRangeComponent', () => {
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 = {
queryFragments: {},
update() {
@@ -143,10 +143,34 @@ describe('SearchDatetimeRangeComponent', () => {
to: toDatetime
}, true);
const startDate = moment(fromDatetime).startOf('minute').format();
const endDate = moment(toDatetime).endOf('minute').format();
const expectedQuery = `cm:created:['2016-10-16T12:30:00Z' TO '2017-10-16T20:00:59Z']`;
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.update).toHaveBeenCalled();

View File

@@ -130,8 +130,8 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
if (isValid && this.id && this.context && this.settings && this.settings.field) {
this.isActive = true;
const start = moment(model.from).startOf('minute').format();
const end = moment(model.to).endOf('minute').format();
const start = moment.utc(model.from).startOf('minute').format();
const end = moment.utc(model.to).endOf('minute').format();
this.context.queryFragments[this.id] = `${this.settings.field}:['${start}' TO '${end}']`;
this.context.update();