public static Date Parse(String text)
{
int limit = text.Length;
int index = 0;
while (true) {
// Extract date components
if ((index >= limit) || !IsDigit (text [index])) break;
int year = (text [index++] - '0') * 1000;
if ((index >= limit) || !IsDigit (text [index])) break;
year += (text [index++] - '0') * 100;
if ((index >= limit) || !IsDigit (text [index])) break;
year += (text [index++] - '0') *10;
if ((index >= limit) || !IsDigit (text [index])) break;
year += (text [index++] - '0');
if ((index >= limit) || (text [index++] != '-')) break;
if ((index >= limit) || !IsDigit (text [index])) break;
int month = (text [index++] - '0') * 10;
if ((index >= limit) || !IsDigit (text [index])) break;
month += (text [index++] - '0');
if ((index >= limit) || (text [index++] != '-')) break;
if ((index >= limit) || !IsDigit (text [index])) break;
int day = (text [index++] - '0') * 10;
if ((index >= limit) || !IsDigit (text [index])) break;
day += (text [index++] - '0');
// Detect zulu time zone
if ((index < limit)&& (text [index] == 'Z')) {
return (new Date (day, month, year, true));
}
// Detect time offsets
if ((index < limit)&& (text [index] == '+')) {
++index;
if ((index >= limit) && !IsDigit (text [index])) break;
int offset = (text [index++] - '0') * 600;
if ((index >= limit) && !IsDigit (text [index])) break;
offset += (text [index++] - '0') * 60;
if ((index >= limit) && (text [index++] != ':')) break;
if ((index >= limit) && !IsDigit (text [index])) break;
offset = (text [index++] - '0') * 10;
if ((index >= limit) && !IsDigit (text [index])) break;
offset += (text [index++] - '0');
return (new Date (day, month, year, offset));
}
if ((index < limit)&& (text [index] == '-')) {
++index;
if ((index >= limit) && !IsDigit (text [index])) break;
int offset = (text [index++] - '0') * 600;
if ((index >= limit) && !IsDigit (text [index])) break;
offset += (text [index++] - '0') * 60;
if ((index >= limit) && (text [index++] != ':')) break;
if ((index >= limit) && !IsDigit (text [index])) break;
offset = (text [index++] - '0') * 10;
if ((index >= limit) && !IsDigit (text [index])) break;
offset += (text [index++] - '0');
return (new Date (day, month, year, -offset));
}
return (new Date (day, month, year, false));
}
throw new ArgumentException ("Value is not in ISO date format");
}