mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
[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:
@@ -50,14 +50,23 @@ public class OrderFormatDate implements OrderFormatDelegate
|
|||||||
{
|
{
|
||||||
public String makeSortString(String value, String language)
|
public String makeSortString(String value, String language)
|
||||||
{
|
{
|
||||||
|
int padding = 0;
|
||||||
int endYearIdx = value.indexOf("-");
|
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
|
// padding the value from left with 0 so that 87 -> 0087, 687-11-24
|
||||||
// -> 0687-11-24
|
// -> 0687-11-24
|
||||||
return String.format("%1$0"
|
return String.format("%1$0" + padding + "d", 0)
|
||||||
+ (length > 4 ? 4 - endYearIdx : 4 - length) + "d", 0)
|
|
||||||
+ value;
|
+ value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user