diff --git a/src/Commands/Blame.cs b/src/Commands/Blame.cs index de221b07..291249be 100644 --- a/src/Commands/Blame.cs +++ b/src/Commands/Blame.cs @@ -65,7 +65,7 @@ namespace SourceGit.Commands var commit = match.Groups[1].Value; var author = match.Groups[2].Value; var timestamp = int.Parse(match.Groups[3].Value); - var when = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString("yyyy/MM/dd"); + var when = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString(_dateFormat); var info = new Models.BlameLineInfo() { @@ -87,6 +87,7 @@ namespace SourceGit.Commands private readonly Models.BlameData _result = new Models.BlameData(); private readonly StringBuilder _content = new StringBuilder(); + private readonly string _dateFormat = Models.DateTimeFormat.Actived.DateOnly; private string _lastSHA = string.Empty; private bool _needUnifyCommitSHA = false; private int _minSHALen = 64; diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 534cf5bb..9bc7f0c3 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -31,9 +31,9 @@ namespace SourceGit.Models public List Decorators { get; set; } = new List(); public bool HasDecorators => Decorators.Count > 0; - public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"); - public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"); - public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd"); + public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Actived.DateTime); + public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Actived.DateTime); + public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Actived.DateOnly); public bool IsMerged { get; set; } = false; public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime; diff --git a/src/Models/DateTimeFormat.cs b/src/Models/DateTimeFormat.cs new file mode 100644 index 00000000..5adbea68 --- /dev/null +++ b/src/Models/DateTimeFormat.cs @@ -0,0 +1,45 @@ +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) + { + DisplayText = displayText; + DateOnly = dateOnly; + DateTime = dateTime; + } + + public static int ActiveIndex + { + get; + set; + } = 0; + + public static DateTimeFormat Actived + { + get => Supported[ActiveIndex]; + } + + 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("Jun 31 2025 08:00:00", "MMM d yyyy", "MMM d yyyy HH:mm:ss"), + new DateTimeFormat("31 Jun 2025 08:00:00", "d MMM yyyy", "d MMM yyyy HH:mm:ss"), + }; + } +} diff --git a/src/Models/Stash.cs b/src/Models/Stash.cs index 06da763a..3d395a84 100644 --- a/src/Models/Stash.cs +++ b/src/Models/Stash.cs @@ -9,6 +9,6 @@ namespace SourceGit.Models public ulong Time { get; set; } = 0; public string Message { get; set; } = ""; - public string TimeStr => DateTime.UnixEpoch.AddSeconds(Time).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"); + public string TimeStr => DateTime.UnixEpoch.AddSeconds(Time).ToLocalTime().ToString(DateTimeFormat.Actived.DateTime); } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index f2165f3f..f47454aa 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -465,6 +465,7 @@ Tool GENERAL Check for updates on startup + Date Format Language History Commits Show author time instead of commit time in graph diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index e53af9a8..5780f140 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -469,6 +469,7 @@ 工具 通用配置 启动时检测软件更新 + 日期时间格式 显示语言 最大历史提交数 在提交路线图中显示修改时间而非提交时间 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index e96f68ad..4704b8f0 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -468,6 +468,7 @@ 工具 一般設定 啟動時檢查軟體更新 + 日期時間格式 顯示語言 最大歷史提交數 在提交路線圖中顯示修改時間而非提交時間 diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 04f0fa91..efd446df 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -129,6 +129,21 @@ namespace SourceGit.ViewModels set => SetProperty(ref _subjectGuideLength, value); } + public int DateTimeFormat + { + get => Models.DateTimeFormat.ActiveIndex; + set + { + if (value != Models.DateTimeFormat.ActiveIndex && + value >= 0 && + value < Models.DateTimeFormat.Supported.Count) + { + Models.DateTimeFormat.ActiveIndex = value; + OnPropertyChanged(); + } + } + } + public bool UseFixedTabWidth { get => _useFixedTabWidth; diff --git a/src/Views/Blame.axaml.cs b/src/Views/Blame.axaml.cs index d32e4370..1784efc1 100644 --- a/src/Views/Blame.axaml.cs +++ b/src/Views/Blame.axaml.cs @@ -37,6 +37,7 @@ namespace SourceGit.Views { var typeface = view.CreateTypeface(); var underlinePen = new Pen(Brushes.DarkOrange); + var width = Bounds.Width; foreach (var line in view.VisualLines) { @@ -64,16 +65,6 @@ namespace SourceGit.Views context.DrawLine(underlinePen, new Point(x, y + shaLink.Baseline + 2), new Point(x + shaLink.Width, y + shaLink.Baseline + 2)); x += shaLink.Width + 8; - var time = new FormattedText( - info.Time, - CultureInfo.CurrentCulture, - FlowDirection.LeftToRight, - typeface, - _editor.FontSize, - _editor.Foreground); - context.DrawText(time, new Point(x, y)); - x += time.Width + 8; - var author = new FormattedText( info.Author, CultureInfo.CurrentCulture, @@ -82,6 +73,15 @@ namespace SourceGit.Views _editor.FontSize, _editor.Foreground); context.DrawText(author, new Point(x, y)); + + var time = new FormattedText( + info.Time, + CultureInfo.CurrentCulture, + FlowDirection.LeftToRight, + typeface, + _editor.FontSize, + _editor.Foreground); + context.DrawText(time, new Point(width - time.Width, y)); } } } @@ -116,15 +116,6 @@ namespace SourceGit.Views Brushes.DarkOrange); x += shaLink.Width + 8; - var time = new FormattedText( - info.Time, - CultureInfo.CurrentCulture, - FlowDirection.LeftToRight, - typeface, - _editor.FontSize, - _editor.Foreground); - x += time.Width + 8; - var author = new FormattedText( info.Author, CultureInfo.CurrentCulture, @@ -132,7 +123,16 @@ namespace SourceGit.Views typeface, _editor.FontSize, _editor.Foreground); - x += author.Width; + x += author.Width + 8; + + var time = new FormattedText( + info.Time, + CultureInfo.CurrentCulture, + FlowDirection.LeftToRight, + typeface, + _editor.FontSize, + _editor.Foreground); + x += time.Width; if (maxWidth < x) maxWidth = x; diff --git a/src/Views/FileHistories.axaml b/src/Views/FileHistories.axaml index 8403ae73..b0706d24 100644 --- a/src/Views/FileHistories.axaml +++ b/src/Views/FileHistories.axaml @@ -78,7 +78,7 @@ - + - + diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index fbb907d9..265fe807 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -428,7 +428,7 @@ namespace SourceGit.Views var timestamp = UseAuthorTime ? commit.AuthorTime : commit.CommitterTime; if (ShowAsDateTime) - return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss"); + return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString(Models.DateTimeFormat.Actived.DateTime); var now = DateTime.Now; var localTime = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime(); diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 6adbaca4..ea74a836 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -46,7 +46,7 @@ - + + + + + + + + + + - @@ -74,11 +91,11 @@ - - - - + - - -