public class GitDateParser
extends java.lang.Object
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.Modifier and Type | Class and Description |
---|---|
(package private) static class |
GitDateParser.ParseableSimpleDateFormat |
Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<java.util.Map<java.util.Locale,java.util.Map<GitDateParser.ParseableSimpleDateFormat,java.text.SimpleDateFormat>>> |
formatCache |
static java.util.Date |
NEVER
The Date representing never.
|
Constructor and Description |
---|
GitDateParser() |
Modifier and Type | Method and Description |
---|---|
private static java.text.SimpleDateFormat |
getDateFormat(GitDateParser.ParseableSimpleDateFormat f,
java.util.Locale locale) |
private static java.text.SimpleDateFormat |
getNewSimpleDateFormat(GitDateParser.ParseableSimpleDateFormat f,
java.util.Locale locale,
java.util.Map<GitDateParser.ParseableSimpleDateFormat,java.text.SimpleDateFormat> map) |
private static java.util.Date |
parse_relative(java.lang.String dateStr,
java.util.Calendar now) |
private static java.util.Date |
parse_simple(java.lang.String dateStr,
GitDateParser.ParseableSimpleDateFormat f,
java.util.Locale locale) |
static java.util.Date |
parse(java.lang.String dateStr,
java.util.Calendar now)
Parses a string into a
Date using the default locale. |
static java.util.Date |
parse(java.lang.String dateStr,
java.util.Calendar now,
java.util.Locale locale)
Parses a string into a
Date using the given locale. |
public static final java.util.Date NEVER
private static java.lang.ThreadLocal<java.util.Map<java.util.Locale,java.util.Map<GitDateParser.ParseableSimpleDateFormat,java.text.SimpleDateFormat>>> formatCache
private static java.text.SimpleDateFormat getDateFormat(GitDateParser.ParseableSimpleDateFormat f, java.util.Locale locale)
private static java.text.SimpleDateFormat getNewSimpleDateFormat(GitDateParser.ParseableSimpleDateFormat f, java.util.Locale locale, java.util.Map<GitDateParser.ParseableSimpleDateFormat,java.text.SimpleDateFormat> map)
public static java.util.Date parse(java.lang.String dateStr, java.util.Calendar now) throws java.text.ParseException
Date
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:
dateStr
- the string to be parsednow
- 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.null
then the current time will be used
instead.Date
java.text.ParseException
- if the given dateStr was not recognizedpublic static java.util.Date parse(java.lang.String dateStr, java.util.Calendar now, java.util.Locale locale) throws java.text.ParseException
Date
using the given 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:
dateStr
- the string to be parsednow
- 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.null
then the current time will be used
instead.locale
- locale to be used to parse the date stringDate
java.text.ParseException
- if the given dateStr was not recognizedprivate static java.util.Date parse_simple(java.lang.String dateStr, GitDateParser.ParseableSimpleDateFormat f, java.util.Locale locale) throws java.text.ParseException
java.text.ParseException
private static java.util.Date parse_relative(java.lang.String dateStr, java.util.Calendar now)