| | | 1 | | using System.Globalization; |
| | | 2 | | using OzonOrdersWeb.Build; |
| | | 3 | | |
| | | 4 | | namespace OzonOrdersWeb.WebServices; |
| | | 5 | | |
| | | 6 | | /// <summary>Компактная подпись версии сборки для UI (git commit + дата).</summary> |
| | | 7 | | public static class AppBuildInfoDisplay |
| | | 8 | | { |
| | 0 | 9 | | private static readonly Lazy<BuildLabel> Cached = new(Resolve); |
| | | 10 | | |
| | 0 | 11 | | public static string CompactLabel => Cached.Value.Short; |
| | 0 | 12 | | public static string Tooltip => Cached.Value.Full; |
| | | 13 | | |
| | | 14 | | private static BuildLabel Resolve() |
| | | 15 | | { |
| | 0 | 16 | | var hash = AppBuildInfo.CommitHash; |
| | 0 | 17 | | if (hash.Length > 7) |
| | 0 | 18 | | hash = hash[..7]; |
| | 0 | 19 | | var when = TryParseCommitDate(AppBuildInfo.CommitDate) ?? DateTimeOffset.UtcNow; |
| | 0 | 20 | | var msk = ResolveMoscowTimeZone(); |
| | 0 | 21 | | var local = TimeZoneInfo.ConvertTime(when, msk); |
| | | 22 | | |
| | 0 | 23 | | return new BuildLabel( |
| | 0 | 24 | | $"{hash} · {local:dd.MM HH:mm}", |
| | 0 | 25 | | $"Сборка {hash} от {local:dd.MM.yyyy HH:mm} (МСК)"); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | private static DateTimeOffset? TryParseCommitDate(string raw) |
| | | 29 | | { |
| | 0 | 30 | | if (string.IsNullOrWhiteSpace(raw)) |
| | 0 | 31 | | return null; |
| | | 32 | | |
| | 0 | 33 | | return DateTimeOffset.TryParse(raw, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var parsed) |
| | 0 | 34 | | ? parsed |
| | 0 | 35 | | : null; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | private static TimeZoneInfo ResolveMoscowTimeZone() |
| | | 39 | | { |
| | | 40 | | try |
| | | 41 | | { |
| | 0 | 42 | | return TimeZoneInfo.FindSystemTimeZoneById( |
| | 0 | 43 | | OperatingSystem.IsWindows() ? "Russian Standard Time" : "Europe/Moscow"); |
| | | 44 | | } |
| | 0 | 45 | | catch (TimeZoneNotFoundException) |
| | | 46 | | { |
| | 0 | 47 | | return TimeZoneInfo.CreateCustomTimeZone("MSK", TimeSpan.FromHours(3), "MSK", "MSK"); |
| | | 48 | | } |
| | 0 | 49 | | } |
| | | 50 | | |
| | 0 | 51 | | private sealed record BuildLabel(string Short, string Full); |
| | | 52 | | } |