export type WeekdayStr = 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA' | 'SU' ; export const ALL_WEEKDAYS = [ 'MO' , 'TU' , 'WE' , 'TH' , 'FR' , 'SA' , 'SU' ] ; export class Weekday { public readonly weekday : number ; public readonly n ? : number ; constructor ( weekday , n ? ) { if ( n === 0 ) throw new Error ( "Can't create weekday with n == 0" ) ; this . weekday = weekday ; this . n = n ; } static fromStr ( str ) { return new Weekday ( ALL_WEEKDAYS . indexOf ( str ) ) ; } nth ( n ) { return this . n === n ? this : new Weekday ( this . weekday , n ) ; } equals ( other ) { return this . weekday === other . weekday && this . n === other . n ; } toString ( ) { let s = ALL_WEEKDAYS [ this . weekday ] ; if ( this . n ) s = ( this . n > 0 ? '+' : '' ) + String ( this . n ) + s ; return s ; } getJsWeekday ( ) { return this . weekday === 6 ? 0 : this . weekday + 1 ; } }