add a button to reset time

This commit is contained in:
Florian Stinglmayr 2022-12-14 19:07:05 +01:00
parent c2082df6f1
commit 0cb8641056
2 changed files with 29 additions and 4 deletions

View File

@ -42,9 +42,11 @@
<Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/>
<Label Content="From (UTC):" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Center"/>
<xctk:DateTimePicker x:Name="startdate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Label Content="To:" Height="26.2857142857143" VerticalAlignment="Top"/>
<Label Content="To (UTC):" Height="26.2857142857143" VerticalAlignment="Top"/>
<xctk:DateTimePicker x:Name="enddate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/>
<Button x:Name="ResetTime" Content="Reset Time" Click="ResetTime_Click" />
<Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/>
<Button x:Name="ManuallyParse" Content="Manually Parse JSON" Click="ManuallyParse_Click" />
</ToolBar>
<ToolBar Grid.Row="1" HorizontalAlignment="Left" Height="36" VerticalAlignment="Top" Width="Auto" Grid.ColumnSpan="2">

View File

@ -57,16 +57,17 @@ public partial class MainWindow : Window {
journal = new PlayerJournal(Config.Global.JournalLocation);
// Set both to now
startdate.CultureInfo = enddate.CultureInfo = CultureInfo.InvariantCulture;
ResetTime();
InitialiseTime();
journallocation.Text = Config.Global.JournalLocation;
}
private void ResetTime() {
private void InitialiseTime() {
DateTime today = DateTime.Today;
DateTime tomorrow = today.AddDays(1);
startdate.CultureInfo = enddate.CultureInfo = CultureInfo.InvariantCulture;
startdate.Value = today;
enddate.Value = tomorrow;
}
@ -372,4 +373,26 @@ public partial class MainWindow : Window {
RefreshView();
}
}
private DateTime ResetTimeToZero(DateTime d) {
DateTime obj = d;
obj = obj.AddHours(d.Hour * -1);
obj = obj.AddMinutes(d.Minute * -1);
obj = obj.AddSeconds(d.Second * -1);
return obj;
}
private void ResetTime_Click(object sender, RoutedEventArgs e) {
DateTime? d = startdate.Value;
if (d != null) {
startdate.Value = ResetTimeToZero(d.Value);
}
d = enddate.Value;
if (d != null) {
enddate.Value = ResetTimeToZero(d.Value);
}
}
}