From f548e7da5d978dc1921fe2378b809f77ae0936ab Mon Sep 17 00:00:00 2001 From: raOrion <31798221+raOrion@users.noreply.github.com> Date: Sat, 9 Sep 2017 16:17:12 +0300 Subject: [PATCH] Single quotation marks in format string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes the format string contains the text in single quotation marks. For example: "d MMMM yyyy 'г.' H:mm:ss". These parts should be removed from "format" string and from the "value" string - otherwise the parsing mechanism is not working correctly. --- .../Implementation/DateTimeParser.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs index 60cf05cc..1dec83a9 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs @@ -30,6 +30,28 @@ namespace Xceed.Wpf.Toolkit if( string.IsNullOrEmpty( value ) || string.IsNullOrEmpty( format ) ) return false; + + // === Sometimes the format string contains the text in single quotation marks. For example: + // "d MMMM yyyy 'г.' H:mm:ss". These parts should be removed from "format" string and from the "value" string + // - otherwise the parsing mechanism is not working correctly + while (true) + { + int pos = format.IndexOf('\''); + if (pos > -1) + { + int end = format.IndexOf('\'', pos + 1); + if (end > -1) + { + int sz = end - pos + 1; + var ff = format.Substring(pos, sz); + format = format.Remove(pos, sz); + if (sz > 2) + value = value.Replace(ff.Substring(1, sz - 2), string.Empty); + } + } + else break; + } + // === var dateTimeString = ComputeDateTimeString( value, format, currentDate, cultureInfo ).Trim();