Duration Format

A small library for producing human-readable string representations of time durations.

Лицензия

Лицензия

Категории

Категории

ORM Данные
Группа

Группа

hu.kazocsaba
Идентификатор

Идентификатор

duration-format
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Duration Format
A small library for producing human-readable string representations of time durations.
Ссылка на сайт

Ссылка на сайт

https://github.com/kazocsaba/duration-format
Система контроля версий

Система контроля версий

https://github.com/kazocsaba/duration-format.git

Скачать duration-format

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/hu.kazocsaba/duration-format/ -->
<dependency>
    <groupId>hu.kazocsaba</groupId>
    <artifactId>duration-format</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/hu.kazocsaba/duration-format/
implementation 'hu.kazocsaba:duration-format:1.0.0'
// https://jarcasting.com/artifacts/hu.kazocsaba/duration-format/
implementation ("hu.kazocsaba:duration-format:1.0.0")
'hu.kazocsaba:duration-format:jar:1.0.0'
<dependency org="hu.kazocsaba" name="duration-format" rev="1.0.0">
  <artifact name="duration-format" type="jar" />
</dependency>
@Grapes(
@Grab(group='hu.kazocsaba', module='duration-format', version='1.0.0')
)
libraryDependencies += "hu.kazocsaba" % "duration-format" % "1.0.0"
[hu.kazocsaba/duration-format "1.0.0"]

Зависимости

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.4

Модули Проекта

Данный проект не имеет модулей.

Duration format

This library provides the class DurationFormat that can be used to create string representations of time durations. The primary feature of the library is that the time unit is selected automatically based on the input. The following example outputs are created using the same configuration:

13 s 499 μs
93 m 6 s 486 ms

Using

The library resides in the central Maven repository with group ID hu.kazocsaba and artifact ID duration-format. If you use a project management system which can fetch dependencies from there, you can just add the library as a dependency. E.g. in Maven:

<dependency>
    <groupId>hu.kazocsaba</groupId>
    <artifactId>duration-format</artifactId>
    <version>a.b.c</version>
</dependency>

Example

Quick and dirty benchmarking:

long start = System.nanoTime();
// run something
long end = System.nanoTime();
System.out.println("Finished in " + new DurationFormat().format(end - start));

Customizing the behaviour:

DurationFormat durationFormat = new DurationFormat()
    .setDropInnerZeroes(false)
    .timeUnit(TimeUnit.MILLISECONDS)        // never display a time unit higher than milliseconds
    .timeUnitLevel(3);                      // allow milliseconds, microseconds, and nanoseconds

durationFormat.format(360);                 // -> "360 ns"
durationFormat.format(150000000);           // -> "1500 ms 0 μs 0 ns"
durationFormat.format(60001003);            // -> "60 ms 1 μs 3 ns"

durationFormat = new DurationFormat()
    .timeUnit(TimeUnit.SECONDS);            // always show the duration in seconds
                                            // .timeUnitLevel(1) is the default

durationFormat.format(360);                 // -> "0 s"
durationFormat.format(158334286578L);       // -> "158 s"

durationFormat = new DurationFormat()       // choose the time unit automatically
    .lowestTimeUnit(TimeUnit.MILLISECONDS); // but we're not interested in anything below milliseconds

durationFormat.format(360);                 // -> "0 ms"
durationFormat.format(1500401823);          // -> "1500 ms"
durationFormat.format(158334286578L);       // -> "3 m"

Версии библиотеки

Версия
1.0.0