-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ refactor parameters timeZone & utcOffset
refactor runtime check & typings of exclusive parameters timeZone & utcOffset and Add getTimeZoneAndOffset function to utils.ts
- Loading branch information
1 parent
94e8aac
commit 1b33011
Showing
2 changed files
with
24 additions
and
10 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 |
---|---|---|
@@ -1,7 +1,25 @@ | ||
import { ExclusiveParametersError } from './errors'; | ||
import { Ranges } from './types/cron.types'; | ||
|
||
export const getRecordKeys = <K extends Ranges[keyof Ranges]>( | ||
record: Partial<Record<K, boolean>> | ||
) => { | ||
return Object.keys(record) as unknown as (keyof typeof record)[]; | ||
}; | ||
|
||
export const getTimeZoneAndOffset = ( | ||
timeZone?: string | null, | ||
utcOffset?: number | null | ||
) => { | ||
if (timeZone != null && utcOffset != null) { | ||
throw new ExclusiveParametersError('timeZone', 'utcOffset'); | ||
} | ||
|
||
if (timeZone != null) { | ||
return { timeZone, utcOffset: null }; | ||
} else if (utcOffset != null) { | ||
return { timeZone: null, utcOffset }; | ||
} else { | ||
return { timeZone: null, utcOffset: null }; | ||
} | ||
}; |