From: Tarek Mahmoud Sayed Date: Thu, 17 Sep 2015 18:05:43 +0000 (-0700) Subject: Port the DateTime parser fix with Serbia cultures X-Git-Tag: accepted/tizen/base/20180629.140029~6396^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=596f0cdafe9f8f2ee2a16419e6203c8e1a8e46d4;p=platform%2Fupstream%2Fcoreclr.git Port the DateTime parser fix with Serbia cultures Serbia has '.' at the end of the date and time parts. (like 'd.M.yyyy.'). while '.' is marked as date and time separator in same time. this confuse the parser and make it fail to parse date/time string formatted with the Serbia culture. [tfs-changeset: 1526268] --- diff --git a/src/mscorlib/src/System/Globalization/DateTimeParse.cs b/src/mscorlib/src/System/Globalization/DateTimeParse.cs index 2c644a9..668c3ea 100644 --- a/src/mscorlib/src/System/Globalization/DateTimeParse.cs +++ b/src/mscorlib/src/System/Globalization/DateTimeParse.cs @@ -2410,23 +2410,34 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR, } } - if (raw.hasSameDateAndTimeSeparators && (dtok.dtt == DTT.YearEnd || dtok.dtt == DTT.YearSpace || dtok.dtt == DTT.YearDateSep)) + if (raw.hasSameDateAndTimeSeparators) { - // When time and date separators are same and we are hitting a year number while the first parsed part of the string was recognized - // as part of time (and not a date) DS.T_Nt, DS.T_NNt then change the state to be a date so we try to parse it as a date instead - if (dps == DS.T_Nt) + if (dtok.dtt == DTT.YearEnd || dtok.dtt == DTT.YearSpace || dtok.dtt == DTT.YearDateSep) { - dps = DS.D_Nd; + // When time and date separators are same and we are hitting a year number while the first parsed part of the string was recognized + // as part of time (and not a date) DS.T_Nt, DS.T_NNt then change the state to be a date so we try to parse it as a date instead + if (dps == DS.T_Nt) + { + dps = DS.D_Nd; + } + if (dps == DS.T_NNt) + { + dps = DS.D_NNd; + } } - if (dps == DS.T_NNt) - { - dps = DS.D_NNd; - // we have the case of Serbia have dates in forms 'd.M.yyyy.' so we can expect '.' after the year number. - // changing the token to YearSpace instead of YearDateSep will make the parsing not failing this case. - if (dtok.dtt == DTT.YearDateSep) + bool atEnd = str.AtEnd(); + if (dateParsingStates[(int)dps][(int)dtok.dtt] == DS.ERROR || atEnd) + { + switch (dtok.dtt) { - dtok.dtt = DTT.YearSpace; + // we have the case of Serbia have dates in forms 'd.M.yyyy.' so we can expect '.' after the date parts. + // changing the token to end with space instead of Date Separator will avoid failing the parsing. + + case DTT.YearDateSep: dtok.dtt = atEnd ? DTT.YearEnd : DTT.YearSpace; break; + case DTT.NumDatesep: dtok.dtt = atEnd ? DTT.NumEnd : DTT.NumSpace; break; + case DTT.NumTimesep: dtok.dtt = atEnd ? DTT.NumEnd : DTT.NumSpace; break; + case DTT.MonthDatesep: dtok.dtt = atEnd ? DTT.MonthEnd : DTT.MonthSpace; break; } } } @@ -4355,6 +4366,11 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR, return (false); } + internal bool AtEnd() + { + return Index < len ? false : true; + } + internal bool Advance(int count) { Contract.Assert(Index + count <= len, "__DTString::Advance: Index + count <= len"); Index += count;