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

public Class GitTimeParser

extends Object
Class Inheritance
Imports
java.text.MessageFormat, .ParseException, java.time.Instant, .LocalDate, .LocalDateTime, java.time.format.DateTimeFormatter, .DateTimeParseException, java.time.temporal.ChronoField, .TemporalAccessor, java.util.EnumMap, .Map, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.internal.JGitText

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private static final Map<GitTimeParser.ParseableSimpleDateFormat, DateTimeFormatter>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LocalDateTime

Returns:

the parsed java.time.LocalDateTime
parse
(String
the string to be parsed
dateStr
)

Parses a string into a java.time.LocalDateTime using the default locale.

pack-priv static LocalDateTime
parse(String dateStr, LocalDateTime now)

public static Instant

Returns:

the parsed java.time.Instant
parseInstant
(String
the string to be parsed
dateStr
)

Parses a string into a java.time.Instant using the default locale.

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

Field Detail

formatCacheback to summary
private static final Map<GitTimeParser.ParseableSimpleDateFormat, DateTimeFormatter> formatCache

Constructor Detail

GitTimeParserback to summary
private GitTimeParser()

Method Detail

parseback to summary
public static LocalDateTime parse(String dateStr) throws ParseException

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

the string to be parsed

Returns:LocalDateTime

the parsed java.time.LocalDateTime

Exceptions
ParseException:
if the given dateStr was not recognized
parseback to summary
pack-priv static LocalDateTime parse(String dateStr, LocalDateTime now) throws ParseException
parseInstantback to summary
public static Instant parseInstant(String dateStr) throws ParseException

Parses a string into a java.time.Instant 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

Returns:Instant

the parsed java.time.Instant

Exceptions
ParseException:
if the given dateStr was not recognized
Since
7.2
parseRelativeback to summary
private static LocalDateTime parseRelative(String dateStr, LocalDateTime now)
Annotations
@SuppressWarnings:nls
@Nullable
parseSimpleback to summary
private static LocalDateTime parseSimple(String dateStr, GitTimeParser.ParseableSimpleDateFormat f) throws DateTimeParseException
org.eclipse.jgit.util back to summary

pack-priv final Enum GitTimeParser.ParseableSimpleDateFormat

extends Enum<GitTimeParser.ParseableSimpleDateFormat>
Class Inheritance

Field Summary

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

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

Constructor Detail

ParseableSimpleDateFormatback to summary
private ParseableSimpleDateFormat(String formatStr)

Method Detail

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