Class MomentsAgoDateFormatter


  • public class MomentsAgoDateFormatter
    extends java.lang.Object
    Improvement based on AZWEB-318.
    Since:
    3.2.1.0 6/19/2007
    Version:
    3.2.1.0 6/19/2007
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getMomentsAgoString​(java.util.Date pastDate)
      Returns "x ago on " by comparing the given pastDate with the current time.
      static java.lang.String getMomentsAgoString​(java.util.Date pastDate, java.text.DateFormat format)
      Returns "x ago on " by comparing the given pastDate with the current time.
      private static java.lang.String handleUnit​(java.util.Calendar then, java.util.Calendar now, java.lang.Integer field)
      Checks to see if the unit we're comparing is less than the difference of the given "then" and "now" dates in milliseconds.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ID_YEAR

        private static final java.lang.Integer ID_YEAR
      • ID_MONTH

        private static final java.lang.Integer ID_MONTH
      • ID_WEEK_OF_YEAR

        private static final java.lang.Integer ID_WEEK_OF_YEAR
      • ID_DAY

        private static final java.lang.Integer ID_DAY
      • ID_HOUR_OF_DAY

        private static final java.lang.Integer ID_HOUR_OF_DAY
      • ID_MINUTE

        private static final java.lang.Integer ID_MINUTE
      • ID_SECOND

        private static final java.lang.Integer ID_SECOND
      • MS_IN_YEAR

        private static final java.lang.Long MS_IN_YEAR
      • MS_IN_MONTH

        private static final java.lang.Long MS_IN_MONTH
      • MS_IN_WEEK

        private static final java.lang.Long MS_IN_WEEK
      • MS_IN_DAY

        private static final java.lang.Long MS_IN_DAY
      • MS_IN_HOUR

        private static final java.lang.Long MS_IN_HOUR
      • MS_IN_MINUTE

        private static final java.lang.Long MS_IN_MINUTE
      • MS_IN_SECOND

        private static final java.lang.Long MS_IN_SECOND
      • CONVERSION_MAP

        private static final java.util.Map CONVERSION_MAP
      • UNIT_MAP

        private static final java.util.Map UNIT_MAP
    • Constructor Detail

      • MomentsAgoDateFormatter

        public MomentsAgoDateFormatter()
    • Method Detail

      • getMomentsAgoString

        public static java.lang.String getMomentsAgoString​(java.util.Date pastDate,
                                                           java.text.DateFormat format)
        Returns "x ago on " by comparing the given pastDate with the current time. All formats are converted to GMT time. In the future the user might have their own locale, in which case we will display the time in their own locale (neat!)
        Parameters:
        pastDate - A date in the past
        format - The format for the pastDate
        Returns:
        "x ago on "
      • getMomentsAgoString

        public static java.lang.String getMomentsAgoString​(java.util.Date pastDate)
        Returns "x ago on " by comparing the given pastDate with the current time.
        Parameters:
        pastDate - A default locale date in the past
        Returns:
        "x ago"
      • handleUnit

        private static java.lang.String handleUnit​(java.util.Calendar then,
                                                   java.util.Calendar now,
                                                   java.lang.Integer field)
        Checks to see if the unit we're comparing is less than the difference of the given "then" and "now" dates in milliseconds.
        Parameters:
        then - The date we're evaluating
        now - The current time
        field - The field which we're evaluating ("units")
        Returns:
        null if then is 0 "units" from now, otherwise a displayable string that will notify the user how long ago then was from now.