Fix filter for date values

TG-110 #ready-for-test

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/18/head
trivernis 3 years ago
parent c3b8304290
commit 79dad3af0b
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -28,9 +28,9 @@ export type PropertyQuery = PropertyQueryStatus
export type PropertyQueryStatus = { Status: FileStatus }; export type PropertyQueryStatus = { Status: FileStatus };
export type PropertyQueryFileSize = { FileSize: ValueComparator<number> }; export type PropertyQueryFileSize = { FileSize: ValueComparator<number> };
export type PropertyQueryImportedTime = { ImportedTime: ValueComparator<Date> }; export type PropertyQueryImportedTime = { ImportedTime: ValueComparator<string> };
export type PropertyQueryChangedTime = { ChangedTime: ValueComparator<Date> }; export type PropertyQueryChangedTime = { ChangedTime: ValueComparator<string> };
export type PropertyQueryCreatedTime = { CreatedTime: ValueComparator<Date> }; export type PropertyQueryCreatedTime = { CreatedTime: ValueComparator<string> };
export type PropertyQueryTagCount = { TagCount: ValueComparator<number> }; export type PropertyQueryTagCount = { TagCount: ValueComparator<number> };
export type PropertyQueryCd = { Cd: string }; export type PropertyQueryCd = { Cd: string };
export type PropertyQueryId = { Id: number }; export type PropertyQueryId = { Id: number };

@ -29,21 +29,21 @@ export class FilterQueryBuilder {
public static importedTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery { public static importedTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery {
return filterQuery({ return filterQuery({
ImportedTime: valuesToCompareEnum(date, comparator, ImportedTime: valuesToCompareEnum(formatDate(date)!!, comparator,
max_date formatDate(max_date)
) )
}); });
} }
public static changedTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery { public static changedTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery {
return filterQuery({ return filterQuery({
ChangedTime: valuesToCompareEnum(date, comparator, max_date) ChangedTime: valuesToCompareEnum(formatDate(date)!!, comparator, formatDate(max_date))
}); });
} }
public static createdTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery { public static createdTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery {
return filterQuery({ return filterQuery({
CreatedTime: valuesToCompareEnum(date, comparator, max_date) CreatedTime: valuesToCompareEnum(formatDate(date)!!, comparator, formatDate(max_date))
}); });
} }
@ -150,6 +150,7 @@ export class FilterQueryBuilder {
} }
break; break;
case "ImportedTime": case "ImportedTime":
console.debug(propertyName, rawComparator, compareValue);
value = this.parsePropertyValue(compareValue, parseDate); value = this.parsePropertyValue(compareValue, parseDate);
if (value != undefined) { if (value != undefined) {
return this.importedTime(value[0], comparator, value[1]); return this.importedTime(value[0], comparator, value[1]);
@ -263,7 +264,7 @@ function filterQuery(propertyQuery: PropertyQuery): FilterQuery {
return { Property: propertyQuery }; return { Property: propertyQuery };
} }
function valuesToCompareEnum<T>(min_value: T, comparator: Comparator, max_value?: T): ValueComparator<T> { function valuesToCompareEnum<T>(min_value: T, comparator: Comparator, max_value: T | undefined): ValueComparator<T> {
switch (comparator) { switch (comparator) {
case "Less": case "Less":
return { Less: min_value }; return { Less: min_value };
@ -299,9 +300,9 @@ function parseByteSize(value: string): number | undefined {
if (number) { if (number) {
for (const key of Object.keys(valueMappings)) { for (const key of Object.keys(valueMappings)) {
if (checkUnit(key)) { if (checkUnit(key)) {
console.log("key", key, "valueMapping", valueMappings[key]); console.debug("key", key, "valueMapping", valueMappings[key]);
number *= valueMappings[key]; number *= valueMappings[key];
console.log("number", number); console.debug("number", number);
break; break;
} }
} }
@ -311,7 +312,7 @@ function parseByteSize(value: string): number | undefined {
} }
function parseDate(value: string): Date | undefined { function parseDate(value: string): Date | undefined {
const date = Date.parse(value); const date = Date.parse(value.toUpperCase());
if (isNaN(date)) { if (isNaN(date)) {
return undefined; return undefined;
@ -331,3 +332,13 @@ function parseStatus(value: string): FileStatus | undefined {
return undefined; return undefined;
} }
} }
function formatDate(date?: Date): string | undefined {
if (date) {
const pad = (s: number) => s.toString().padStart(2, "0");
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
date.getMinutes())}:${pad(
date.getSeconds())}`;
}
return;
}

@ -40,19 +40,19 @@ export function propertyQueryToStringParts(propertyQuery: PropertyQuery): [strin
return [ return [
"ImportedTime", "ImportedTime",
getComparator(propertyQuery.ImportedTime), getComparator(propertyQuery.ImportedTime),
getValue(propertyQuery.ImportedTime).toISOString() getValue(propertyQuery.ImportedTime)
]; ];
} else if ("ChangedTime" in propertyQuery) { } else if ("ChangedTime" in propertyQuery) {
return [ return [
"ChangedTime", "ChangedTime",
getComparator(propertyQuery.ChangedTime), getComparator(propertyQuery.ChangedTime),
getValue(propertyQuery.ChangedTime).toISOString() getValue(propertyQuery.ChangedTime)
]; ];
} else if ("CreatedTime" in propertyQuery) { } else if ("CreatedTime" in propertyQuery) {
return [ return [
"CreatedTime", "CreatedTime",
getComparator(propertyQuery.CreatedTime), getComparator(propertyQuery.CreatedTime),
getValue(propertyQuery.CreatedTime).toISOString() getValue(propertyQuery.CreatedTime)
]; ];
} else if ("TagCount" in propertyQuery) { } else if ("TagCount" in propertyQuery) {
return [ return [

Loading…
Cancel
Save