本文整理汇总了C#中System.DateTimeRawInfo类的典型用法代码示例。如果您正苦于以下问题:C# DateTimeRawInfo类的具体用法?C# DateTimeRawInfo怎么用?C# DateTimeRawInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeRawInfo类属于System命名空间,在下文中一共展示了DateTimeRawInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDayOfNNY
private static Boolean GetDayOfNNY(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;
}
if (order == ORDER_MDY || order == ORDER_YMD) {
if (SetDateYMD(ref result, raw.year, n1, n2)) {
result.flags |= ParseFlags.HaveDate;
return true; // MD + Year
}
} else {
if (SetDateYMD(ref result, raw.year, n2, n1)) {
result.flags |= ParseFlags.HaveDate;
return true; // DM + Year
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
示例2: ProcessHebrewTerminalState
internal static bool ProcessHebrewTerminalState(DateTimeParse.DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
{
switch (dps)
{
case DateTimeParse.DS.DX_MN:
case DateTimeParse.DS.DX_NM:
{
DateTimeParse.GetDefaultYear(ref result, ref styles);
if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, true))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
}
if (!DateTimeParse.GetHebrewDayOfNM(ref result, ref raw, dtfi))
{
return false;
}
goto IL_160;
}
case DateTimeParse.DS.DX_MNN:
{
raw.year = raw.GetNumber(1);
if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
}
if (!DateTimeParse.GetDayOfMNN(ref result, ref raw, dtfi))
{
return false;
}
goto IL_160;
}
case DateTimeParse.DS.DX_YMN:
{
if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
}
if (!DateTimeParse.GetDayOfYMN(ref result, ref raw, dtfi))
{
return false;
}
goto IL_160;
}
case DateTimeParse.DS.DX_YM:
{
if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
}
if (!DateTimeParse.GetDayOfYM(ref result, ref raw, dtfi))
{
return false;
}
goto IL_160;
}
case DateTimeParse.DS.TX_N:
{
if (!DateTimeParse.GetTimeOfN(dtfi, ref result, ref raw))
{
return false;
}
goto IL_160;
}
case DateTimeParse.DS.TX_NN:
{
if (!DateTimeParse.GetTimeOfNN(dtfi, ref result, ref raw))
{
return false;
}
goto IL_160;
}
case DateTimeParse.DS.TX_NNN:
{
if (!DateTimeParse.GetTimeOfNNN(dtfi, ref result, ref raw))
{
return false;
}
goto IL_160;
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
IL_160:
if (dps > DateTimeParse.DS.ERROR)
{
raw.numCount = 0;
}
return true;
}
示例3: ParseISO8601
private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
{
if (raw.year >= 0 && raw.GetNumber(0) >= 0)
{
raw.GetNumber(1);
}
str.Index--;
int second = 0;
double num = 0.0;
str.SkipWhiteSpaces();
int hour;
if (!DateTimeParse.ParseDigits(ref str, 2, out hour))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.SkipWhiteSpaces();
if (!str.Match(':'))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.SkipWhiteSpaces();
int minute;
if (!DateTimeParse.ParseDigits(ref str, 2, out minute))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.SkipWhiteSpaces();
if (str.Match(':'))
{
str.SkipWhiteSpaces();
if (!DateTimeParse.ParseDigits(ref str, 2, out second))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (str.Match('.'))
{
if (!DateTimeParse.ParseFraction(ref str, out num))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.Index--;
}
str.SkipWhiteSpaces();
}
if (str.GetNext())
{
char @char = str.GetChar();
if (@char == '+' || @char == '-')
{
result.flags |= ParseFlags.TimeZoneUsed;
if (!DateTimeParse.ParseTimeZone(ref str, ref result.timeZoneOffset))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
else
{
if (@char == 'Z' || @char == 'z')
{
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
result.flags |= ParseFlags.TimeZoneUtc;
}
else
{
str.Index--;
}
}
str.SkipWhiteSpaces();
if (str.Match('#'))
{
if (!DateTimeParse.VerifyValidPunctuation(ref str))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.SkipWhiteSpaces();
}
if (str.Match('\0') && !DateTimeParse.VerifyValidPunctuation(ref str))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (str.GetNext())
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
Calendar defaultInstance = GregorianCalendar.GetDefaultInstance();
DateTime parsedDate;
if (!defaultInstance.TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1), hour, minute, second, 0, result.era, out parsedDate))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
//.........这里部分代码省略.........
示例4: GetDateOfDSN
private static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo raw)
{
if (raw.numCount != 1 || result.Day != -1)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
result.Day = raw.GetNumber(0);
return true;
}
示例5: GetDateOfNNDS
private static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
{
if ((result.flags & ParseFlags.HaveYear) != (ParseFlags)0)
{
if ((result.flags & ParseFlags.HaveMonth) == (ParseFlags)0 && (result.flags & ParseFlags.HaveDay) == (ParseFlags)0 && DateTimeParse.SetDateYMD(ref result, result.Year = DateTimeParse.AdjustYear(ref result, raw.year), raw.GetNumber(0), raw.GetNumber(1)))
{
return true;
}
}
else
{
if ((result.flags & ParseFlags.HaveMonth) != (ParseFlags)0 && (result.flags & ParseFlags.HaveYear) == (ParseFlags)0 && (result.flags & ParseFlags.HaveDay) == (ParseFlags)0)
{
int num;
if (!DateTimeParse.GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out num))
{
result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
return false;
}
if (num == 0)
{
if (DateTimeParse.SetDateYMD(ref result, DateTimeParse.AdjustYear(ref result, raw.GetNumber(0)), result.Month, raw.GetNumber(1)))
{
return true;
}
}
else
{
if (DateTimeParse.SetDateYMD(ref result, DateTimeParse.AdjustYear(ref result, raw.GetNumber(1)), result.Month, raw.GetNumber(0)))
{
return true;
}
}
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
示例6: GetDayOfYM
private static bool GetDayOfYM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
{
if ((result.flags & ParseFlags.HaveDate) != (ParseFlags)0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (DateTimeParse.SetDateYMD(ref result, raw.year, raw.month, 1))
{
result.flags |= ParseFlags.HaveDate;
return true;
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
示例7: GetTimeOfN
private static bool GetTimeOfN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
{
if ((result.flags & ParseFlags.HaveTime) != (ParseFlags)0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (raw.timeMark == DateTimeParse.TM.NotSet)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
result.Hour = raw.GetNumber(0);
result.flags |= ParseFlags.HaveTime;
return true;
}
示例8: GetDateOfNNDS
private static Boolean GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
{
// For partial CJK Dates, the only valid formats are with a specified year, followed by two numbers, which
// will be the Month and Day, and with a specified Month, when the numbers are either the year and day or
// day and year, depending on the short date pattern.
if ((result.flags & ParseFlags.HaveYear) != 0) {
if (((result.flags & ParseFlags.HaveMonth) == 0) && ((result.flags & ParseFlags.HaveDay) == 0)) {
if (TryAdjustYear(ref result, raw.year, out result.Year) && SetDateYMD(ref result, result.Year, raw.GetNumber(0), raw.GetNumber(1))) {
return true;
}
}
}
else if ((result.flags & ParseFlags.HaveMonth) != 0) {
if (((result.flags & ParseFlags.HaveYear) == 0) && ((result.flags & ParseFlags.HaveDay) == 0)) {
int order;
if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out order)) {
result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
return false;
}
int year;
if (order == ORDER_YMD) {
if (TryAdjustYear(ref result, raw.GetNumber(0), out year) && SetDateYMD(ref result, year, result.Month, raw.GetNumber(1))) {
return true;
}
}
else {
if (TryAdjustYear(ref result, raw.GetNumber(1), out year) && SetDateYMD(ref result, year, result.Month, raw.GetNumber(0))){
return true;
}
}
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
示例9: ProcessDateTimeSuffix
//
// A date suffix is found, use this method to put the number into the result.
//
private static bool ProcessDateTimeSuffix(ref DateTimeResult result, ref DateTimeRawInfo raw, ref DateTimeToken dtok)
{
switch (dtok.suffix)
{
case TokenType.SEP_YearSuff:
if ((result.flags & ParseFlags.HaveYear) != 0) {
return false;
}
result.flags |= ParseFlags.HaveYear;
result.Year = raw.year = dtok.num;
break;
case TokenType.SEP_MonthSuff:
if ((result.flags & ParseFlags.HaveMonth) != 0) {
return false;
}
result.flags |= ParseFlags.HaveMonth;
result.Month= raw.month = dtok.num;
break;
case TokenType.SEP_DaySuff:
if ((result.flags & ParseFlags.HaveDay) != 0) {
return false;
}
result.flags |= ParseFlags.HaveDay;
result.Day = dtok.num;
break;
case TokenType.SEP_HourSuff:
if ((result.flags & ParseFlags.HaveHour) != 0) {
return false;
}
result.flags |= ParseFlags.HaveHour;
result.Hour = dtok.num;
break;
case TokenType.SEP_MinuteSuff:
if ((result.flags & ParseFlags.HaveMinute) != 0) {
return false;
}
result.flags |= ParseFlags.HaveMinute;
result.Minute = dtok.num;
break;
case TokenType.SEP_SecondSuff:
if ((result.flags & ParseFlags.HaveSecond) != 0) {
return false;
}
result.flags |= ParseFlags.HaveSecond;
result.Second = dtok.num;
break;
}
return true;
}
示例10: GetTimeOfNNN
private static Boolean GetTimeOfNNN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
{
if ((result.flags & ParseFlags.HaveTime) != 0) {
// Multiple times in the input string
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
Contract.Assert(raw.numCount >= 3, "raw.numCount >= 3");
result.Hour = raw.GetNumber(0);
result.Minute = raw.GetNumber(1);
result.Second = raw.GetNumber(2);
result.flags |= ParseFlags.HaveTime;
return true;
}
示例11: GetDateOfNDS
private static Boolean GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
{
if (result.Month == -1)
{
//Should have a month suffix
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (result.Year != -1)
{
// Aleady has a year suffix
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (!TryAdjustYear(ref result, raw.GetNumber(0), out result.Year))
{
// the year value is out of range
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
result.Day = 1;
return true;
}
示例12: GetTimeOfN
private static Boolean GetTimeOfN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
{
if ((result.flags & ParseFlags.HaveTime) != 0) {
// Multiple times in the input string
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
//
// In this case, we need a time mark. Check if so.
//
if (raw.timeMark == TM.NotSet)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
result.Hour = raw.GetNumber(0);
result.flags |= ParseFlags.HaveTime;
return true;
}
示例13: AdjustTimeMark
private static void AdjustTimeMark(DateTimeFormatInfo dtfi, ref DateTimeRawInfo raw) {
// Specail case for culture which uses AM as empty string.
// E.g. af-ZA (0x0436)
// S1159 \x0000
// S2359 nm
// In this case, if we are parsing a string like "2005/09/14 12:23", we will assume this is in AM.
if (raw.timeMark == TM.NotSet) {
if (dtfi.AMDesignator != null && dtfi.PMDesignator != null) {
if (dtfi.AMDesignator.Length == 0 && dtfi.PMDesignator.Length != 0) {
raw.timeMark = TM.AM;
}
if (dtfi.PMDesignator.Length == 0 && dtfi.AMDesignator.Length != 0) {
raw.timeMark = TM.PM;
}
}
}
}
示例14: GetDayOfYM
private static Boolean GetDayOfYM(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;
}
if (SetDateYMD(ref result, raw.year, raw.month, 1))
{
result.flags |= ParseFlags.HaveDate;
return true;
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
示例15: 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;
}