Skip to content

Commit b2aba44

Browse files
authored
fix: change default seperator to prevent / or : being replaced by culture in DateTime.ToString (#2307)
Other languages like de_DE have "." as the seperator. On such systems the options with the "/" would still translate to ".". Same problem can be applied to Time. This fixes the issue by setting default seperators no matter which language is used. This also changes how MMM behaves and does also show the correct value now.
1 parent 6e53d94 commit b2aba44

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎src/Models/DateTimeFormat.cs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34

45
namespace SourceGit.Models
56
{
@@ -39,7 +40,17 @@ public string DateFormat
3940

4041
public string Example
4142
{
42-
get => DateTime.Now.ToString(DateFormat);
43+
get => DateTime.Now.ToString(DateFormat, _culture);
44+
}
45+
46+
private static readonly CultureInfo _culture = CreateCulture();
47+
48+
private static CultureInfo CreateCulture()
49+
{
50+
var culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
51+
culture.DateTimeFormat.DateSeparator = "/";
52+
culture.DateTimeFormat.TimeSeparator = ":";
53+
return culture;
4354
}
4455

4556
public DateTimeFormat(string date)
@@ -57,10 +68,10 @@ public static string Format(DateTime localTime, bool dateOnly = false)
5768
{
5869
var actived = Supported[ActiveIndex];
5970
if (dateOnly)
60-
return localTime.ToString(actived.DateFormat);
71+
return localTime.ToString(actived.DateFormat, _culture);
6172

6273
var format = Use24Hours ? $"{actived.DateFormat} HH:mm:ss" : $"{actived.DateFormat} hh:mm:ss tt";
63-
return localTime.ToString(format);
74+
return localTime.ToString(format, _culture);
6475
}
6576
}
66-
}
77+
}

0 commit comments

Comments
 (0)