diff --git a/src/Models/DateTimeFormat.cs b/src/Models/DateTimeFormat.cs index e73e8c18..4e71a74f 100644 --- a/src/Models/DateTimeFormat.cs +++ b/src/Models/DateTimeFormat.cs @@ -1,16 +1,20 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace SourceGit.Models { public class DateTimeFormat { - public string DisplayText { get; set; } public string DateOnly { get; set; } public string DateTime { get; set; } - public DateTimeFormat(string displayText, string dateOnly, string dateTime) + public string Example + { + get => _example.ToString(DateTime); + } + + public DateTimeFormat(string dateOnly, string dateTime) { - DisplayText = displayText; DateOnly = dateOnly; DateTime = dateTime; } @@ -28,18 +32,19 @@ namespace SourceGit.Models public static readonly List Supported = new List { - new DateTimeFormat("2025/01/31 08:00:00", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss"), - new DateTimeFormat("2025.01.31 08:00:00", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss"), - new DateTimeFormat("2025-01-31 08:00:00", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"), - new DateTimeFormat("01/31/2025 08:00:00", "MM/dd/yyyy", "MM/dd/yyyy HH:mm:ss"), - new DateTimeFormat("01.31.2025 08:00:00", "MM.dd.yyyy", "MM.dd.yyyy HH:mm:ss"), - new DateTimeFormat("01-31-2025 08:00:00", "MM-dd-yyyy", "MM-dd-yyyy HH:mm:ss"), - new DateTimeFormat("31/01/2025 08:00:00", "dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss"), - new DateTimeFormat("31.01.2025 08:00:00", "dd.MM.yyyy", "dd.MM.yyyy HH:mm:ss"), - new DateTimeFormat("31-01-2025 08:00:00", "dd-MM-yyyy", "dd-MM-yyyy HH:mm:ss"), - - new DateTimeFormat("Jan 31 2025 08:00:00", "MMM d yyyy", "MMM d yyyy HH:mm:ss"), - new DateTimeFormat("31 Jan 2025 08:00:00", "d MMM yyyy", "d MMM yyyy HH:mm:ss"), + new DateTimeFormat("yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss"), + new DateTimeFormat("yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss"), + new DateTimeFormat("yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"), + new DateTimeFormat("MM/dd/yyyy", "MM/dd/yyyy HH:mm:ss"), + new DateTimeFormat("MM.dd.yyyy", "MM.dd.yyyy HH:mm:ss"), + new DateTimeFormat("MM-dd-yyyy", "MM-dd-yyyy HH:mm:ss"), + new DateTimeFormat("dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss"), + new DateTimeFormat("dd.MM.yyyy", "dd.MM.yyyy HH:mm:ss"), + new DateTimeFormat("dd-MM-yyyy", "dd-MM-yyyy HH:mm:ss"), + new DateTimeFormat("MMM d yyyy", "MMM d yyyy HH:mm:ss"), + new DateTimeFormat("d MMM yyyy", "d MMM yyyy HH:mm:ss"), }; + + private static readonly DateTime _example = new DateTime(2025, 1, 31, 8, 0, 0, DateTimeKind.Local); } } diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index 20f49d90..d7afe6ae 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -191,7 +191,8 @@ FontWeight="{Binding FontWeight}" Opacity="{Binding Opacity}" UseAuthorTime="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowAuthorTimeInGraph, Mode=OneWay}" - ShowAsDateTime="{Binding Source={x:Static vm:Preference.Instance}, Path=!DisplayTimeAsPeriodInHistories}"/> + ShowAsDateTime="{Binding Source={x:Static vm:Preference.Instance}, Path=!DisplayTimeAsPeriodInHistories}" + DateTimeFormat="{Binding Source={x:Static vm:Preference.Instance}, Path=DateTimeFormat}"/> diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 265fe807..87ae11cb 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -343,6 +343,15 @@ namespace SourceGit.Views set => SetValue(ShowAsDateTimeProperty, value); } + public static readonly StyledProperty DateTimeFormatProperty = + AvaloniaProperty.Register(nameof(DateTimeFormat), 0); + + public int DateTimeFormat + { + get => GetValue(DateTimeFormatProperty); + set => SetValue(DateTimeFormatProperty, value); + } + public static readonly StyledProperty UseAuthorTimeProperty = AvaloniaProperty.Register(nameof(UseAuthorTime), true); @@ -371,6 +380,11 @@ namespace SourceGit.Views else StartTimer(); } + else if (change.Property == DateTimeFormatProperty) + { + if (ShowAsDateTime) + SetCurrentValue(TextProperty, GetDisplayText()); + } } protected override void OnLoaded(RoutedEventArgs e) @@ -426,10 +440,10 @@ namespace SourceGit.Views if (commit == null) return string.Empty; - var timestamp = UseAuthorTime ? commit.AuthorTime : commit.CommitterTime; if (ShowAsDateTime) - return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString(Models.DateTimeFormat.Actived.DateTime); + return UseAuthorTime ? commit.AuthorTimeStr : commit.CommitterTimeStr; + var timestamp = UseAuthorTime ? commit.AuthorTime : commit.CommitterTime; var now = DateTime.Now; var localTime = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime(); var span = now - localTime; diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index aad47f51..d87d1907 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -72,7 +72,7 @@ - +