You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, about about porting over your PrettyDurationinternal class in Akka to this library? It's something I repeatedly copy/paste because it's so handy for logging and annoying to code 😉
How about something along the lines of (not systematically tested):
importjava.util.Localeimportcom.markatta.timeforscala.{ Duration, Nanos, TimeUnit }
importscala.concurrent.duration.{ DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS, SECONDS }
objectPrettyDuration {
implicitclassPrettyPrintableDuration(valduration:Duration) extendsAnyVal {
/** Selects most appropriate TimeUnit for given duration and formats it accordingly, with 4 digits precision **/defpretty:String= pretty(includeNanos =false)
/** Selects most appropriate TimeUnit for given duration and formats it accordingly */defpretty(includeNanos: Boolean, precision: Int=4):String= {
require(precision >0, "precision must be > 0")
duration match {
cased: Duration=>valnanos= d.toNanos
valunit= chooseUnit(nanos)
valvalue= nanos.toDouble /NANOSECONDS.convert(1, unit)
s"%.${precision}g %s%s".formatLocal(
Locale.ROOT,
value,
abbreviate(unit),
if (includeNanos) s" ($nanos ns)"else""
)
case _ =>"undefined"
}
}
defchooseUnit(nanos: Long):TimeUnit= {
vald=Nanos(nanos)
if (d.toDays >0) DAYSelseif (d.toHours >0) HOURSelseif (d.toMinutes >0) MINUTESelseif (d.getSeconds >0) SECONDSelseif (d.toMillis >0) MILLISECONDSelseif (d.toNanos /1000>0) MICROSECONDSelseNANOSECONDS
}
defabbreviate(unit: TimeUnit):String= unit match {
caseNANOSECONDS=>"ns"caseMICROSECONDS=>"μs"caseMILLISECONDS=>"ms"caseSECONDS=>"s"caseMINUTES=>"min"caseHOURS=>"h"caseDAYS=>"d"
}
}
}
The text was updated successfully, but these errors were encountered:
Hey, about about porting over your
PrettyDuration
internal class in Akka to this library? It's something I repeatedly copy/paste because it's so handy for logging and annoying to code 😉How about something along the lines of (not systematically tested):
The text was updated successfully, but these errors were encountered: