Skip to content

Fix: fallback conversion from BibTeX year field to biblatex date field #13040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wanling0000
Copy link
Contributor

@wanling0000 wanling0000 commented Apr 30, 2025

Closes #11868
This PR introduces a fallback mechanism in the "Convert to biblatex" cleanup step to improve compatibility with BibLaTeX-style date formats mistakenly entered in the BibTeX year field.

What was the problem?
Users reported that when year = {2011-11-11} (or other extended formats) is used in BibTeX mode, the "Convert to biblatex" cleanup did not populate the date field as expected.

This is because the cleanup logic only merges year + month if both are present and parsable. Non-standard values in year were silently ignored.

What has been changed?

  • A fallback step was added after the main conversion logic:
    • If date is still missing, and
    • month is empty, and
    • year contains a parsable BibLaTeX-style date,
    • then date is set directly from year, and year is cleared.

This fallback is intentionally conservative and only runs if the standard cleanup logic does not produce a date.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • [/] Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

return changes;
}

private Collection<? extends FieldChange> applyDateFallback(BibEntry entry) {
Copy link

Choose a reason for hiding this comment

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

The method applyDateFallback is new and should follow the Single-responsibility principle. It currently handles both date parsing and field clearing, which could be separated.

String yearText = yearValue.get().trim();
Optional<Date> fallbackDate = Date.parse(yearText);
if (fallbackDate.isPresent()) {
entry.setField(StandardField.DATE, yearText).ifPresent(changes::add);
Copy link

Choose a reason for hiding this comment

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

The method applyDateFallback should use withField instead of setField when creating a new BibEntry object to adhere to JabRef's coding standards.

@wanling0000 wanling0000 marked this pull request as ready for review April 30, 2025 22:45
Copy link

trag-bot bot commented Apr 30, 2025

@trag-bot didn't find any issues in the code! ✅✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup entries - Convert to biblatex does not work
1 participant