diff --git a/docs/src/pages/quasar-utils/date-utils.md b/docs/src/pages/quasar-utils/date-utils.md
index b36e4bc0795..3f8c2e52a7a 100644
--- a/docs/src/pages/quasar-utils/date-utils.md
+++ b/docs/src/pages/quasar-utils/date-utils.md
@@ -67,6 +67,7 @@ Available format tokens:
| Day of Week |
- **d**: 0 1 ... 5 6
- **do**: 0th 1st ... 5th 6th
- **dd**: Su Mo ... Fr Sa
- **ddd**: Sun Mon ... Fri Sat
- **dddd**: Sunday Monday ... Friday Saturday
|
| Day of Week (ISO) | |
| Week of Year | - **w**: 1 2 ... 52 53
- **wo**: 1st 2nd ... 52nd 53rd
- **ww**: 01 02 ... 52 53
|
+| ISO Week Year | - **GG**: 70 71 ... 29 30
- **GGGG**: 1970 1971 ... 2029 2030
|
| Hour | - **H**: 0 1 ... 22 23
- **HH**: 00 01 ... 22 23
- **h**: 0 ... 11 12
- **hh**: 01 02 ... 11 12
|
| Minute | - **m**: 0 1 ... 58 59
- **mm**: 00 01 ... 58 59
|
| Second | - **s**: 0 1 ... 58 59
- **ss**: 00 01 ... 58 59
|
@@ -307,6 +308,16 @@ const newDate = new Date(2017, 0, 4)
const week = date.getWeekOfYear(newDate) // `week` is 1
```
+To get the [ISO week year](https://en.wikipedia.org/wiki/ISO_week_date) for a given date object use:
+
+```js
+import { date } from 'quasar'
+
+const newDate = new Date(2022, 0, 1) // End of the last week of 2021
+const year = date.getISOWeekYear(newDate) // `year` is 2021
+const week = date.getWeekOfYear(newDate) // `week` is 52
+```
+
To get the day number in year for a given date object use:
```js
diff --git a/ui/src/utils/date/date.js b/ui/src/utils/date/date.js
index eed8b34d8b5..6d8d5726edf 100644
--- a/ui/src/utils/date/date.js
+++ b/ui/src/utils/date/date.js
@@ -509,6 +509,16 @@ export function getWeekOfYear (date) {
return 1 + Math.floor(weekDiff)
}
+export function getISOWeekYear (date) {
+ // Remove time components of date
+ const thursday = new Date(date.getFullYear(), date.getMonth(), date.getDate())
+
+ // Change date to Thursday same week
+ thursday.setDate(thursday.getDate() - ((thursday.getDay() + 6) % 7) + 3)
+
+ return thursday.getFullYear()
+}
+
function getDayIdentifier (date) {
return date.getFullYear() * 10000 + date.getMonth() * 100 + date.getDate()
}
@@ -762,6 +772,22 @@ const formatter = {
: date.getFullYear()
},
+ GG (date, dateLocale, forcedYear) {
+ // workaround for < 1900 with new Date()
+ const g = this.GGGG(date, dateLocale, forcedYear) % 100
+ return g >= 0
+ ? pad(g)
+ : '-' + pad(Math.abs(g))
+ },
+
+ // Year: 1900, 1901, ..., 2099
+ GGGG (date, _dateLocale, forcedYear) {
+ // workaround for < 1900 with new Date()
+ return forcedYear !== void 0 && forcedYear !== null
+ ? forcedYear
+ : getISOWeekYear(date)
+ },
+
// Month: 1, 2, ..., 12
M (date) {
return date.getMonth() + 1
@@ -1017,6 +1043,7 @@ export default {
buildDate,
getDayOfWeek,
getWeekOfYear,
+ getISOWeekYear,
isBetweenDates,
addToDate,
subtractFromDate,