Skip to content

Commit

Permalink
Merge pull request #784 from nextcloud-libraries/docs/improve-get-fir…
Browse files Browse the repository at this point in the history
…st-day-typing

docs: improve return type of getFirstDay()
  • Loading branch information
susnux authored Feb 6, 2025
2 parents a958c04 + 23b3f08 commit 6f4ba94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"files": ["**.ts"],
"rules": {
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error"
"@typescript-eslint/no-useless-constructor": "error",
"jsdoc/require-returns-type": "off"
}
},
{
Expand Down
10 changes: 6 additions & 4 deletions lib/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import { getCanonicalLocale } from './locale'

declare let window: Nextcloud.v27.WindowWithGlobals

export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6

/**
* Get the first day of the week
*
* @return {number}
* @return The first day where 0 is Sunday, 1 is Monday etc.
*/
export function getFirstDay(): number {
export function getFirstDay(): WeekDay {
// Server rendered
if (typeof window.firstDay !== 'undefined') {
return window.firstDay
return window.firstDay as WeekDay
}

// Try to fallback to Intl
Expand All @@ -33,7 +35,7 @@ export function getFirstDay(): number {
const weekInfo: WeekInfo = intl.getWeekInfo?.() ?? intl.weekInfo
if (weekInfo) {
// Convert 1..7 to 0..6 format
return weekInfo.firstDay % 7
return weekInfo.firstDay % 7 as WeekDay
}

// Fallback to Monday
Expand Down

0 comments on commit 6f4ba94

Please sign in to comment.