Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/heruan/humanize

Humanization libraries for Java.
https://github.com/heruan/humanize

i18n java time

Last synced: about 1 month ago
JSON representation

Humanization libraries for Java.

Awesome Lists containing this project

README

        

= Humanization libraries for Java

image:https://img.shields.io/github/release/heruan/humanize.svg[link=https://github.com/heruan/humanize/releases,title=Latest release]
image:https://img.shields.io/github/downloads/heruan/humanize/total.svg[link=https://github.com/heruan/humanize/archive/master.zip,title=GitHub]
image:https://img.shields.io/circleci/project/github/heruan/humanize.svg[link=https://circleci.com/gh/heruan/humanize,title=CricleCI]
image:https://img.shields.io/codecov/c/github/heruan/humanize.svg[link=https://codecov.io/gh/heruan/humanize,title=Codecov]
image:https://img.shields.io/github/license/heruan/humanize.svg[link=http://www.apache.org/licenses/LICENSE-2.0.html,title=Apache License 2.0]

== humanize-time

image:https://img.shields.io/maven-central/v/to.lova.humanize/humanize-time.svg[title=humanize-time]

Add the dependency to your `pom.xml`:

[source,xml]
----

to.lova.humanize
humanize-time
0.1.2

----

Use it in your code as simple as:

[source,java]
----
Temporal minutesAgo = ZonedDateTime.now().minus(5, ChronoUnit.MINUTES);
String relative = HumanizeTime.fromNow(minutesAgo);
// produces: "5 minutes ago"
----

By default it uses the locale provided by `Locale.getDefault()`, but you can request a different one or provide your own resolver:

[source,java]
----
Temporal minutesAgo = ZonedDateTime.now().minus(5, ChronoUnit.MINUTES);
Locale.setDefault(Locale.ITALIAN);
String italian = HumanizeTime.fromNow(temporal);
// produces: "5 minuti fa"
String french = HumanizeTime.fromNow(temporal, Locale.FRENCH);
// produces: "il y a 5 minutes"
String japanese = HumanizeTime.fromNow(temporal, () -> Locale.JAPANESE);
// produces: "5時間前"
----