Skip to content

Instantly share code, notes, and snippets.

@jsjoeio
Created July 2, 2021 14:25
Show Gist options
  • Save jsjoeio/f3e5c0977714d23da4e0654645b7bd01 to your computer and use it in GitHub Desktop.
Save jsjoeio/f3e5c0977714d23da4e0654645b7bd01 to your computer and use it in GitHub Desktop.
opaque type example (DateInTimezone)
declare const _date: unique symbol
export type DateInTimezone = Date & { readonly [_date]: Date }
/**
* Checks if the date is between 12am and 4am
* of the day
*
* Returns true if it is, false otherwise
**/
export function isBetween12amAnd4am(date: DateInTimezone) {
const hours = date.getHours()
return hours >= 0 && hours < 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment