Skip to content

Commit 6f4ba94

Browse files
authored
Merge pull request #784 from nextcloud-libraries/docs/improve-get-first-day-typing
docs: improve return type of getFirstDay()
2 parents a958c04 + 23b3f08 commit 6f4ba94

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"files": ["**.ts"],
99
"rules": {
1010
"no-useless-constructor": "off",
11-
"@typescript-eslint/no-useless-constructor": "error"
11+
"@typescript-eslint/no-useless-constructor": "error",
12+
"jsdoc/require-returns-type": "off"
1213
}
1314
},
1415
{

lib/date.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import { getCanonicalLocale } from './locale'
88

99
declare let window: Nextcloud.v27.WindowWithGlobals
1010

11+
export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6
12+
1113
/**
1214
* Get the first day of the week
1315
*
14-
* @return {number}
16+
* @return The first day where 0 is Sunday, 1 is Monday etc.
1517
*/
16-
export function getFirstDay(): number {
18+
export function getFirstDay(): WeekDay {
1719
// Server rendered
1820
if (typeof window.firstDay !== 'undefined') {
19-
return window.firstDay
21+
return window.firstDay as WeekDay
2022
}
2123

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

3941
// Fallback to Monday

0 commit comments

Comments
 (0)