fix #988 sort numerically #996
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As written in #988 blog notes of older photos (before 1970-04-27) are wrongly sorted shown.
The reason becomes obvious when looking at the numerical presentation of the dates:
I first suspected the culprit in the “10-digit rule” which is to distinguish seconds from milliseconds when normalizing timestamps. In many systems, a timestamp value less than 10^10 is assumed to be in seconds, whereas a larger value is assumed to be in milliseconds. But this assumption did not hold true since PiGallery2 uses dates properly transformed to milliseconds.
The reason is even simpler, but well hidden in the blog.service.ts.
The line
dates.sort();does not look suspicious at all unless you know that the JavaScriptsort()method sorts values lexicographically (as strings) rather than numerically even ifdatesis an array of typenumber. This leads to incorrect sorting of timestamps. The solution is to provide a numeric comparison function likesort((a, b) => a - b)to ensure proper chronological sorting, which this PR has implemented.