Skip to content

fix: respect system 24-hour time setting - #1111

Open
guzino wants to merge 8 commits into
synonymdev:masterfrom
guzino:fix/system-time-format
Open

fix: respect system 24-hour time setting#1111
guzino wants to merge 8 commits into
synonymdev:masterfrom
guzino:fix/system-time-format

Conversation

@guzino

@guzino guzino commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #677

This PR makes activity timestamps follow the device's 12/24-hour time setting.

Description

DatePattern.ACTIVITY_TIME was h:mm, a 12-hour pattern with no meridiem, so a payment received at 15:23 rendered as 3:23. That is wrong for anyone on a 24-hour clock and ambiguous even for 12-hour users. The two neighbouring row patterns (ACTIVITY_ROW_DATE, ACTIVITY_ROW_DATE_YEAR) were hardcoded the other way, to 24-hour, so the same activity row changed clock format depending on how old the item was. Nothing in the app consulted the system setting.

Rather than pass a 12/24-hour flag around the screens, this adds one entry point for user-facing timestamps:

  • uiDateText(timestamp, style) in ui/utils/DateText.kt, backed by a UiDateStyle enum (TIME, DATE, DATE_TIME, DATE_TIME_YEAR) in ext/DateTime.kt that owns the patterns. It resolves the clock format through rememberIs24HourFormat(), which registers for ACTION_TIME_CHANGED so timestamps update without waiting for an unrelated recomposition.
  • ActivityRow and ActivityDetailScreen pick a style and call it. Neither builds a pattern or sees the flag.
  • ext/Numbers.kt (toActivityItemDate, toActivityItemTime) is removed as superseded, along with the ACTIVITY_* pattern constants and the unused INVOICE_EXPIRY, leaving DatePattern as plain constants.
  • Instant.formatted() takes optional locale and zone so patterns can be asserted without depending on the CI machine's locale or timezone. Existing call sites are unchanged.

ChannelDetailScreen still hardcodes 24-hour via DatePattern.CHANNEL_DETAILS (#1110), and toLocalizedTimestamp defaults to Locale.US so App Status and Backup timestamps ignore the device locale (#1112). Both are separate screens and are left out here; with uiDateText in place each becomes a two-line adoption.

Preview

before-activity-list after-activity-list-24h after-activity-list-12h

QA Notes

Manual Tests

  • 1. Set the device to 24-hour time (Settings > System > Date & time). Receive a payment, then check the activity row and activity detail: both show the time on a 24-hour clock (e.g. 14:38), matching the status bar.
  • 2. Set the device to 12-hour time and reopen the activity list: the same entry reads 2:38 PM.
  • 3. Check an activity item from earlier this year and one from a previous year: the date is unchanged and the time follows the same 12/24-hour choice as today's items.
  • 4. regression: Switch the device to a non-English locale and confirm activity dates still render with a localized month name.

Automated Checks

  • Unit tests added in DateTimeExtTest.kt: each UiDateStyle in both clock formats, midnight and noon boundaries, month-name localization, and timezone handling. All use a fixed instant with explicit locale and zone so they are deterministic.
  • Local: just compile, just test, just lint all pass, no new detekt findings.
  • Verified on an emulator in both 12- and 24-hour modes with a regtest transaction.

Comment thread app/src/main/java/to/bitkit/ext/Context.kt
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Greptile Summary

The PR centralizes user-facing activity timestamp formatting and makes activity rows and details respect the device’s 12/24-hour clock preference.

  • Adds a context-backed clock-format setting and reusable UiDateStyle formatting entry point.
  • Migrates activity list and detail timestamps to the new formatter.
  • Removes superseded activity formatting extensions and constants.
  • Adds deterministic coverage for clock formats, locale, and timezone behavior.

Confidence Score: 3/5

The activity timestamps need reactive handling of system clock-format changes before this is safe to merge.

The formatter reads the current 12/24-hour preference only during composition, while the system setting is not represented by observable state, leaving open activity screens in the previous format after the preference changes.

Files Needing Attention: app/src/main/java/to/bitkit/ext/Context.kt and the activity Compose call sites

Important Files Changed

Filename Overview
app/src/main/java/to/bitkit/ext/Context.kt Adds a wrapper around Android’s system 24-hour-format setting, but does not expose changes as observable Compose state.
app/src/main/java/to/bitkit/ext/DateTime.kt Adds centralized activity timestamp styles and locale/timezone-aware instant formatting without breaking existing callers.
app/src/main/java/to/bitkit/ui/screens/wallets/activity/ActivityDetailScreen.kt Migrates the separate date and time fields to system-aware formatting, which refreshes only when the screen recomposes.
app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/ActivityRow.kt Preserves age-based timestamp styles while applying the device clock preference during composition.
app/src/test/java/to/bitkit/ext/DateTimeExtTest.kt Adds deterministic tests covering all new styles, 12/24-hour boundaries, locale handling, and timezone conversion.

Reviews (1): Last reviewed commit: "fix: respect system 24-hour time setting" | Re-trigger Greptile

@ovitrif ovitrif added this to the 2.5.0 milestone Jul 28, 2026
@ovitrif
ovitrif requested a review from jvsena42 July 28, 2026 09:55
@ovitrif ovitrif assigned ovitrif and jvsena42 and unassigned ovitrif Jul 28, 2026
Comment on lines +36 to +46
val receiver = object : BroadcastReceiver() {
override fun onReceive(receiverContext: Context?, intent: Intent?) = run {
is24Hour = context.is24HourTimeFormat
}
}
ContextCompat.registerReceiver(
context,
receiver,
IntentFilter(Intent.ACTION_TIME_CHANGED),
ContextCompat.RECEIVER_NOT_EXPORTED,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

every instance will registerReceiver/unregisterReceiver one receiver, causing a real junk risk for a big list

@jvsena42 jvsena42 Jul 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

take a look at ui/Locals.kt pattern. Could create a LocalIs24HourFormat and provide a single rememberIs24HourFormat in ContentView/MainActivity with uiDateText reading LocalIs24HourFormat.current

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 3e90024f4. LocalIs24HourFormat in ui/Locals.kt, provided once in ContentView — one receiver for the app instead of one per row. Left it nullable so previews and anything outside ContentView fall back to the device value rather than a hardcoded default.

Comment on lines +371 to +374
val style = when {
dateTime.toLocalDate() == now -> UiDateStyle.TIME
dateTime.year == now.year -> UiDateStyle.DATE_TIME
else -> UiDateStyle.DATE_TIME_YEAR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extracting a pure fun uiDateStyleFor(timestamp: ULong, today: LocalDate, zone: ZoneId): UiDateStyle into ext/DateTime.kt would make it more testable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 0a102b0bc. Pure uiDateStyleFor(timestamp, today, zone) in ext/DateTime.kt, with today/zone defaulted so the call site stays a one-liner. Four tests cover today / this year / previous year and the zone boundary.

Comment on lines +28 to +29
): String = Instant.ofEpochSecond(timestamp.toLong())
.formatted(style.pattern(rememberIs24HourFormat()), locale, zone)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add a remember for avoid rebuilding the pattern string and a DateTimeFormatter on every recomposition of every row

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 3e90024f4. The DateTimeFormatter is remembered on (style, is24Hour, locale, zone) and the formatted string on (formatter, timestamp).

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.

[Bug]: Activity time uses different time format to system

3 participants