Skip to content

Fix timestamp when looking at photos - #3571

Open
tintou wants to merge 2 commits into
nextcloud:masterfrom
tintou:tintou/timestamp-issue
Open

Fix timestamp when looking at photos#3571
tintou wants to merge 2 commits into
nextcloud:masterfrom
tintou:tintou/timestamp-issue

Conversation

@tintou

@tintou tintou commented Jun 21, 2026

Copy link
Copy Markdown

Reject timestamp 0 as it is very unlikely to represent the right time and least to photos being unsorted.

This is especially true for my setup using the S3 from OVH that seem to not return the mtime.

馃 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Fixes: #2768

@tintou
tintou force-pushed the tintou/timestamp-issue branch from a492882 to d1f68f6 Compare June 21, 2026 14:13
Comment thread lib/Listener/OriginalDateTimeMetadataProvider.php
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@tintou
tintou requested a review from come-nc July 16, 2026 12:10
@come-nc
come-nc requested a review from artonge July 16, 2026 15:04
@tintou
tintou force-pushed the tintou/timestamp-issue branch from 4de4d05 to f2051ca Compare July 20, 2026 06:45
tintou and others added 2 commits July 20, 2026 09:08
DateTime::createFromFormat() can successfully parse dates that produce a
Unix timestamp of 0 (e.g. EXIF DateTimeOriginal '1970:01:01 00:00:00'
from a camera with a reset clock). The strict !== false check did not
catch this, so original_date_time was stored as 0.

A value of 0 sorts to the very bottom of the DAV SEARCH results ordered
by this field DESC, making those photos unreachable via offset-based
pagination. Treat any parsed timestamp <= 0 as a parse failure and fall
through to the next method.

Fixes: nextcloud#2768

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Corentin No毛l <corentin.noel@collabora.com>
Non-standard S3-compatible storage backends may return 0 for the
Last-Modified header, causing getMTime() to return 0. Storing that
value as original_date_time would sort the file to the bottom of
the DAV SEARCH results ordered DESC, making it unreachable via
offset-based pagination.

When mtime is 0 we leave the metadata unset (NULL) rather than
writing 0. NULL is an acceptable unknown; 0 actively breaks sorting.

Fixes: nextcloud#2768

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Corentin No毛l <corentin.noel@collabora.com>
@tintou
tintou force-pushed the tintou/timestamp-issue branch from f2051ca to 3b515af Compare July 20, 2026 07:08
Comment on lines +115 to +118
$mtime = $node->getMTime();
if ($mtime > 0) {
$metadata->setInt(self::METADATA_KEY, $mtime, true);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's keep meaningful fallback, else, the file won't even be included in requests filtering by photos-original_date_time.

Suggested change
$mtime = $node->getMTime();
if ($mtime > 0) {
$metadata->setInt(self::METADATA_KEY, $mtime, true);
}
$mtime = $node->getMTime();
if ($mtime > 0) {
$metadata->setInt(self::METADATA_KEY, $mtime, true);
return;
}
$metadata->setInt(self::METADATA_KEY, $node->getUploadTime(), true);

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New photos or videos not displayed in "All Media"; new Photos not displayed in "Photos"; new videos ARE displayed in "Videos"

4 participants