import Decimal from "break_infinity.js" ; import { Notation } from "./notation" ; const HOURS = [ "🕛" , "🕐" , "🕑" , "🕒" , "🕓" , "🕔" , "🕕" , "🕖" , "🕗" , "🕘" , "🕙" , "🕚" ] ; const LOG12 = Math . log10 ( 12 ) ; export class ClockNotation extends Notation { public get name ( ) : string { return "Clock" ; } public get infinite ( ) : string { return "🕛🕡" ; } public formatUnder1000 ( value ) { return this . clockwise ( new Decimal ( value ) ) ; } public formatDecimal ( value ) { return this . clockwise ( value ) ; } private clockwise ( value ) { if ( value . lt ( 12 ) ) { return this . hour ( value . toNumber ( ) ) ; } const log = value . log10 ( ) / LOG12 ; let exponent = Math . floor ( log ) ; if ( log < 301 ) { const clockLow = ( 12 ** ( log - exponent + 1 ) - 12 ) / 11 ; if ( exponent < 13 ) { return this . hour ( exponent - 1 ) + this . hour ( clockLow ) ; } exponent -= 13 ; let prefix = "" ; if ( exponent >= 144 ) { prefix = this . hour ( 0 ) ; exponent -= 144 ; } return prefix + this . hour ( exponent / 12 ) + this . hour ( exponent % 12 ) + this . hour ( clockLow ) ; } exponent -= 301 ; let clockHigh = 1 ; while ( exponent >= 1728 ) { exponent = ( exponent - 1728 ) / 12 ; ++ clockHigh ; } return this . hour ( clockHigh ) + this . hour ( exponent / 144 ) + this . hour ( exponent % 144 / 12 ) + this . hour ( exponent % 12 ) ; } private hour ( number ) { return HOURS [ Math . max ( Math . min ( Math . floor ( number ) , 11 ) , 0 ) ] ; } }