This commit is contained in:
Manav Rathi
2024-08-23 20:09:19 +05:30
parent 118b828ee5
commit da5da33dc2
3 changed files with 11 additions and 2 deletions

View File

@@ -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;
};

View File

@@ -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 };
});

View File

@@ -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;
}
/**