Allow DATE_TIME IS operand to filter on a whole day (#17529)
Fixes: https://github.com/twentyhq/core-team-issues/issues/2027 We've replaced the DATE_TIME picker with DATE picker, and changed the logic to filter for complete day period. https://github.com/user-attachments/assets/ba7e1078-bab3-4c62-a803-d6a851f14b7d --------- Co-authored-by: Arun kumar <arunkumar@Aruns-MacBook-Air.local> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { Temporal } from 'temporal-polyfill';
|
||||
|
||||
import {
|
||||
FieldMetadataType,
|
||||
@@ -52,7 +53,6 @@ import {
|
||||
import { arrayOfStringsOrVariablesSchema } from '@/utils/filter/utils/validation-schemas/arrayOfStringsOrVariablesSchema';
|
||||
import { arrayOfUuidOrVariableSchema } from '@/utils/filter/utils/validation-schemas/arrayOfUuidsOrVariablesSchema';
|
||||
import { jsonRelationFilterValueSchema } from '@/utils/filter/utils/validation-schemas/jsonRelationFilterValueSchema';
|
||||
import { Temporal } from 'temporal-polyfill';
|
||||
|
||||
type FieldShared = {
|
||||
id: string;
|
||||
@@ -390,6 +390,43 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
|
||||
throw new Error(`Date filter is empty`);
|
||||
}
|
||||
|
||||
if (recordFilter.operand === RecordFilterOperand.IS) {
|
||||
const timeZone = filterValueDependencies.timeZone ?? 'UTC';
|
||||
|
||||
let parsedPlainDate = null;
|
||||
|
||||
try {
|
||||
parsedPlainDate = recordFilter.value.includes('T')
|
||||
? Temporal.Instant.from(recordFilter.value)
|
||||
.toZonedDateTimeISO(timeZone)
|
||||
.toPlainDate()
|
||||
: Temporal.PlainDate.from(recordFilter.value);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Cannot parse "${recordFilter.value}" for ${filterType} filter`,
|
||||
);
|
||||
}
|
||||
|
||||
const zonedDateTime = parsedPlainDate.toZonedDateTime(timeZone);
|
||||
const start = zonedDateTime.toInstant();
|
||||
const end = zonedDateTime.add({ days: 1 }).toInstant();
|
||||
|
||||
return {
|
||||
and: [
|
||||
{
|
||||
[correspondingFieldMetadataItem.name]: {
|
||||
gte: start.toString(),
|
||||
} as DateTimeFilter,
|
||||
},
|
||||
{
|
||||
[correspondingFieldMetadataItem.name]: {
|
||||
lt: end.toString(),
|
||||
} as DateTimeFilter,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const resolvedDateTime = Temporal.Instant.from(recordFilter.value);
|
||||
|
||||
switch (recordFilter.operand) {
|
||||
@@ -407,34 +444,6 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
|
||||
} as DateTimeFilter,
|
||||
};
|
||||
}
|
||||
case RecordFilterOperand.IS: {
|
||||
const start = resolvedDateTime
|
||||
.toZonedDateTimeISO('UTC')
|
||||
.with({
|
||||
second: 0,
|
||||
millisecond: 0,
|
||||
microsecond: 0,
|
||||
nanosecond: 0,
|
||||
})
|
||||
.toInstant();
|
||||
|
||||
const end = start.add({ minutes: 1 });
|
||||
|
||||
return {
|
||||
and: [
|
||||
{
|
||||
[correspondingFieldMetadataItem.name]: {
|
||||
lt: end.toString(),
|
||||
} as DateTimeFilter,
|
||||
},
|
||||
{
|
||||
[correspondingFieldMetadataItem.name]: {
|
||||
gte: start.toString(),
|
||||
} as DateTimeFilter,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user