Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util

public Class GitDateParser

extends Object
Class Inheritance
Annotations
@Deprecated
since:7.1
Imports
java.text.MessageFormat, .ParseException, .SimpleDateFormat, java.util.Calendar, .Date, .GregorianCalendar, .HashMap, .Locale, .Map, org.eclipse.jgit.internal.JGitText

Deprecated

since 7.1.

Use GitTimeParser instead.

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private static ThreadLocal<Map<Locale, Map<GitDateParser.ParseableSimpleDateFormat, SimpleDateFormat>>>
public static final Date
NEVER

The Date representing never.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static SimpleDateFormat
private static SimpleDateFormat
public static Date

Returns:

the parsed java.util.Date
parse
(String
the string to be parsed
dateStr
,
Calendar
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.
now
)

Parses a string into a java.util.Date using the default locale.

public static Date

Returns:

the parsed java.util.Date
parse
(String
the string to be parsed
dateStr
,
Calendar
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.
now
,
Locale
locale to be used to parse the date string
locale
)

Parses a string into a java.util.Date using the given locale.

private static Date
private static Date
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

formatCacheback to summary
private static ThreadLocal<Map<Locale, Map<GitDateParser.ParseableSimpleDateFormat, SimpleDateFormat>>> formatCache
NEVERback to summary
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

GitDateParserback to summary
public GitDateParser()

Method Detail

getDateFormatback to summary
private static SimpleDateFormat getDateFormat(GitDateParser.ParseableSimpleDateFormat f, Locale locale)
getNewSimpleDateFormatback to summary
private static SimpleDateFormat getNewSimpleDateFormat(GitDateParser.ParseableSimpleDateFormat f, Locale locale, Map<GitDateParser.ParseableSimpleDateFormat, SimpleDateFormat> map)
parseback to summary
public static Date parse(String dateStr, Calendar now) throws ParseException

Parses a string into a java.util.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:

  • "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:String

the string to be parsed

now:Calendar

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:Date

the parsed java.util.Date

Exceptions
ParseException:
if the given dateStr was not recognized
parseback to summary
public static Date parse(String dateStr, Calendar now, Locale locale) throws ParseException

Parses a string into a java.util.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:

  • "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:String

the string to be parsed

now:Calendar

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.

locale:Locale

locale to be used to parse the date string

Returns:Date

the parsed java.util.Date

Exceptions
ParseException:
if the given dateStr was not recognized
Since
3.2
parse_relativeback to summary
private static Date parse_relative(String dateStr, Calendar now)
Annotations
@SuppressWarnings:nls
parse_simpleback to summary
private static Date parse_simple(String dateStr, GitDateParser.ParseableSimpleDateFormat f, Locale locale) throws ParseException
org.eclipse.jgit.util back to summary

pack-priv final Enum GitDateParser.ParseableSimpleDateFormat

extends Enum<GitDateParser.ParseableSimpleDateFormat>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final GitDateParser.ParseableSimpleDateFormat
private final String
public static final GitDateParser.ParseableSimpleDateFormat
public static final GitDateParser.ParseableSimpleDateFormat
public static final GitDateParser.ParseableSimpleDateFormat
public static final GitDateParser.ParseableSimpleDateFormat
public static final GitDateParser.ParseableSimpleDateFormat
public static final GitDateParser.ParseableSimpleDateFormat
public static final GitDateParser.ParseableSimpleDateFormat

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static GitDateParser.ParseableSimpleDateFormat
public static GitDateParser.ParseableSimpleDateFormat[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULTback to summary
public static final GitDateParser.ParseableSimpleDateFormat DEFAULT
formatStrback to summary
private final String formatStr
ISOback to summary
public static final GitDateParser.ParseableSimpleDateFormat ISO
LOCALback to summary
public static final GitDateParser.ParseableSimpleDateFormat LOCAL
RFCback to summary
public static final GitDateParser.ParseableSimpleDateFormat RFC
SHORTback to summary
public static final GitDateParser.ParseableSimpleDateFormat SHORT
SHORT_WITH_DOTSback to summary
public static final GitDateParser.ParseableSimpleDateFormat SHORT_WITH_DOTS
SHORT_WITH_DOTS_REVERSEback to summary
public static final GitDateParser.ParseableSimpleDateFormat SHORT_WITH_DOTS_REVERSE
SHORT_WITH_SLASHback to summary
public static final GitDateParser.ParseableSimpleDateFormat SHORT_WITH_SLASH

Constructor Detail

ParseableSimpleDateFormatback to summary
private ParseableSimpleDateFormat(String formatStr)

Method Detail

valueOfback to summary
public static GitDateParser.ParseableSimpleDateFormat valueOf(String name)
valuesback to summary
public static GitDateParser.ParseableSimpleDateFormat[] values()