Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rename

Manav Rathia5ffb0f4bd44
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.ts
index 3736327e7e..27bbe574bc 100644
--- a/web/apps/photos/src/services/searchService.ts
+++ b/web/apps/photos/src/services/searchService.ts
@@ -9,7 +9,7 @@ import {
} from "@/new/photos/services/ml";
import { parsePotentialDate } from "@/new/photos/services/search";
import type {
- DateValue,
+ SearchDateComponents,
SearchPerson,
} from "@/new/photos/services/search/types";
import { EnteFile } from "@/new/photos/types/file";
@@ -217,13 +217,13 @@ function getDateSuggestion(searchPhrase: string): Suggestion[] {
}));
}
-export function getFormattedDate(date: DateValue) {
+export function getFormattedDate(date: SearchDateComponents) {
const options = {};
- date.date && (options["day"] = "numeric");
+ date.day && (options["day"] = "numeric");
(date.month || date.month === 0) && (options["month"] = "long");
date.year && (options["year"] = "numeric");
return new Intl.DateTimeFormat("en-IN", options).format(
- new Date(date.year ?? 1, date.month ?? 1, date.date ?? 1),
+ new Date(date.year ?? 1, date.month ?? 1, date.day ?? 1),
);
}
@@ -369,7 +369,7 @@ function convertSuggestionToSearchQuery(option: Suggestion): Search {
switch (option.type) {
case SuggestionType.DATE:
return {
- date: option.value as DateValue,
+ date: option.value as SearchDateComponents,
};
case SuggestionType.LOCATION:
diff --git a/web/apps/photos/src/types/search/index.ts b/web/apps/photos/src/types/search/index.ts
index ffa26fdd5e..4c0b901655 100644
--- a/web/apps/photos/src/types/search/index.ts
+++ b/web/apps/photos/src/types/search/index.ts
@@ -1,7 +1,7 @@
import { FileType } from "@/media/file-type";
import type { MLStatus } from "@/new/photos/services/ml";
import type {
- DateValue,
+ SearchDateComponents,
SearchPerson,
} from "@/new/photos/services/search/types";
import { EnteFile } from "@/new/photos/types/file";
@@ -25,7 +25,7 @@ export interface Suggestion {
type: SuggestionType;
label: string;
value:
- | DateValue
+ | SearchDateComponents
| number[]
| SearchPerson
| MLStatus
@@ -37,7 +37,7 @@ export interface Suggestion {
}
export type Search = {
- date?: DateValue;
+ date?: SearchDateComponents;
location?: LocationTagData;
city?: City;
collection?: number;
diff --git a/web/apps/photos/src/worker/search.worker.ts b/web/apps/photos/src/worker/search.worker.ts
index 3f30216852..e32a449dcf 100644
--- a/web/apps/photos/src/worker/search.worker.ts
+++ b/web/apps/photos/src/worker/search.worker.ts
@@ -1,4 +1,4 @@
-import type { DateValue } from "@/new/photos/services/search/types";
+import type { SearchDateComponents } from "@/new/photos/services/search/types";
import { EnteFile } from "@/new/photos/types/file";
import * as Comlink from "comlink";
import {
@@ -66,18 +66,19 @@ function isSearchedFile(file: EnteFile, search: Search) {
return false;
}
-const isSameDayAnyYear = (baseDate: DateValue) => (compareDate: Date) => {
- let same = true;
+const isSameDayAnyYear =
+ (baseDate: SearchDateComponents) => (compareDate: Date) => {
+ let same = true;
- if (baseDate.month || baseDate.month === 0) {
- same = baseDate.month === compareDate.getMonth();
- }
- if (same && baseDate.date) {
- same = baseDate.date === compareDate.getDate();
- }
- if (same && baseDate.year) {
- same = baseDate.year === compareDate.getFullYear();
- }
+ if (baseDate.month || baseDate.month === 0) {
+ same = baseDate.month === compareDate.getMonth();
+ }
+ if (same && baseDate.day) {
+ same = baseDate.day === compareDate.getDate();
+ }
+ if (same && baseDate.year) {
+ same = baseDate.year === compareDate.getFullYear();
+ }
- return same;
-};
+ return same;
+ };
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index b20256d932..660360b4e4 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -1,9 +1,11 @@
import * as chrono from "chrono-node";
-import type { DateValue } from "./types";
+import type { SearchDateComponents } from "./types";
const DIGITS = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
-export const parsePotentialDate = (humanDate: string): DateValue[] => {
+export const parsePotentialDate = (
+ humanDate: string,
+): SearchDateComponents[] => {
const date = chrono.parseDate(humanDate);
const date1 = chrono.parseDate(`${humanDate} 1`);
if (date !== null) {
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index 924b7a78df..8d4b71eab5 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -5,10 +5,23 @@
import type { EnteFile } from "../../types/file";
-export interface DateValue {
- date?: number;
- month?: number;
- year?: number;
+/**
+ * A parsed version of a potential natural language date time string.
+ *
+ * The components which were parsed will be set. The type doesn't enforce this,
+ * but at least one component will be present.
+ *
+ * e.g. "December 2022" will be parsed into a (year 2022, month 12, day
+ * undefined), while "22 December 2022" will be parsed into (year 2022, month
+ * 12, day 22).
+ */
+export interface SearchDateComponents {
+ /** The year, if the search string specified one. */
+ year: number | undefined;
+ /** The month, if the search string specified one. */
+ month: number | undefined;
+ /** The day of the month, if the search string specified one. */
+ day: number | undefined;
}
/**