Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/lists/PeopleTimesheetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export default {
},

getWeekTitle(week) {
const beginning = moment(this.currentYear + '-' + week, 'YYYY-W')
const beginning = moment(this.year + '-' + week, 'YYYY-W')
const end = beginning.clone().add(6, 'days')
return beginning.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD')
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/Timesheets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default {

currentYear: moment().year(),
currentMonth: moment().month() + 1,
currentWeek: moment().week(),
currentWeek: moment().isoWeek(),
currentDay: moment().date(),
currentPerson: this.getCurrentPerson(),

Expand Down Expand Up @@ -441,7 +441,7 @@ export default {
this.currentMonth,
moment().year(),
moment().month() + 1,
moment().week()
moment().isoWeek()
)
},

Expand Down
20 changes: 8 additions & 12 deletions src/components/sides/PeopleTimesheetInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,21 @@ export default {
emits: ['close'],

computed: {
// Monday of the displayed ISO week, as aggregated by the backend.
weekStartDate() {
return moment(this.year + '-' + this.week, 'YYYY-W')
},

startDay() {
return moment().day('Monday').year(this.year).week(this.week).date()
return this.weekStartDate.date()
},

endDay() {
return moment()
.day('Monday')
.year(this.year)
.week(this.week)
.add(6, 'days')
.date()
return this.weekStartDate.clone().add(6, 'days').date()
},

weekMonth() {
return moment()
.day('Monday')
.year(this.year)
.week(this.week)
.format('MMM')
return this.weekStartDate.format('MMM')
},

monthString() {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ export const getDayRange = (year, month, currentYear, currentMonth) => {
}

export const getWeekRange = (year, currentYear) => {
if (currentYear === year) {
return range(1, moment().week())
const now = moment()
// Late December days can belong to ISO week 1 of the next year: only
// truncate the range at the current week when today's ISO week still
// belongs to the displayed year.
if (currentYear === year && now.isoWeekYear() <= year) {
return range(1, now.isoWeek())
} else {
return range(1, moment(String(year), 'YYYY').isoWeeksInYear())
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/lib/time.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe('time', () => {
vi.setSystemTime(new Date('2019-09-10T12:00:00Z'))
})

afterEach(() => {
vi.setSystemTime(new Date('2019-09-10T12:00:00Z'))
})

afterAll(() => {
vi.useRealTimers()
})
Expand Down Expand Up @@ -114,6 +118,16 @@ describe('time', () => {
expect(getWeekRange(2018, 2019)).toEqual(range(1, 52))
// 2019-09-10 (frozen clock) falls in week 37.
expect(getWeekRange(2019, 2019)).toEqual(range(1, 37))
// 2020 has 53 ISO weeks.
expect(getWeekRange(2020, 2026)).toEqual(range(1, 53))
// Regression #1928: 2025-12-30 belongs to ISO week 1 of 2026, all the
// weeks of 2025 must stay visible.
vi.setSystemTime(new Date('2025-12-30T12:00:00Z'))
expect(getWeekRange(2025, 2025)).toEqual(range(1, 52))
// 2027-01-01 belongs to ISO week 53 of 2026, where the backend files
// its hours in the 2027 table.
vi.setSystemTime(new Date('2027-01-01T12:00:00Z'))
expect(getWeekRange(2027, 2027)).toEqual(range(1, 53))
})

test('getDayRange', () => {
Expand Down