-
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
117ba7c
commit 948fe52
Showing
10 changed files
with
139 additions
and
48 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
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,9 +1,12 @@ | ||
export { DateTime, Interval } from "luxon"; | ||
export * from "./types"; | ||
export * from "./calendar"; | ||
export * from "./format"; | ||
export * from "./parse"; | ||
export * from "./interval"; | ||
export * from "./month"; | ||
export * from "./parse"; | ||
export * from "./quarter"; | ||
export * from "./types"; | ||
export * from "./week"; | ||
export * from "./weekKey"; | ||
export * from "./year"; | ||
export * from "./yearQuarter"; | ||
export * from "./calendar"; |
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,16 @@ | ||
import { DateTime } from "luxon"; | ||
|
||
import { IfValid, isValid } from "./helpers"; | ||
|
||
/** | ||
return broadcast month (1-12) for a given date | ||
**/ | ||
export function getBroadcastMonth<IsValid extends boolean>( | ||
date: DateTime<IsValid>, | ||
): IfValid<IsValid, number> { | ||
if (!isValid(date)) { | ||
return null as IfValid<IsValid, number>; | ||
} | ||
|
||
return date.endOf("week").month as unknown as IfValid<IsValid, number>; | ||
} |
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,38 @@ | ||
import { DateTime } from "luxon"; | ||
|
||
import { IfValid, isValid } from "./helpers"; | ||
import { getBroadcastWeek } from "./week"; | ||
|
||
/** | ||
* returns broadcast quarter for a given date | ||
**/ | ||
export function getBroadcastQuarter<IsValid extends boolean>( | ||
date: DateTime<IsValid>, | ||
): IfValid<IsValid, number> { | ||
const week = getBroadcastWeek(date); | ||
if (!isValid(date) || week === null) { | ||
return null as IfValid<IsValid, number>; | ||
} | ||
|
||
const quarterLength = 13; | ||
return Math.min(Math.ceil(week / quarterLength), 4) as IfValid< | ||
IsValid, | ||
number | ||
>; | ||
} | ||
|
||
/** | ||
* returns broadcast [quarter, week] for a given date | ||
**/ | ||
export function getBroadcastQuarterWeek<IsValid extends boolean>( | ||
date: DateTime<IsValid>, | ||
): IfValid<IsValid, [number, number]> { | ||
const week = getBroadcastWeek(date); | ||
if (!isValid(date) || week === null) { | ||
return null as IfValid<IsValid, [number, number]>; | ||
} | ||
|
||
const quarterLength = 13; | ||
const quarter = Math.min(Math.ceil(week / quarterLength), 4); | ||
return [quarter, week] as IfValid<IsValid, [number, number]>; | ||
} |
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,19 @@ | ||
import { DateTime } from "luxon"; | ||
|
||
import { getBroadcastYearInterval } from "./interval"; | ||
import { IfValid, isValid } from "./helpers"; | ||
|
||
/** | ||
* returns broadcast year for a given date | ||
**/ | ||
export function getBroadcastYear<IsValid extends boolean>( | ||
date: DateTime<IsValid>, | ||
): IfValid<IsValid, number> { | ||
const yearInterval = getBroadcastYearInterval(date); | ||
|
||
if (!(yearInterval && isValid(yearInterval.end))) { | ||
return null as IfValid<IsValid, number>; | ||
} | ||
|
||
return yearInterval.end.get("year") as IfValid<IsValid, number>; | ||
} |
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