Skip to content

Commit

Permalink
issue #10661 - fix: fixed PR review comments
Browse files Browse the repository at this point in the history
Made a class comment in CffDate.java
Replaced System.lineseparator() with OS.NEWLINE in CffDate.java
Added a final newline in cff.layout file
  • Loading branch information
jeanprbt committed Feb 27, 2024
1 parent e6b3179 commit 7a9de00
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
40 changes: 24 additions & 16 deletions src/main/java/org/jabref/logic/layout/format/CffDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,30 @@
import java.time.format.DateTimeParseException;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.logic.util.OS;

/**
* This class is used to parse dates for CFF exports. Since we do not know if the input String contains
* year, month and day, we must go through all these cases to return the best CFF format possible.
* Different cases are stated below.
* <p>
* Year, Month and Day contained => preferred-citation:
* date-released: yyyy-mm-dd
* <p>
* Year and Month contained => preferred-citation
* ...
* month: mm
* year: yyyy
* <p>
* Year contained => preferred-citation:
* ...
* year: yyyy
* <p>
* Poorly formatted => preferred-citation:
* ...
* issue-date: text-as-is
*/
public class CffDate implements LayoutFormatter {

/*
This class is used to parse dates for CFF exports. Since we do not know if the input String contains
year, month and day, we must go through all these cases to return the best CFF format possible.
Different cases are stated below.
Year, Month and Day contained => date-released: yyyy-mm-dd
Year and Month contained => month: mm
year: yyyy
Year contained => year: yyyy
Poorly formatted => issue-date: <fieldText>
*/

@Override
public String format(String fieldText) {
StringBuilder builder = new StringBuilder();
Expand All @@ -40,9 +49,8 @@ public String format(String fieldText) {
int year = yearMonth.getYear();
builder.append("month: ");
builder.append(month);
builder.append(System.lineSeparator());
builder.append(" ");
builder.append("year: ");
builder.append(OS.NEWLINE);
builder.append(" year: "); // Account for indent since we are in `preferred-citation` indentation block
builder.append(year);
} catch (DateTimeParseException f) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/resource/layout/cff.layout
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ preferred-citation:
\begin{abstract} abstract: \abstract\end{abstract}
\begin{doi} doi: \doi\end{doi}
\begin{volume} volume: \volume\end{volume}
\begin{url} url: "\url"\end{url}
\begin{url} url: "\url"\end{url}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.logic.layout.format;

import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.logic.util.OS;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -15,7 +16,7 @@ public class CffDateTest {
@BeforeEach
public void setUp() {
formatter = new CffDate();
newLine = System.lineSeparator();
newLine = OS.NEWLINE;
}

@Test
Expand Down

0 comments on commit 7a9de00

Please sign in to comment.