Skip to content

Commit

Permalink
Added layout DateFormatter, see #1249 (#1584)
Browse files Browse the repository at this point in the history
* Added layout DateFormatter, see #1249

* Removed comment (sorry about that)
  • Loading branch information
oscargus committed Jul 15, 2016
1 parent aa721f0 commit cb2cde2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

### Changed
- [#1026](https://github.com/JabRef/jabref/issues/1026) JabRef does no longer delete user comments outside of BibTeX entries and strings
- [#1249](https://github.com/JabRef/jabref/issues/1249) Date layout formatter added

### Fixed
- Fixed [#1264](https://github.com/JabRef/jabref/issues/1264): S with caron does not render correctly
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/net/sf/jabref/logic/layout/format/DateFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.sf.jabref.logic.layout.format;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import net.sf.jabref.logic.layout.ParamLayoutFormatter;


public class DateFormatter implements ParamLayoutFormatter {

private String formatString = "yyyy-MM-dd"; // Use ISO-format as default


@Override
public String format(String fieldText) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatString);
LocalDate date = LocalDate.parse(fieldText, DateTimeFormatter.ISO_LOCAL_DATE);
return date.format(formatter);
}

@Override
public void setArgument(String arg) {
formatString = arg;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.sf.jabref.logic.layout.format;

import net.sf.jabref.logic.layout.ParamLayoutFormatter;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class DateFormatterTest {

private ParamLayoutFormatter formatter;

@Before
public void setUp() {
formatter = new DateFormatter();
}

@Test
public void testDefaultFormat() {
Assert.assertEquals("2016-07-15", formatter.format("2016-07-15"));
}

@Test
public void testRequestedFormat() {
formatter.setArgument("MM/yyyy");
Assert.assertEquals("07/2016", formatter.format("2016-07-15"));
}

}

0 comments on commit cb2cde2

Please sign in to comment.