struct Time::Span

Overview

Extensions to the stdlib Time::Span struct.

Included Modules

Defined in:

time-span-humanize.cr

Instance Method Summary

Instance Method Detail

def humanize(io : IO) #

Humanize the time span, writing it into io. This method does not know about units other than second and its fractions.

1.second.humanize(STDOUT)         # => 1.0s
500.milliseconds.humanize(STDOUT) # => 500ms
5.minutes.humanize(STDOUT)        # => 300s
10.hours.humanize(STDOUT)         # => 36,000s

It's based on Johannes Müller's code found in crystal/src/benchmark/ips.cr.


[View source]
def humanize #

Humanize the time span, returning a String in human-readable format. See #humanize(io).


[View source]