Forces conversion to long date format even if CultureInfo.CurrentCulture doesn't have it. (#431)

This commit is contained in:
BDisp
2020-05-20 18:36:41 +01:00
committed by GitHub
parent 88d6047c74
commit 658e023904

View File

@@ -41,7 +41,7 @@ namespace Terminal.Gui {
{
CultureInfo cultureInfo = CultureInfo.CurrentCulture;
sepChar = cultureInfo.DateTimeFormat.DateSeparator;
longFormat = $" {cultureInfo.DateTimeFormat.ShortDatePattern}";
longFormat = GetLongFormat (cultureInfo.DateTimeFormat.ShortDatePattern);
shortFormat = GetShortFormat(longFormat);
this.isShort = isShort;
CursorPosition = 1;
@@ -55,7 +55,21 @@ namespace Terminal.Gui {
Text = e;
}
string GetShortFormat(string lf)
string GetLongFormat (string lf)
{
ustring [] frm = ustring.Make (lf).Split (ustring.Make (sepChar));
for (int i = 0; i < frm.Length; i++) {
if (frm [i].Contains ("M") && frm [i].Length < 2)
lf = lf.Replace ("M", "MM");
if (frm [i].Contains ("d") && frm [i].Length < 2)
lf = lf.Replace ("d", "dd");
if (frm [i].Contains ("y") && frm [i].Length < 4)
lf = lf.Replace ("yy", "yyyy");
}
return $" {lf}";
}
string GetShortFormat (string lf)
{
return lf.Replace("yyyy", "yy");
}