diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d21265e7d..97c4788b3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve to the page field for cases where the page numbers are missing. [#7019](https://github.com/JabRef/jabref/issues/7019) - We added a new fetcher to enable users to search jstor.org [#6627](https://github.com/JabRef/jabref/issues/6627) - We added an error message in the New Entry dialog that is shown in case the fetcher did not find anything . [#7000](https://github.com/JabRef/jabref/issues/7000) +- We added a new formatter to output shorthand month format. [#6579](https://github.com/JabRef/jabref/issues/6579) ### Changed diff --git a/src/main/java/org/jabref/logic/layout/LayoutEntry.java b/src/main/java/org/jabref/logic/layout/LayoutEntry.java index 8a1f6e7349f..658232eb72d 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/org/jabref/logic/layout/LayoutEntry.java @@ -74,6 +74,7 @@ import org.jabref.logic.layout.format.RisAuthors; import org.jabref.logic.layout.format.RisKeywords; import org.jabref.logic.layout.format.RisMonth; +import org.jabref.logic.layout.format.ShortMonthFormatter; import org.jabref.logic.layout.format.ToLowerCase; import org.jabref.logic.layout.format.ToUpperCase; import org.jabref.logic.layout.format.WrapContent; @@ -542,6 +543,8 @@ private LayoutFormatter getLayoutFormatterByName(String name) { return new MarkdownFormatter(); case "CSLType": return new CSLType(); + case "ShortMonth": + return new ShortMonthFormatter(); default: return null; } diff --git a/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java new file mode 100644 index 00000000000..63bef135801 --- /dev/null +++ b/src/main/java/org/jabref/logic/layout/format/ShortMonthFormatter.java @@ -0,0 +1,15 @@ +package org.jabref.logic.layout.format; + +import java.util.Optional; + +import org.jabref.logic.layout.LayoutFormatter; +import org.jabref.model.entry.Month; + +public class ShortMonthFormatter implements LayoutFormatter { + + @Override + public String format(String fieldText) { + Optional month = Month.parse(fieldText); + return month.map(Month::getShortName).orElse(""); + } +} diff --git a/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java new file mode 100644 index 00000000000..bcd17b9e518 --- /dev/null +++ b/src/test/java/org/jabref/logic/layout/format/ShortMonthFormatterTest.java @@ -0,0 +1,24 @@ +package org.jabref.logic.layout.format; + +import org.jabref.logic.layout.LayoutFormatter; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ShortMonthFormatterTest { + + private LayoutFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new ShortMonthFormatter(); + } + + @Test + public void testFormat() { + assertEquals("jan", formatter.format("01")); + assertEquals("jan", formatter.format("Januar")); + } +}