private SetDate ( int year, int month, int day ) : void | ||
year | int | |
month | int | |
day | int | |
return | void |
private static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) { if ((result.flags & ParseFlags.HaveDate) != (ParseFlags)0) { result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; } int number = raw.GetNumber(0); int number2 = raw.GetNumber(1); int num; if (!DateTimeParse.GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out num)) { result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern); return false; } if (num == 1) { int year; if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number2), raw.month, number, result.era)) { result.SetDate(year, raw.month, number); result.flags |= ParseFlags.HaveDate; return true; } if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number), raw.month, number2, result.era)) { result.SetDate(year, raw.month, number2); result.flags |= ParseFlags.HaveDate; return true; } } else { if (num == 0) { int year; if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number), raw.month, number2, result.era)) { result.SetDate(year, raw.month, number2); result.flags |= ParseFlags.HaveDate; return true; } if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number2), raw.month, number, result.era)) { result.SetDate(year, raw.month, number); result.flags |= ParseFlags.HaveDate; return true; } } else { if (num == 2) { int year; if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number2), raw.month, number, result.era)) { result.SetDate(year, raw.month, number); result.flags |= ParseFlags.HaveDate; return true; } if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number), raw.month, number2, result.era)) { result.SetDate(year, raw.month, number2); result.flags |= ParseFlags.HaveDate; return true; } } } } result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; }
private static bool SetDateYMD(ref DateTimeResult result, int year, int month, int day) { if (result.calendar.IsValidDay(year, month, day, result.era)) { result.SetDate(year, month, day); return true; } return false; }
private static Boolean GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) { if ((result.flags & ParseFlags.HaveDate) != 0) { // Multiple dates in the input string result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; } int n1 = raw.GetNumber(0); int n2 = raw.GetNumber(1); int order; if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out order)) { result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern); return false; } int year; if (order == ORDER_MDY) { if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era)) { result.SetDate(year, raw.month, n1); // MDY result.flags |= ParseFlags.HaveDate; return true; } else if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era)) { result.SetDate(year, raw.month, n2); // YMD result.flags |= ParseFlags.HaveDate; return true; } } else if (order == ORDER_YMD) { if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era)) { result.SetDate(year, raw.month, n2); // YMD result.flags |= ParseFlags.HaveDate; return true; } else if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era)) { result.SetDate(year, raw.month, n1); // DMY result.flags |= ParseFlags.HaveDate; return true; } } else if (order == ORDER_DMY) { if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era)) { result.SetDate(year, raw.month, n1); // DMY result.flags |= ParseFlags.HaveDate; return true; } else if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era)) { result.SetDate(year, raw.month, n2); // YMD result.flags |= ParseFlags.HaveDate; return true; } } result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null); return false; }
private static bool SetDateYMD(ref DateTimeResult result, int year, int month, int day) { // Note, longer term these checks should be done at the end of the parse. This current // way of checking creates order dependence with parsing the era name. if (result.calendar.IsValidDay(year, month, day, result.era)) { result.SetDate(year, month, day); // YMD return (true); } return (false); }
private static void GetDayOfMNN(DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) { int n1 = raw.num[0]; int n2 = raw.num[1]; int order = GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi); int year; if (order == ORDER_MDY) { if (IsValidDay(result, year = AdjustYear(result, n2), raw.month, n1)) { result.SetDate(year, raw.month, n1); // MDY return; } else if (IsValidDay(result, year = AdjustYear(result, n1), raw.month, n2)) { result.SetDate(year, raw.month, n2); // YMD return; } } else if (order == ORDER_YMD) { if (IsValidDay(result, year = AdjustYear(result, n1), raw.month, n2)) { result.SetDate(year, raw.month, n2); // YMD return; } else if (IsValidDay(result, year = AdjustYear(result, n2), raw.month, n1)) { result.SetDate(year, raw.month, n1); // DMY return; } } else if (order == ORDER_DMY) { if (IsValidDay(result, year = AdjustYear(result, n2), raw.month, n1)) { result.SetDate(year, raw.month, n1); // DMY return; } else if (IsValidDay(result, year = AdjustYear(result, n1), raw.month, n2)) { result.SetDate(year, raw.month, n2); // YMD return; } } throw new FormatException(Environment.GetResourceString("Format_BadDateTime")); }
private static bool SetDateYMD(DateTimeResult result, int year, int month, int day) { if (IsValidMonth(result, year, month) && IsValidDay(result, year, month, day)) { result.SetDate(year, month, day); // YMD return (true); } return (false); }