Skip to content

Commit

Permalink
Merge branch 'w2p-119687_Solr-date-sort-field-format-check-7.2' into …
Browse files Browse the repository at this point in the history
…Solr-date-sort-field-format-check
  • Loading branch information
Atmire-Kristof committed Oct 31, 2024
2 parents ac51918 + 56becc6 commit 2bca8e3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dspace-api/src/main/java/org/dspace/sort/OrderFormatDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
*/
package org.dspace.sort;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* Standard date ordering delegate implementation. The only "special" need is
* to treat dates with less than 4-digit year.
*
* @author Andrea Bollini
*/
public class OrderFormatDate implements OrderFormatDelegate {
private final SimpleDateFormat yearIso = new SimpleDateFormat("yyyy");

@Override
public String makeSortString(String value, String language) {
if (!isValidDate(value)) {
return null;
}

int padding = 0;
int endYearIdx = value.indexOf('-');

Expand All @@ -34,4 +43,13 @@ public String makeSortString(String value, String language) {
return value;
}
}

private boolean isValidDate(String value) {
try {
yearIso.parse(value);
} catch (ParseException e) {
return false;
}
return true;
}
}

0 comments on commit 2bca8e3

Please sign in to comment.