From 658e0239040073de43f2f63157deb906ca1e9d9f Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 20 May 2020 18:36:41 +0100 Subject: [PATCH] Forces conversion to long date format even if CultureInfo.CurrentCulture doesn't have it. (#431) --- Terminal.Gui/Views/DateField.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs index 1f1915a10..0c82ea499 100644 --- a/Terminal.Gui/Views/DateField.cs +++ b/Terminal.Gui/Views/DateField.cs @@ -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"); }