Skip to content

Commit

Permalink
Merge pull request #1226 from VladiStep/timestampToDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Grossley authored Mar 23, 2023
2 parents 5355cf6 + 3360edd commit be1c34a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
15 changes: 14 additions & 1 deletion UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<local:BooleanToVisibilityConverter x:Key="BooleanFalseToVisibilityConverter" local:trueValue="Collapsed" local:falseValue="Visible"/>
<local:ByteArrayConverter x:Key="byteArrayConverter"/>
<local:ByteGUIDArrayConverter x:Key="byteGUIDArrayConverter"/>
<local:TimestampDateTimeConverter x:Key="TimestampDateTimeConverter"/>
</UserControl.Resources>

<StackPanel>
Expand Down Expand Up @@ -125,7 +126,19 @@
<TextBox Grid.Row="14" Grid.Column="1" Margin="3" Text="{Binding GeneralInfo.LicenseCRC32, StringFormat={}{0:X8}}"/>

<TextBlock Grid.Row="15" Grid.Column="0" Margin="3">Timestamp</TextBlock>
<TextBox Grid.Row="15" Grid.Column="1" Margin="3" Text="{Binding GeneralInfo.Timestamp}"/>
<TextBox Grid.Row="15" Grid.Column="1" Margin="3" IsReadOnly="True"
Text="{Binding GeneralInfo.Timestamp, Mode=OneWay, Converter={StaticResource TimestampDateTimeConverter}}"
ToolTip="{Binding GeneralInfo.Timestamp, Mode=OneWay, Converter={StaticResource TimestampDateTimeConverter}, ConverterParameter=GMT}"
ToolTipService.InitialShowDelay="250">
<TextBox.Background>
<VisualBrush AlignmentX="Right" AlignmentY="Center" Stretch="None">
<VisualBrush.Visual>
<Label Content="(local time, hover to see GMT+0)"
Foreground="Gray" FontStyle="Italic" Margin="0,0,5,0"/>
</VisualBrush.Visual>
</VisualBrush>
</TextBox.Background>
</TextBox>

<TextBlock Grid.Row="16" Grid.Column="0" Margin="3">Display name</TextBlock>
<local:UndertaleStringReference Grid.Row="16" Grid.Column="1" Margin="3" ObjectReference="{Binding GeneralInfo.DisplayName}"/>
Expand Down
25 changes: 25 additions & 0 deletions UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,4 +37,28 @@ private void SyncRoomList_Click(object sender, RoutedEventArgs e)
roomOrder.Add(new UndertaleResourceById<UndertaleRoom, UndertaleChunkROOM>() { 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)";
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)
{
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());
}
}
}

0 comments on commit be1c34a

Please sign in to comment.