Skip to content

Print an older commit's date in the phone's time zone, as the web does - #164

Open
RaphaelFakhri wants to merge 1 commit into
NativePHP:mainfrom
RaphaelFakhri:fix/relative-date-phone-timezone
Open

RaphaelFakhri wants to merge 1 commit into
NativePHP:mainfrom
RaphaelFakhri:fix/relative-date-phone-timezone

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Beside a commit, reply, notification or Remote, the app prints how long ago it happened: now, 5m, 3h, 2d, and after a week the date, like Sep 1. That date was printed in the time zone devnull's answer carries, which is UTC, so away from UTC an older commit could show the day before or after the one it was made on. The web prints it in the reader's time zone.

For example, with the phone in Los Angeles, a commit made at 8 PM on Aug 31 (03:00 UTC on Sep 1) shows Sep 1 in the app and Aug 31 on the web. A commit made on the evening of Dec 31 shows Jan 1 with no year, as if it were from this year.

Fix

Display::relativeTime() now reads the date in the phone's time zone, through Display::now(), the way dayLabel(), dayKey() and clock() already do. Both the day and the "is it this year" check use that zone. The now, m, h and d counts don't change.

Tests

A new test in tests/Unit/Devnull/DisplayTest.php prints older commits with the phone in America/Los_Angeles.

  • Without the change, it fails twice: Sep 1 instead of Aug 31, and Jan 1 instead of Dec 31, 2025.
  • With the change, DisplayTest.php passes (36 passed).

I didn't run this on a device.

Screenshots

  • No visible change

Fixes #163

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.

Commits older than a week show the UTC date, not the phone's

1 participant