-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
package net.sf.jabref.model.entry; | ||
|
||
import net.sf.jabref.logic.util.strings.StringUtil; | ||
|
||
import java.util.Calendar; | ||
|
||
public class YearUtil { | ||
|
||
private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR); | ||
|
||
|
||
/** | ||
* Will convert a two digit year using the following scheme (describe at | ||
* http://www.filemaker.com/help/02-Adding%20and%20view18.html): | ||
|
@@ -44,8 +41,8 @@ static String toFourDigitYear(String year, int thisYear) { | |
return year; | ||
} | ||
|
||
Integer yearNumber = StringUtil.intValueOfWithNull(year); | ||
if(yearNumber == null) { | ||
Integer yearNumber = intValueOfWithNull(year); | ||
if (yearNumber == null) { | ||
return year; | ||
} | ||
|
||
|
@@ -61,22 +58,42 @@ private static int toFourDigitYearWithInts(String year, int thisYear) { | |
return 0; | ||
} | ||
|
||
Integer yearNumber = StringUtil.intValueOfWithNull(year); | ||
if(yearNumber == null) { | ||
Integer yearNumber = intValueOfWithNull(year); | ||
if (yearNumber == null) { | ||
return 0; | ||
} | ||
|
||
return new Year(thisYear).toFourDigitYear(yearNumber); | ||
} | ||
|
||
private static Integer intValueOfWithNull(String str) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
simonharrer
Author
Contributor
|
||
int idx = 0; | ||
int end; | ||
boolean sign = false; | ||
char ch; | ||
|
||
if ((str == null) || ((end = str.length()) == 0) || ((((ch = str.charAt(0)) < '0') || (ch > '9')) && (!(sign = ch == '-') || (++idx == end) || ((ch = str.charAt(idx)) < '0') || (ch > '9')))) { | ||
return null; | ||
} | ||
|
||
int ival = 0; | ||
for (; ; ival *= 10) { | ||
ival += '0' - ch; | ||
if (++idx == end) { | ||
return sign ? ival : -ival; | ||
} | ||
if (((ch = str.charAt(idx)) < '0') || (ch > '9')) { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
private static class Year { | ||
|
||
private final int year; | ||
private final int century; | ||
private final int yearShort; | ||
|
||
|
||
public Year(int year) { | ||
this.year = year; | ||
this.yearShort = this.year % 100; | ||
|
3 comments
on commit e0380b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like the YearUtil class at all and I think it is obsolete, or at least its self created logic is obsolete.
As with the new Java 8 Release, there haven been important changes made to the Date-Logic.
Especially the new DateFormatters. Why don't use them instead of manually trying to do Date Arithmetic`?
http://www.tutorialspoint.com/java8/java8_datetime_api.htm
And here:
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ofPattern-java.lang.String-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this Year arithmetic cannot be easily handled with Java 8 classes, but you are welcome to try it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will look into that.
I really don't like this...I suspect moving YearUtil to logic is also not possible, right?