本文整理汇总了C#中System.DateTimeResult.SetDate方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeResult.SetDate方法的具体用法?C# DateTimeResult.SetDate怎么用?C# DateTimeResult.SetDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTimeResult
的用法示例。
在下文中一共展示了DateTimeResult.SetDate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDayOfMNN
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;
}
示例2: SetDateYMD
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;
}
示例3: GetDayOfMNN
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;
}
示例4: SetDateYMD
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);
}
示例5: GetDayOfMNN
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"));
}
示例6: SetDateYMD
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);
}