ResourcesTimeUnit should be either immutable or not use maxQuantity and millisPerUnit in hashCode() #152
Closed
Description
Time units are used as keys in a LinkedHashMap
!
https://github.com/ocpsoft/prettytime/blob/master/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java#L68
As a result, if you do:
PrettyTime prettyTime = new PrettyTime();
prettyTime.getUnit(JustNow.class).setMaxQuantity(1000L * 2L);
prettyTime.format(new Date());
you will most probably get NPE because the TimeFormat
for JustNow
will not be found.
A workaround is to replace the unit:
PrettyTime prettyTime = new PrettyTime();
TimeFormat timeFormat = prettyTime.removeUnit(JustNow.class);
JustNow justNow = new JustNow();
justNow.setMaxQuantity(1000L * 2L);
prettyTime.registerUnit(justNow, timeFormat);
prettyTime.format(new Date());
Metadata
Assignees
Labels
No labels