Skip to content
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

Sorting unexpected #116

Open
pucicu opened this issue Jan 10, 2022 · 2 comments
Open

Sorting unexpected #116

pucicu opened this issue Jan 10, 2022 · 2 comments

Comments

@pucicu
Copy link

pucicu commented Jan 10, 2022

I have a bibtex file using year and month fields. I need to sort the output list by years and within the years by months. As far as I understand the documentation, I can sort it by
uasort($entries, 'compare_bib_entry_by_year,compare_bib_entry_by_month');
but this does not give the expected result. The years are still unsorted. The alternatives
uasort($entries, 'compare_bib_entry_by_month,compare_bib_entry_by_year');
or

uasort($entries, 'compare_bib_entry_by_year');
uasort($entries, 'compare_bib_entry_by_month');

also do not sort as expected, because the months are not in the correct order within the individual years.

How can I have a resulting list with correctly sorted time?

Thanks!

@monperrus
Copy link
Owner

monperrus commented Feb 2, 2022

Thanks for the bug report @pucicu.

  • use usort instead of uasort
  • ordering worked, but in reverse order, which is contrary to the core PHP contract.

I switched to natural order and added tests, see last commit.

usort($entries, 'compare_bib_entry_by_year') // works as expected

Could you try with the last commit on master?

@pucicu
Copy link
Author

pucicu commented Feb 4, 2022

Thanks for considering this issue.

I have checked out the last version and tried. But it still does not work as I would expect.

Perhaps I should explain a bit more my needs:

  • I have a bibtex file with entries that can have same year and even same month.
  • I would like to sort descending way, the youngest should be on top.
  • Within the year, the order should be also from January at bottom to December at top.
  • Within a month the authors should be sorted ascending. But this is optional as the joint ordering Year + Month does not work.

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

No branches or pull requests

2 participants