Skip to content

Commit 674528b

Browse files
committed
edited notes: better docstring for resolveDateParams
1 parent 8e09ed8 commit 674528b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

apps/server/src/routes/api/edited-notes.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,27 @@ interface DateValue {
111111
type DateFilter = DateValue;
112112

113113
/**
114-
* Resolves date keyword with optional delta (e.g., "TODAY-1") to date
115-
* @param dateStr date keyword (TODAY, MONTH, YEAR) or date in format YYYY-MM-DD (or beggining)
116-
* @returns
114+
* Resolves a date string into a concrete date representation.
115+
* The date string can be a keyword with an optional delta, or a standard date format.
116+
*
117+
* Supported keywords are:
118+
* - `today`: Resolves to the current date in `YYYY-MM-DD` format.
119+
* - `month`: Resolves to the current month in `YYYY-MM` format.
120+
* - `year`: Resolves to the current year in `YYYY` format.
121+
*
122+
* An optional delta can be appended to the keyword to specify an offset.
123+
* For example:
124+
* - `today-1` resolves to yesterday.
125+
* - `month+2` resolves to the month after next.
126+
* - `year-10` resolves to 10 years ago.
127+
*
128+
* If the `dateStr` does not match a keyword pattern, it is returned as is.
129+
* This is to support standard date formats like `YYYY-MM-DD`, `YYYY-MM`, or `YYYY`.
130+
*
131+
* @param dateStr A string representing the date. This can be a keyword
132+
* (e.g., "today", "month-1", "year+5") or a date string
133+
* (e.g., "2023-10-27", "2023-10", "2023").
134+
* @returns A `DateFilter` object containing the resolved date string.
117135
*/
118136
export function resolveDateParams(dateStr: string): DateFilter {
119137
const match = dateStr.match(/^(today|month|year)([+-]\d+)?$/i);

0 commit comments

Comments
 (0)