-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da364e3
commit af4eafb
Showing
8 changed files
with
57 additions
and
38 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, it, expect, vi } from 'vitest' | ||
import { getCurrentSeason } from '@/lib/getCurrentSeason' | ||
|
||
|
||
describe('getCurrentSeason', () => { | ||
it('should return the correct season when its the year behind', () => { | ||
vi.useFakeTimers().setSystemTime(new Date('2023-10-10')) | ||
const season = getCurrentSeason() | ||
expect(season).toBe(2024) | ||
}) | ||
|
||
it('should return the correct season when its the current year', () => { | ||
vi.useFakeTimers().setSystemTime(new Date('2024-01-01')) | ||
const season = getCurrentSeason() | ||
expect(season).toBe(2024) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Returns the current season based on the current month and year. | ||
* If the current month is greater than or equal to August (8th month), | ||
* it returns the next year as the current season. | ||
* Otherwise, it returns the current year as the current season. | ||
* @returns The current season as a number. | ||
*/ | ||
export const getCurrentSeason = (): number => { | ||
const date = new Date() | ||
|
||
const currentMonth = date.getMonth() | ||
const currentyear = date.getFullYear() | ||
|
||
if (currentMonth >= 8) { | ||
return currentyear + 1 | ||
} | ||
return currentyear | ||
} |
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