Package com.iizix.text.util
Class PrettyLocaledTexts
java.lang.Object
com.iizix.text.util.PrettyLocaledTexts
Utility functions to produce locale'd strings for durations and distances.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionPrettyLocaledTexts
(ILocaleString localeString) Creates an instance of used for the application session and its locale.Method Summary
Modifier and TypeMethodDescriptiondecorateDistance
(long distance, long here, int precision, int form) Gets the distance.decorateDuration
(long duration, long now, int precision, int form) Gets the duration.static PrettyLocaledTexts
Gets the system default instance for PrettyLocaledTexts.
Constructor Details
PrettyLocaledTexts
Creates an instance of used for the application session and its locale. If the locale is changed, a new instance of this class should be retrieved.- Parameters:
localeString
- The locale string instance, null for system default.
Method Details
getDefault
Gets the system default instance for PrettyLocaledTexts.decorateDuration
Gets the duration.- Parameters:
duration
- The duration in seconds (absolute value is used).now
- The amount of seconds considered as "now".precision
- 0=seconds, 1=minutes, 2=hours, 3=days, 4=weeks, 5=years (of 365 days)form
- The form: 0=short, 1=medium, 2=long, 3=long with "one" as text.- Returns:
- The locale'd string.
- Throws:
IllegalArgumentException
- If theprecision
not 0-5 orform
is not 0-3.
decorateDistance
Gets the distance.If the distance is less than "here", "near" or "close by" is always returned, regardless of precision.
If precision is 1=kilometer and the distance is less than 1000, "less than a kilometer" is returned.
- Parameters:
distance
- The distance in meters (absolute value is used).here
- The amount of meters considered as "here" or "nearby".precision
- Precision: 0=meters, 1=kilometers.form
- The form: 0=short, 1=long, 2=long with "one" as text.- Returns:
- The locale'd string.
- Throws:
IllegalArgumentException
- If theprecision
is not 0-1 orform
is not 0-2.