Skip to content

Add support for date ranges for BibLaTeX Date#14289

Closed
Alex1034 wants to merge 27 commits intoJabRef:mainfrom
Alex1034:feature/date-range
Closed

Add support for date ranges for BibLaTeX Date#14289
Alex1034 wants to merge 27 commits intoJabRef:mainfrom
Alex1034:feature/date-range

Conversation

@Alex1034
Copy link
Copy Markdown

@Alex1034 Alex1034 commented Nov 11, 2025

Closes #8902

Summary

This pull request adds support for date ranges in BibLaTeX date fields.

Previously, JabRef only supported single dates (e.g., 2021-05-03).
With this change, JabRef now correctly parses and formats date ranges (e.g., 2020/2021, 2015-01-01/2016-12-31) in compliance with ISO 690 and BibLaTeX standards.

Steps to test

  1. Open the entry editor and locate the Date field.
  2. Try entering a date range, e.g.:
    • 2020/2021
    • 2021-05-01/2021-06-30
  3. Save and reopen the entry.
  4. Confirm that both start and end dates are parsed and displayed correctly.
  5. Export the entry to ensure the field is saved as date = {2020/2021}.

Additional details

  • Updated Date.java to normalize and handle start/end dates.
  • Updated DateEditorViewModel.java to correctly format and display date ranges.
  • Added normalization for incomplete date ranges (e.g., "2010/" → "2010").
  • Updated CHANGELOG.md under the [Unreleased] section.

Changelog

  • I have modified CHANGELOG.md appropriately.

PR Checklist

  • I have followed the contributing guidelines
  • I have written tests for the change
  • I have added an entry to the changelog
  • I have manually tested the change in JabRef
  • My code follows the project’s code style and passes existing tests
  • I have considered security implications

Mandatory checks

  • [/] I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • I described the change in CHANGELOG.md in a way that is understandable for the average user (if change is visible to the user)
  • I checked the user documentation.(no changes needed)

@github-actions
Copy link
Copy Markdown
Contributor

Hey @Alex1034!

Thank you for contributing to JabRef! Your help is truly appreciated ❤️.

We have automatic checks in place, based on which you will soon get automated feedback if any of them are failing. We also use TragBot with custom rules that scans your changes and provides some preliminary comments, before a maintainer takes a look. TragBot is still learning, and may not always be accurate. In the "Files changed" tab, you can go through its comments and just click on "Resolve conversation" if you are sure that it is incorrect, or comment on the conversation if you are doubtful.

Please re-check our contribution guide in case of any other doubts related to our contribution workflow.

@Override
public TemporalAccessor fromString(String string) {
if (StringUtil.isNotBlank(string)) {
// ✅ Sanitize incomplete ranges (e.g., "2010/" → "2010")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this AI comment

@calixtus calixtus changed the title [PATCH] Added support for date ranges for BibLaTeX Date Add support for date ranges for BibLaTeX Date Nov 15, 2025
Copy link
Copy Markdown
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Tests are missing
  • CHANGELOG.md entry missing

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Nov 20, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Nov 20, 2025
@koppor koppor added the status: changes-required Pull requests that are not yet complete label Nov 21, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Nov 23, 2025
Comment on lines +58 to +71
private String sanitizeIncompleteRange(String dateString) {
String trimmed = dateString.trim();

if (trimmed.endsWith("/") && !trimmed.matches(".*\\d+/\\d+.*")) {
LOGGER.debug("Sanitizing incomplete range (trailing slash): {}", trimmed);
return trimmed.substring(0, trimmed.length() - 1).trim();
}

if (trimmed.startsWith("/") && !trimmed.matches(".*\\d+/\\d+.*")) {
LOGGER.debug("Sanitizing incomplete range (leading slash): {}", trimmed);
return trimmed.substring(1).trim();
}

return dateString;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a logic part, not a gui part. Please search for an appropriate place in the logic package.

I would assume near org.jabref.model.entry.Date

private DateEditorViewModel viewModel;
private StringConverter<TemporalAccessor> dateToStringConverter;

private TemporalAccessor sentinel() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a constant. Also needs to have a comment.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Nov 23, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Nov 23, 2025
@koppor koppor added the status: changes-required Pull requests that are not yet complete label Nov 28, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 1, 2025

Your pull request conflicts with the target branch.

Please merge with your code.
For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line.

@calixtus calixtus added the dev: code-quality Issues related to code or architecture decisions label Dec 12, 2025
@calixtus calixtus self-assigned this Dec 12, 2025
@calixtus
Copy link
Copy Markdown
Member

@Alex1034 Please check the license checkbox in the mandatory checks section in the PR description. Otherwise this PR will be closed.

@JabRef JabRef deleted a comment from jabref-machine Dec 22, 2025
@jabref-machine
Copy link
Copy Markdown
Collaborator

Your code currently does not meet JabRef's code guidelines. We use Checkstyle to identify issues. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Source Code Tests / Checkstyle (pull_request)" and click on it.

In case of issues with the import order, double check that you activated Auto Import. You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues, commit, and push.

- We separated the "Clean up entries" dialog into three tabs for clarity. [#13819](https://github.com/JabRef/jabref/issues/13819)
- `JabKit`: `--porcelain` does not output any logs to the console anymore. [#14244](https://github.com/JabRef/jabref/pull/14244)
- <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>L</kbd> now opens the terminal in the active library directory. [#14130](https://github.com/JabRef/jabref/issues/14130)
- We improved handling of dates. [#14289](https://github.com/JabRef/jabref/pull/14289)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why PR linked??

The issue needs to be linked. #8902

private static final Logger LOGGER = LoggerFactory.getLogger(DateEditorViewModel.class);

private final DateTimeFormatter dateFormatter;
private static final TemporalAccessor RANGE_SENTINEL = LocalDate.of(1, 1, 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment missing - why this is used, which hese numbers chosen.

return dateFormatter.parse(text);
} catch (DateTimeException e) {
LOGGER.error("Error while parsing date {}", text, e);
return RANGE_SENTINEL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever the user has an invalid date., the 1.1.1970 is now returned which is wrong
Errors should stay errors. Invalid dates are invalid dates and not suddenly another

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 26, 2025

@Alex1034 You even did not add a test case for the original issue - WHY?

Then, the date is truncated into 2000.
If "Normalize date" is disabled (by skipping the step 3), the date is saved as 2000/2010.
A range of dates such as 2000/2010 should be saved as it is entered after "Normalize date."

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 26, 2025

/block

@calixtus
Copy link
Copy Markdown
Member

PR

@calixtus calixtus closed this Dec 26, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull requests was closed without merging. You have been unassigned from the respective issue #8902. In case you closed the PR for yourself, you can re-open it. Please also check After submission of a pull request in CONTRIBUTING.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev: code-quality Issues related to code or architecture decisions first contrib 📌 Pinned status: changes-required Pull requests that are not yet complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save action "Normalize date" truncates an end of a range of dates

5 participants