本文整理汇总了C#中System.DateTimeResult类的典型用法代码示例。如果您正苦于以下问题:C# DateTimeResult类的具体用法?C# DateTimeResult怎么用?C# DateTimeResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeResult类属于System命名空间,在下文中一共展示了DateTimeResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseExact
internal static DateTime ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) {
DateTimeResult result = new DateTimeResult(); // The buffer to store the parsing result.
result.Init();
if (TryParseExact(s, format, dtfi, style, ref result)) {
return result.parsedDate;
}
else {
throw GetDateTimeParseException(ref result);
}
}
示例2: TryParseExact
internal static bool TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result) {
result = DateTime.MinValue;
DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result.
resultData.Init();
if (TryParseExact(s, format, dtfi, style, ref resultData)) {
result = resultData.parsedDate;
return true;
}
return false;
}
示例3: TryParseExact
internal static bool TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset) {
result = DateTime.MinValue;
offset = TimeSpan.Zero;
DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result.
resultData.Init();
resultData.flags |= ParseFlags.CaptureOffset;
if (TryParseExact(s, format, dtfi, style, ref resultData)) {
result = resultData.parsedDate;
offset = resultData.timeZoneOffset;
return true;
}
return false;
}
示例4: TryParseExact
internal static bool TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, out DateTime result)
{
DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider);
result = DateTime.MinValue;
DateTimeResult resultData = new DateTimeResult(); // The buffer to store the parsing result.
resultData.Init();
if (TryParseExact(s, format, dtfi, style, ref resultData))
{
result = resultData.parsedDate;
return true;
}
return false;
}
示例5: ParseExact
internal static DateTime ParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style)
{
DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider);
DateTimeResult result = new DateTimeResult(); // The buffer to store the parsing result.
result.Init();
if (TryParseExact(s, format, dtfi, style, ref result))
{
return result.parsedDate;
}
else
{
throw GetDateTimeParseException(ref result);
}
}
示例6: TryParseExact
internal static bool TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result) {
if (s == null) {
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
return false;
}
if (format == null) {
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "format");
return false;
}
if (s.Length == 0) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (format.Length == 0) {
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
}
BCLDebug.Assert(dtfi != null, "dtfi == null");
return DoStrictParse(s, format, style, dtfi, ref result);
}
示例7: Lex
private static bool Lex(DateTimeParse.DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi)
{
dtok.dtt = DateTimeParse.DTT.Unk;
TokenType tokenType;
int num;
str.GetRegularToken(out tokenType, out num, dtfi);
switch (tokenType)
{
case TokenType.NumberToken:
case TokenType.YearNumberToken:
{
if (raw.numCount == 3 || num == -1)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (dps == DateTimeParse.DS.T_NNt && str.Index < str.len - 1)
{
char c = str.Value[str.Index];
if (c == '.')
{
DateTimeParse.ParseFraction(ref str, out raw.fraction);
}
}
if ((dps == DateTimeParse.DS.T_NNt || dps == DateTimeParse.DS.T_Nt) && str.Index < str.len - 1 && !DateTimeParse.HandleTimeZone(ref str, ref result))
{
return false;
}
dtok.num = num;
if (tokenType != TokenType.YearNumberToken)
{
int index;
char current;
TokenType separatorToken;
TokenType tokenType2 = separatorToken = str.GetSeparatorToken(dtfi, out index, out current);
if (separatorToken > TokenType.SEP_YearSuff)
{
if (separatorToken <= TokenType.SEP_HourSuff)
{
if (separatorToken == TokenType.SEP_MonthSuff || separatorToken == TokenType.SEP_DaySuff)
{
dtok.dtt = DateTimeParse.DTT.NumDatesuff;
dtok.suffix = tokenType2;
break;
}
if (separatorToken != TokenType.SEP_HourSuff)
{
goto IL_52A;
}
}
else
{
if (separatorToken <= TokenType.SEP_SecondSuff)
{
if (separatorToken != TokenType.SEP_MinuteSuff && separatorToken != TokenType.SEP_SecondSuff)
{
goto IL_52A;
}
}
else
{
if (separatorToken == TokenType.SEP_LocalTimeMark)
{
dtok.dtt = DateTimeParse.DTT.NumLocalTimeMark;
raw.AddNumber(dtok.num);
break;
}
if (separatorToken != TokenType.SEP_DateOrOffset)
{
goto IL_52A;
}
if (DateTimeParse.dateParsingStates[(int)dps][4] == DateTimeParse.DS.ERROR && DateTimeParse.dateParsingStates[(int)dps][3] > DateTimeParse.DS.ERROR)
{
str.Index = index;
str.m_current = current;
dtok.dtt = DateTimeParse.DTT.NumSpace;
}
else
{
dtok.dtt = DateTimeParse.DTT.NumDatesep;
}
raw.AddNumber(dtok.num);
break;
}
}
dtok.dtt = DateTimeParse.DTT.NumTimesuff;
dtok.suffix = tokenType2;
break;
}
if (separatorToken <= TokenType.SEP_Am)
{
if (separatorToken == TokenType.SEP_End)
{
dtok.dtt = DateTimeParse.DTT.NumEnd;
raw.AddNumber(dtok.num);
break;
}
if (separatorToken == TokenType.SEP_Space)
{
dtok.dtt = DateTimeParse.DTT.NumSpace;
//.........这里部分代码省略.........
示例8: TryParseExactMultiple
internal static bool TryParseExactMultiple(string s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result)
{
if (s == null)
{
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
return false;
}
if (formats == null)
{
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats");
return false;
}
if (s.Length == 0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (formats.Length == 0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
}
for (int i = 0; i < formats.Length; i++)
{
if (formats[i] == null || formats[i].Length == 0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
}
DateTimeResult dateTimeResult = default(DateTimeResult);
dateTimeResult.Init();
dateTimeResult.flags = result.flags;
if (DateTimeParse.TryParseExact(s, formats[i], dtfi, style, ref dateTimeResult))
{
result.parsedDate = dateTimeResult.parsedDate;
result.timeZoneOffset = dateTimeResult.timeZoneOffset;
return true;
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
示例9: DoStrictParse
private static bool DoStrictParse(string s, string formatParam, DateTimeStyles styles, DateTimeFormatInfo dtfi, ref DateTimeResult result)
{
ParsingInfo parsingInfo = default(ParsingInfo);
parsingInfo.Init();
parsingInfo.calendar = dtfi.Calendar;
parsingInfo.fAllowInnerWhite = ((styles & DateTimeStyles.AllowInnerWhite) != DateTimeStyles.None);
parsingInfo.fAllowTrailingWhite = ((styles & DateTimeStyles.AllowTrailingWhite) != DateTimeStyles.None);
if (formatParam.Length == 1)
{
if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0 && formatParam[0] == 'U')
{
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
}
formatParam = DateTimeParse.ExpandPredefinedFormat(formatParam, ref dtfi, ref parsingInfo, ref result);
}
result.calendar = parsingInfo.calendar;
if (parsingInfo.calendar.ID == 8)
{
parsingInfo.parseNumberDelegate = DateTimeParse.m_hebrewNumberParser;
parsingInfo.fCustomNumberParser = true;
}
result.Hour = (result.Minute = (result.Second = -1));
__DTString _DTString = new __DTString(formatParam, dtfi, false);
__DTString _DTString2 = new __DTString(s, dtfi, false);
if (parsingInfo.fAllowTrailingWhite)
{
_DTString.TrimTail();
_DTString.RemoveTrailingInQuoteSpaces();
_DTString2.TrimTail();
}
if ((styles & DateTimeStyles.AllowLeadingWhite) != DateTimeStyles.None)
{
_DTString.SkipWhiteSpaces();
_DTString.RemoveLeadingInQuoteSpaces();
_DTString2.SkipWhiteSpaces();
}
while (_DTString.GetNext())
{
if (parsingInfo.fAllowInnerWhite)
{
_DTString2.SkipWhiteSpaces();
}
if (!DateTimeParse.ParseByFormat(ref _DTString2, ref _DTString, ref parsingInfo, dtfi, ref result))
{
return false;
}
}
if (_DTString2.Index < _DTString2.Value.Length - 1)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (parsingInfo.fUseTwoDigitYear && (dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) == DateTimeFormatFlags.None)
{
if (result.Year >= 100)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
result.Year = parsingInfo.calendar.ToFourDigitYear(result.Year);
}
if (parsingInfo.fUseHour12)
{
if (parsingInfo.timeMark == DateTimeParse.TM.NotSet)
{
parsingInfo.timeMark = DateTimeParse.TM.AM;
}
if (result.Hour > 12)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (parsingInfo.timeMark == DateTimeParse.TM.AM)
{
if (result.Hour == 12)
{
result.Hour = 0;
}
}
else
{
result.Hour = ((result.Hour == 12) ? 12 : (result.Hour + 12));
}
}
else
{
if ((parsingInfo.timeMark == DateTimeParse.TM.AM && result.Hour >= 12) || (parsingInfo.timeMark == DateTimeParse.TM.PM && result.Hour < 12))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
bool flag = result.Year == -1 && result.Month == -1 && result.Day == -1;
if (!DateTimeParse.CheckDefaultDateTime(ref result, ref parsingInfo.calendar, styles))
{
return false;
}
if (!flag && dtfi.HasYearMonthAdjustment && !dtfi.YearMonthAdjustment(ref result.Year, ref result.Month, (result.flags & ParseFlags.ParsedMonthName) != (ParseFlags)0))
{
//.........这里部分代码省略.........
示例10: ExpandPredefinedFormat
private static string ExpandPredefinedFormat(string format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
{
char c = format[0];
if (c <= 'R')
{
if (c != 'O')
{
if (c != 'R')
{
goto IL_160;
}
goto IL_65;
}
}
else
{
if (c != 'U')
{
switch (c)
{
case 'o':
{
break;
}
case 'p':
case 'q':
case 't':
{
goto IL_160;
}
case 'r':
{
goto IL_65;
}
case 's':
{
dtfi = DateTimeFormatInfo.InvariantInfo;
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
goto IL_160;
}
case 'u':
{
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0)
{
result.flags |= ParseFlags.UtcSortPattern;
goto IL_160;
}
goto IL_160;
}
default:
{
goto IL_160;
}
}
}
else
{
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = new TimeSpan(0L);
result.flags |= ParseFlags.TimeZoneUtc;
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
{
dtfi = (DateTimeFormatInfo)dtfi.Clone();
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
goto IL_160;
}
goto IL_160;
}
}
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
goto IL_160;
IL_65:
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0)
{
result.flags |= ParseFlags.Rfc1123Pattern;
}
IL_160:
return DateTimeFormat.GetRealFormat(format, dtfi);
}
示例11: GetDateTimeNow
private static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeStyles styles)
{
if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0)
{
if ((result.flags & ParseFlags.TimeZoneUsed) != (ParseFlags)0)
{
return new DateTime(DateTime.UtcNow.Ticks + result.timeZoneOffset.Ticks, DateTimeKind.Unspecified);
}
if ((styles & 64) != 0)
{
return DateTime.UtcNow;
}
}
return DateTime.Now;
}
示例12: 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);
//.........这里部分代码省略.........
示例13: GetDateOfNDS
private static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
{
if (result.Month == -1)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (result.Year != -1)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
result.Year = DateTimeParse.AdjustYear(ref result, raw.GetNumber(0));
result.Day = 1;
return true;
}
示例14: 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;
}
示例15: AdjustTimeZoneToUniversal
private static bool AdjustTimeZoneToUniversal(ref DateTimeResult result)
{
long num = result.parsedDate.Ticks;
num -= result.timeZoneOffset.Ticks;
if (num < 0L)
{
num += 864000000000L;
}
if (num < 0L || num > 3155378975999999999L)
{
result.SetFailure(ParseFailureKind.Format, "Format_DateOutOfRange", null);
return false;
}
result.parsedDate = new DateTime(num, DateTimeKind.Utc);
return true;
}