fix: Show server logs timestamps in a local timezone

Resolves #540
This commit is contained in:
Inex Code 2024-08-06 20:25:13 +03:00
parent 76821aeec5
commit 4445b5cba1
2 changed files with 11 additions and 24 deletions

View file

@ -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

View file

@ -203,7 +203,7 @@ class LogEntryWidget extends StatelessWidget {
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
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>[
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),