Introduce "never" as parseable date
For configuration parameter like "gc.pruneexpire" we need to understand the value "never". Never is handled as a date so far into the future that it will never happen. The actual value currently used is the constant GitDateParser.NEVER. Change-Id: I7744eaee9bf5026da517151c212c88325c348d6c Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
This commit is contained in:
parent
84e171fbab
commit
e0a3091af7
|
@ -76,6 +76,17 @@ public void yesterday() throws ParseException {
|
||||||
Assert.assertEquals(cal.getTime(), parse);
|
Assert.assertEquals(cal.getTime(), parse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void never() throws ParseException {
|
||||||
|
GregorianCalendar cal = new GregorianCalendar(SystemReader
|
||||||
|
.getInstance().getTimeZone(), SystemReader.getInstance()
|
||||||
|
.getLocale());
|
||||||
|
Date parse = GitDateParser.parse("never", cal);
|
||||||
|
Assert.assertEquals(GitDateParser.NEVER, parse);
|
||||||
|
parse = GitDateParser.parse("never", null);
|
||||||
|
Assert.assertEquals(GitDateParser.NEVER, parse);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void now() throws ParseException {
|
public void now() throws ParseException {
|
||||||
String dateStr = "2007-02-21 15:35:00 +0100";
|
String dateStr = "2007-02-21 15:35:00 +0100";
|
||||||
|
|
|
@ -62,6 +62,12 @@
|
||||||
* understands.
|
* understands.
|
||||||
*/
|
*/
|
||||||
public class GitDateParser {
|
public class GitDateParser {
|
||||||
|
/**
|
||||||
|
* The Date representing never. Though this is a concrete value, most
|
||||||
|
* callers are adviced to avoid depending on the actual value.
|
||||||
|
*/
|
||||||
|
public static final Date NEVER = new Date(Long.MAX_VALUE);
|
||||||
|
|
||||||
// Since SimpleDateFormat instances are expensive to instantiate they should
|
// Since SimpleDateFormat instances are expensive to instantiate they should
|
||||||
// be cached. Since they are also not threadsafe they are cached using
|
// be cached. Since they are also not threadsafe they are cached using
|
||||||
// ThreadLocal.
|
// ThreadLocal.
|
||||||
|
@ -113,6 +119,7 @@ private ParseableSimpleDateFormat(String formatStr) {
|
||||||
* relative formats (e.g. "yesterday") the caller can specify the reference
|
* relative formats (e.g. "yesterday") the caller can specify the reference
|
||||||
* date. These types of strings can be parsed:
|
* date. These types of strings can be parsed:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
* <li>"never"</li>
|
||||||
* <li>"now"</li>
|
* <li>"now"</li>
|
||||||
* <li>"yesterday"</li>
|
* <li>"yesterday"</li>
|
||||||
* <li>"(x) years|months|weeks|days|hours|minutes|seconds ago"<br>
|
* <li>"(x) years|months|weeks|days|hours|minutes|seconds ago"<br>
|
||||||
|
@ -146,6 +153,9 @@ public static Date parse(String dateStr, Calendar now)
|
||||||
throws ParseException {
|
throws ParseException {
|
||||||
dateStr = dateStr.trim();
|
dateStr = dateStr.trim();
|
||||||
Date ret;
|
Date ret;
|
||||||
|
|
||||||
|
if ("never".equalsIgnoreCase(dateStr))
|
||||||
|
return NEVER;
|
||||||
ret = parse_relative(dateStr, now);
|
ret = parse_relative(dateStr, now);
|
||||||
if (ret != null)
|
if (ret != null)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue