Class TimeAgoParser

java.lang.Object
org.schabi.newpipe.extractor.localization.TimeAgoParser

public class TimeAgoParser extends 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 Details

    • TimeAgoParser

      public TimeAgoParser(PatternsHolder patternsHolder, LocalDateTime 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 Details

    • parse

      public DateWrapper parse(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