org.eclipse.jgit.util
Class GitDateParser

java.lang.Object
  extended by org.eclipse.jgit.util.GitDateParser

public class GitDateParser
extends Object

Parses strings with time and date specifications into Date. 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.


Field Summary
static Date NEVER
          The Date representing never.
 
Constructor Summary
GitDateParser()
           
 
Method Summary
static Date parse(String dateStr, Calendar now)
          Parses a string into a Date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEVER

public static final Date NEVER
The Date representing never. Though this is a concrete value, most callers are adviced to avoid depending on the actual value.

Constructor Detail

GitDateParser

public GitDateParser()
Method Detail

parse

public static Date parse(String dateStr,
                         Calendar now)
                  throws ParseException
Parses a string into a Date. Since this parser also supports relative formats (e.g. "yesterday") the caller can specify the reference date. These types of strings can be parsed:

Parameters:
dateStr - the string to be parsed
now - the base date which is used for the calculation of relative formats. E.g. if baseDate is "25.8.2012" then parsing of the string "1 week ago" would result in a date corresponding to "18.8.2012". This is used when a JGit command calls this parser often but wants a consistent starting point for calls.
If set to null then the current time will be used instead.
Returns:
the parsed Date
Throws:
ParseException - if the given dateStr was not recognized


Copyright © 2013. All Rights Reserved.