Skip to content

armgit / ente

Public Imported from GitHub
0

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

Guarantees

Manav Rathi177d3dcccfbc
diff --git a/web/apps/photos/src/worker/search.worker.ts b/web/apps/photos/src/worker/search.worker.ts
index 41cc61d636..6308a8d3c5 100644
--- a/web/apps/photos/src/worker/search.worker.ts
+++ b/web/apps/photos/src/worker/search.worker.ts
@@ -71,8 +71,8 @@ const isDateComponentsMatch = (
{ year, month, day, weekday }: SearchDateComponents,
date: Date,
) => {
- // Components are guaranteed to have at least one component, so start by
- // assuming true.
+ // Components are guaranteed to have at least one attribute present, so
+ // start by assuming true.
let match = true;
if (year) match = date.getFullYear() == year;
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index 00ee4d4b77..26cce2f230 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -30,34 +30,39 @@ export const parseDateComponents = (s: string): DateSearchResult[] => {
};
export const parseChrono = (s: string): DateSearchResult[] =>
- chrono.parse(s).map((result) => {
- const p = result.start;
- const component = (s: Component) =>
- p.isCertain(s) ? nullToUndefined(p.get(s)) : undefined;
+ chrono
+ .parse(s)
+ .map((result) => {
+ const p = result.start;
+ const component = (s: Component) =>
+ p.isCertain(s) ? nullToUndefined(p.get(s)) : undefined;
- const year = component("year");
- const month = component("month");
- const day = component("day");
- const weekday = component("weekday");
- const components = { year, month, day, weekday };
+ const year = component("year");
+ const month = component("month");
+ const day = component("day");
+ const weekday = component("weekday");
- const format: Intl.DateTimeFormatOptions = {};
- if (year) format.year = "numeric";
- if (month) format.month = "long";
- if (day) format.day = "numeric";
- if (weekday) format.weekday = "long";
+ if (!year && !month && !day && !weekday) return undefined;
+ const components = { year, month, day, weekday };
- const formatter = new Intl.DateTimeFormat(undefined, format);
- const formattedDate = formatter.format(p.date());
- return { components, formattedDate };
- });
+ const format: Intl.DateTimeFormatOptions = {};
+ if (year) format.year = "numeric";
+ if (month) format.month = "long";
+ if (day) format.day = "numeric";
+ if (weekday) format.weekday = "long";
+
+ const formatter = new Intl.DateTimeFormat(undefined, format);
+ const formattedDate = formatter.format(p.date());
+ return { components, formattedDate };
+ })
+ .filter((x) => x !== undefined);
/** Parse a string like "2024" into a date search result. */
const parseYearComponents = (s: string): DateSearchResult[] => {
- // s is already trimmed
+ // s is already trimmed.
if (s.length == 4) {
const year = parseInt(s);
- if (year > 0 && year <= 9999) {
+ if (year && year <= 9999) {
const components = { year };
return [{ components, formattedDate: s }];
}
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index a33c7ac21e..458de6a8b9 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -8,8 +8,8 @@ import type { EnteFile } from "../../types/file";
/**
* 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.
+ * All attributes which were parsed will be set. The type doesn't enforce this,
+ * but it is guaranteed that at least one attribute will be present.
*/
export interface SearchDateComponents {
/**