Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Durations can't be formatted with library #4

Open
buckett opened this issue Feb 12, 2019 · 1 comment
Open

Durations can't be formatted with library #4

buckett opened this issue Feb 12, 2019 · 1 comment

Comments

@buckett
Copy link
Contributor

buckett commented Feb 12, 2019

If you attempt to format an Instant with:

String duration = HumanizeTime.fromNow(Instant.now());

you get an error:

java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years
	at java.base/java.time.Instant.until(Instant.java:1156) ~[na:na]
	at java.base/java.time.temporal.ChronoUnit.between(ChronoUnit.java:272) ~[na:na]
	at to.lova.humanize.time.HumanizeTime.from(HumanizeTime.java:130) ~[humanize-time-0.1.2.jar:na]
	at to.lova.humanize.time.HumanizeTime.fromNow(HumanizeTime.java:119) ~[humanize-time-0.1.2.jar:na]
	at to.lova.humanize.time.HumanizeTime.fromNow(HumanizeTime.java:63) ~[humanize-time-0.1.2.jar:na]
	at to.lova.humanize.time.HumanizeTime.fromNow(HumanizeTime.java:41) ~[humanize-time-0.1.2.jar:na]
@heruan
Copy link
Owner

heruan commented Feb 12, 2019

Thank you for reporting this. It is a known issue with Instant, see for example: https://stackoverflow.com/questions/39907925/why-instant-does-not-support-operations-with-chronounit-years

Did you try using a ZonedDateTime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants