-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8288 from jrjohnson/5908-first-week-year
Fix New Year Errors
- Loading branch information
Showing
5 changed files
with
200 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
import Component from '@glimmer/component'; | ||
import { DateTime } from 'luxon'; | ||
|
||
export default class DashboardWeekComponent extends Component { | ||
get expanded() { | ||
const now = DateTime.now(); | ||
const lastSunday = now.set({ weekday: 1 }).minus({ week: 1 }).toFormat('W'); | ||
const thisSunday = now.set({ weekday: 1 }).toFormat('W'); | ||
const nextSunday = now.set({ weekday: 1 }).plus({ week: 1 }).toFormat('W'); | ||
const lastSunday = this.thisThursday.minus({ week: 1 }).toFormat('W'); | ||
const thisSunday = this.thisThursday.toFormat('W'); | ||
const nextSunday = this.thisThursday.plus({ week: 1 }).toFormat('W'); | ||
|
||
return `${lastSunday}-${thisSunday}-${nextSunday}`; | ||
} | ||
|
||
get thisThursday() { | ||
const thursday = DateTime.fromObject({ | ||
weekday: 4, | ||
hour: 0, | ||
minute: 0, | ||
second: 0, | ||
}); | ||
|
||
// In this component the week always starts on Sunday, but luxon's starts on Monday | ||
// If today is sunday, we need to add a week to get the correct Thursday | ||
if (DateTime.now().weekday === 7) { | ||
return thursday.plus({ weeks: 1 }); | ||
} | ||
|
||
return thursday; | ||
} | ||
|
||
get year() { | ||
return DateTime.now().year; | ||
return this.thisThursday.weekYear; | ||
} | ||
|
||
get week() { | ||
const today = DateTime.now(); | ||
// In this component the week always starts on Sunday, but luxon's starts on Monday | ||
// so we need to adjust the week number to account for that. | ||
if (today.weekday === 7) { | ||
return today.weekNumber + 1; | ||
} else { | ||
return today.weekNumber; | ||
} | ||
return this.thisThursday.weekNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters