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'.
      TimeAgoParser​(PatternsHolder patternsHolder, java.time.OffsetDateTime now)
      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.
      • 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.
      • TimeAgoParser

        public TimeAgoParser​(PatternsHolder patternsHolder,
                             java.time.OffsetDateTime now)
        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.
        now - The current time
    • 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