Weekday
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 };
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user