[DS-265] Fix rare condition where if you had a 4 character value that contains a '-', it would use the length of the string to determine the padding, which would result in an attempt to use a 0 width specification.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@4250 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Graham Triggs
2009-09-09 21:23:36 +00:00
parent 4e0ac8e702
commit e1fe542237

View File

@@ -50,14 +50,23 @@ public class OrderFormatDate implements OrderFormatDelegate
{
public String makeSortString(String value, String language)
{
int padding = 0;
int endYearIdx = value.indexOf("-");
int length = value.length();
if (length < 4 || (endYearIdx >= 0 && endYearIdx < 4))
if (endYearIdx >= 0 && endYearIdx < 4)
{
padding = 4 - endYearIdx;
}
else if (value.length() < 4)
{
padding = 4 - value.length();
}
if (padding > 0)
{
// padding the value from left with 0 so that 87 -> 0087, 687-11-24
// -> 0687-11-24
return String.format("%1$0"
+ (length > 4 ? 4 - endYearIdx : 4 - length) + "d", 0)
return String.format("%1$0" + padding + "d", 0)
+ value;
}
else