From 21e8ea864d005d39b293ad8a78d7e8521f6d5af8 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Thu, 23 Mar 2023 14:35:03 +0300 Subject: [PATCH 1/2] Made the "Timestamp" format human-readable. --- .../Editors/UndertaleGeneralInfoEditor.xaml | 3 ++- .../UndertaleGeneralInfoEditor.xaml.cs | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml index 0d941b27d..b3be10d7c 100644 --- a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml @@ -15,6 +15,7 @@ + @@ -125,7 +126,7 @@ Timestamp - + Display name diff --git a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs index c1229c814..cf3b3ef35 100644 --- a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -36,4 +37,25 @@ private void SyncRoomList_Click(object sender, RoutedEventArgs e) roomOrder.Add(new UndertaleResourceById() { Resource = room }); } } + + public class TimestampDateTimeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not ulong timestamp) + return "(error)"; + DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds((long)timestamp).LocalDateTime; + return dateTime.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not string dateTimeStr) + return new ValidationResult(false, "The value is not a string."); + if (!DateTime.TryParse(dateTimeStr, out DateTime dateTime)) + return new ValidationResult(false, "Invalid date time format."); + + return (ulong)(new DateTimeOffset(dateTime).ToUnixTimeSeconds()); + } + } } From 3360edd5a6d0149c7cd29fbebaa1951af1ff8268 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Thu, 23 Mar 2023 18:26:10 +0300 Subject: [PATCH 2/2] Made "Timestamp" field read-only and added a hint. --- .../Editors/UndertaleGeneralInfoEditor.xaml | 14 +++++++++++++- .../Editors/UndertaleGeneralInfoEditor.xaml.cs | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml index b3be10d7c..f0cf424bd 100644 --- a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml @@ -126,7 +126,19 @@ Timestamp - + + + + + + + + Display name diff --git a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs index cf3b3ef35..e7d90428a 100644 --- a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs @@ -44,8 +44,11 @@ public object Convert(object value, Type targetType, object parameter, CultureIn { if (value is not ulong timestamp) return "(error)"; - DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds((long)timestamp).LocalDateTime; - return dateTime.ToString(); + DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds((long)timestamp); + if (parameter is string par && par == "GMT") + return "GMT+0: " + dateTimeOffset.UtcDateTime.ToString(); + else + return dateTimeOffset.LocalDateTime.ToString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)