Class PrettyLocaledTexts

java.lang.Object
com.iizix.text.util.PrettyLocaledTexts

public class PrettyLocaledTexts extends Object
Utility functions to produce locale'd strings for durations and distances.
Author:
Christopher Mindus
  • Constructor Details

    • PrettyLocaledTexts

      public PrettyLocaledTexts(ILocaleString localeString)
      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

      public static PrettyLocaledTexts getDefault()
      Gets the system default instance for PrettyLocaledTexts.
    • decorateDuration

      public String decorateDuration(long duration, long now, int precision, int form)
      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 the precision not 0-5 or form is not 0-3.
    • decorateDistance

      public String decorateDistance(long distance, long here, int precision, int form)
      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 the precision is not 0-1 or form is not 0-2.