Class GitTimeParser

java.lang.Object
org.eclipse.jgit.util.GitTimeParser

public class GitTimeParser extends Object
Parses strings with time and date specifications into Instant. When git needs to parse strings specified by the user this parser can be used. One example is the parsing of the config parameter gc.pruneexpire. The parser can handle only subset of what native gits approxidate parser understands.
Since:
7.1
  • Method Details

    • parse

      public static LocalDateTime parse(String dateStr) throws ParseException
      Parses a string into a LocalDateTime using the default locale. Since this parser also supports relative formats (e.g. "yesterday") the caller can specify the reference date. These types of strings can be parsed:
      • "never"
      • "now"
      • "yesterday"
      • "(x) years|months|weeks|days|hours|minutes|seconds ago"
        Multiple specs can be combined like in "2 weeks 3 days ago". Instead of ' ' one can use '.' to separate the words
      • "yyyy-MM-dd HH:mm:ss Z" (ISO)
      • "EEE, dd MMM yyyy HH:mm:ss Z" (RFC)
      • "yyyy-MM-dd"
      • "yyyy.MM.dd"
      • "MM/dd/yyyy",
      • "dd.MM.yyyy"
      • "EEE MMM dd HH:mm:ss yyyy Z" (DEFAULT)
      • "EEE MMM dd HH:mm:ss yyyy" (LOCAL)
      Parameters:
      dateStr - the string to be parsed
      Returns:
      the parsed LocalDateTime
      Throws:
      ParseException - if the given dateStr was not recognized