From da5da33dc256a6fdba13dc9698209fc6a49a6961 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 23 Aug 2024 20:09:19 +0530 Subject: [PATCH] Weekday --- web/apps/photos/src/worker/search.worker.ts | 3 ++- web/packages/new/photos/services/search/index.ts | 5 ++++- web/packages/new/photos/services/search/types.ts | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web/apps/photos/src/worker/search.worker.ts b/web/apps/photos/src/worker/search.worker.ts index 73605432f6..41cc61d636 100644 --- a/web/apps/photos/src/worker/search.worker.ts +++ b/web/apps/photos/src/worker/search.worker.ts @@ -68,7 +68,7 @@ function isSearchedFile(file: EnteFile, search: Search) { } const isDateComponentsMatch = ( - { year, month, day }: SearchDateComponents, + { year, month, day, weekday }: SearchDateComponents, date: Date, ) => { // Components are guaranteed to have at least one component, so start by @@ -79,6 +79,7 @@ const isDateComponentsMatch = ( // JS getMonth is 0-indexed. if (match && month) match = date.getMonth() + 1 == month; if (match && day) match = date.getDate() == day; + if (match && weekday) match = date.getDay() == weekday; return match; }; diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts index 602546415a..4a2309e6bd 100644 --- a/web/packages/new/photos/services/search/index.ts +++ b/web/packages/new/photos/services/search/index.ts @@ -28,13 +28,16 @@ export const parseDateComponents = ( const year = component("year"); const month = component("month"); const day = component("day"); + const weekday = component("weekday"); + const components = { year, month, day, 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"; const formatter = new Intl.DateTimeFormat(undefined, format); const formattedDate = formatter.format(p.date()); - return { components: { year, month, day }, formattedDate }; + return { components, formattedDate }; }); diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts index c009e546c6..a33c7ac21e 100644 --- a/web/packages/new/photos/services/search/types.ts +++ b/web/packages/new/photos/services/search/types.ts @@ -25,6 +25,11 @@ export interface SearchDateComponents { * The day of the month (1 to 31), if the search string specified one. */ day?: number; + /** + * The day of the week (0 to 6, with Sunday being 0), if the search string + * specified one. + */ + weekday?: number; } /**