diff --git a/lib/screens/SettingsScreen.dart b/lib/screens/SettingsScreen.dart index 956bd25..a4dc9e8 100644 --- a/lib/screens/SettingsScreen.dart +++ b/lib/screens/SettingsScreen.dart @@ -34,7 +34,9 @@ class _SettingsScreenState extends State { @override Widget build(BuildContext context) { List colorSection = []; + List logSection = []; + // System Color Configs colorSection.add(ConfigItem( label: Text('Use system colors'), labelWidth: 200, @@ -63,10 +65,8 @@ class _SettingsScreenState extends State { )), )); } - - List items = []; - items.add(ConfigSection(children: colorSection)); - items.add(ConfigItem( + // Log Configs + logSection.add(ConfigItem( label: Text('Wrap log output'), labelWidth: 200, content: Align( @@ -81,6 +81,25 @@ class _SettingsScreenState extends State { }, )), )); + logSection.add(ConfigItem( + label: Text('Use Local Time Zone'), + labelWidth: 200, + content: Align( + alignment: Alignment.centerRight, + child: Switch.adaptive( + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + value: settings.logLocalTZ, + onChanged: (value) { + setState(() { + settings.logLocalTZ = value; + }); + }, + )), + )); + + List items = []; + items.add(ConfigSection(children: colorSection)); + items.add(ConfigSection(children: logSection)); items.add(ConfigSection(children: [ ConfigPageItem( label: Text('About'), diff --git a/lib/screens/SiteLogsScreen.dart b/lib/screens/SiteLogsScreen.dart index d6e26e5..354568c 100644 --- a/lib/screens/SiteLogsScreen.dart +++ b/lib/screens/SiteLogsScreen.dart @@ -103,8 +103,11 @@ class _SiteLogsScreenState extends State { loadLogs() async { var file = File(widget.site.logFile); try { - final v = await file.readAsString(); + String v = await file.readAsString(); + if (settings.logLocalTZ) { + v = convertToLocalTZ(v); + } setState(() { logs = v; }); @@ -126,4 +129,12 @@ class _SiteLogsScreenState extends State { return BoxConstraints(minWidth: MediaQuery.of(context).size.width); } } + + convertToLocalTZ(String rawLog) { + rawLog = rawLog.replaceAllMapped(RegExp('time="(.*?)"'), (match) { + DateTime userDate = DateTime.parse(match.group(1)); + return 'time="${userDate.toLocal().toIso8601String()}"'; + }); + return rawLog; + } } diff --git a/lib/services/settings.dart b/lib/services/settings.dart index e8a9d01..6f3717d 100644 --- a/lib/services/settings.dart +++ b/lib/services/settings.dart @@ -38,6 +38,14 @@ class Settings { _set('logWrap', enabled); } + bool get logLocalTZ { + return _getBool('logLocalTZ', false); + } + + set logLocalTZ(bool enabled) { + _set('logLocalTZ', enabled); + } + String _getString(String key, String defaultValue) { final val = _settings[key]; if (val is String) {