Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/referencesource/mscorlib/system/globalization/datetimeparse.cs')
-rw-r--r--mcs/class/referencesource/mscorlib/system/globalization/datetimeparse.cs48
1 files changed, 33 insertions, 15 deletions
diff --git a/mcs/class/referencesource/mscorlib/system/globalization/datetimeparse.cs b/mcs/class/referencesource/mscorlib/system/globalization/datetimeparse.cs
index 5ff5059ac69..da422367d63 100644
--- a/mcs/class/referencesource/mscorlib/system/globalization/datetimeparse.cs
+++ b/mcs/class/referencesource/mscorlib/system/globalization/datetimeparse.cs
@@ -1,4 +1,4 @@
-// ==++==
+// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
@@ -699,6 +699,7 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR,
case TokenType.SEP_Date:
dtok.dtt = DTT.YearDateSep;
break;
+
case TokenType.SEP_Time:
if (!raw.hasSameDateAndTimeSeparators)
{
@@ -711,6 +712,7 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR,
// we are sure we are not parsing time.
dtok.dtt = DTT.YearDateSep;
break;
+
case TokenType.SEP_DateOrOffset:
// The separator is either a date separator or the start of a time zone offset. If the token will complete the date then
// process just the number and roll back the index so that the outer loop can attempt to parse the time zone offset.
@@ -816,7 +818,7 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR,
raw.AddNumber(dtok.num);
break;
case TokenType.SEP_Time:
- if (raw.hasSameDateAndTimeSeparators &&
+ if (raw.hasSameDateAndTimeSeparators &&
(dps == DS.D_Y || dps == DS.D_YN || dps == DS.D_YNd || dps == DS.D_YM || dps == DS.D_YMd))
{
// we are parsing a date and we have the time separator same as date separator, so we mark the token as date separator
@@ -2424,23 +2426,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;
}
}
}
@@ -4376,6 +4389,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;
@@ -5039,7 +5057,7 @@ Start:
YearNumberToken = 2, // The number which is considered as year number, which has 3 or more digits. E.g. "2003"
Am = 3, // AM timemark. E.g. "AM"
Pm = 4, // PM timemark. E.g. "PM"
- MonthToken = 5, // A word (or words) that represents a month name. E.g. "Microsoft"
+ MonthToken = 5, // A word (or words) that represents a month name. E.g. "[....]"
EndOfString = 6, // End of string
DayOfWeekToken = 7, // A word (or words) that represents a day of week name. E.g. "Monday" or "Mon"
TimeZoneToken = 8, // A word that represents a timezone name. E.g. "GMT"