Class TimeAgoParser


  • public class TimeAgoParser
    extends java.lang.Object
    A helper class that is meant to be used by services that need to parse durations such as 23 seconds and/or upload dates in the format 2 days ago or similar.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeAgoParser​(PatternsHolder patternsHolder)
      Creates a helper to parse upload dates in the format '2 days ago'.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DateWrapper parse​(java.lang.String textualDate)
      Parses a textual date in the format '2 days ago' into a Calendar representation which is then wrapped in a DateWrapper object.
      long parseDuration​(java.lang.String textualDuration)
      Parses a textual duration into a duration computer number.
      • Methods inherited from class java.lang.Object

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

      • TimeAgoParser

        public TimeAgoParser​(PatternsHolder patternsHolder)
        Creates a helper to parse upload dates in the format '2 days ago'.

        Instantiate a new TimeAgoParser every time you extract a new batch of items.

        Parameters:
        patternsHolder - An object that holds the "time ago" patterns, special cases, and the language word separator.
    • Method Detail

      • parse

        public DateWrapper parse​(java.lang.String textualDate)
                          throws ParsingException
        Parses a textual date in the format '2 days ago' into a Calendar representation which is then wrapped in a DateWrapper object.

        Beginning with days ago, the date is considered as an approximation.

        Parameters:
        textualDate - The original date as provided by the streaming service
        Returns:
        The parsed time (can be approximated)
        Throws:
        ParsingException - if the time unit could not be recognized
      • parseDuration

        public long parseDuration​(java.lang.String textualDuration)
                           throws ParsingException
        Parses a textual duration into a duration computer number.
        Parameters:
        textualDuration - the textual duration to parse
        Returns:
        the textual duration parsed, as a primitive long
        Throws:
        ParsingException - if the textual duration could not be parsed