From 4445b5cba1c31ac26f5d7ad98d2025115e260435 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Tue, 6 Aug 2024 20:25:13 +0300 Subject: [PATCH] fix: Show server logs timestamps in a local timezone Resolves #540 --- lib/logic/models/server_logs.dart | 7 +++-- .../server_details/logs/logs_screen.dart | 28 ++++--------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/logic/models/server_logs.dart b/lib/logic/models/server_logs.dart index 1ff2dbaf..7e7ba1e2 100644 --- a/lib/logic/models/server_logs.dart +++ b/lib/logic/models/server_logs.dart @@ -29,8 +29,11 @@ class ServerLogEntry extends Equatable { final String? systemdUnit; final DateTime timestamp; - static final DateFormat _formatter = DateFormat('hh:mm:ss'); - String get timeString => _formatter.format(timestamp); + static final DateFormat _formatter = DateFormat('HH:mm:ss'); + String get utcTimeString => _formatter.format(timestamp); + String get localTimeString => _formatter.format(timestamp.toLocal()); + String localDateString(final String locale) => + DateFormat.yMMMMEEEEd(locale).format(timestamp.toLocal()); String get fullUTCString => timestamp.toUtc().toIso8601String(); @override diff --git a/lib/ui/pages/server_details/logs/logs_screen.dart b/lib/ui/pages/server_details/logs/logs_screen.dart index 3e8adffa..95dc61fd 100644 --- a/lib/ui/pages/server_details/logs/logs_screen.dart +++ b/lib/ui/pages/server_details/logs/logs_screen.dart @@ -203,7 +203,7 @@ class LogEntryWidget extends StatelessWidget { style: DefaultTextStyle.of(context).style, children: [ TextSpan( - text: '${logEntry.timeString}: ', + text: '${logEntry.localTimeString}: ', style: TextStyle( fontFeatures: const [FontFeature.tabularFigures()], color: color, @@ -246,7 +246,7 @@ class ServerLogEntryDialog extends StatelessWidget { @override Widget build(final BuildContext context) => AlertDialog( scrollable: true, - title: Text(log.timeString), + title: Text(log.localTimeString), contentPadding: const EdgeInsets.symmetric( vertical: 16, horizontal: 12, @@ -255,27 +255,11 @@ class ServerLogEntryDialog extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Divider(), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 12), - child: SelectableText.rich( - TextSpan( - style: DefaultTextStyle.of(context).style, - children: [ - TextSpan( - text: '${'console_page.logged_at'.tr()}: ', - style: const TextStyle(), - ), - TextSpan( - text: '${log.timeString} (${log.fullUTCString})', - style: const TextStyle( - fontWeight: FontWeight.w700, - fontFeatures: [FontFeature.tabularFigures()], - ), - ), - ], - ), - ), + _KeyValueRow( + 'console_page.logged_at'.tr(), + '${log.localTimeString} (${log.localDateString(context.locale.languageCode)})', ), + _KeyValueRow('UTC', log.fullUTCString), const Divider(), _SectionRow('server.log_dialog.metadata'.tr()), _KeyValueRow('server.log_dialog.cursor'.tr(), log.cursor),