private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
        {
            switch (format[0])
            {
            case 'o':
            case 'O':
                dtfi = DateTimeFormatInfo.InvariantInfo;
                goto Label_0160;

            case 'r':
            case 'R':
                if (offset != NullOffset)
                {
                    dateTime -= offset;
                }
                else if (dateTime.Kind == DateTimeKind.Local)
                {
                    InvalidFormatForLocal(format, dateTime);
                }
                dtfi = DateTimeFormatInfo.InvariantInfo;
                goto Label_0160;

            case 's':
                dtfi = DateTimeFormatInfo.InvariantInfo;
                goto Label_0160;

            case 'u':
                if (offset == NullOffset)
                {
                    if (dateTime.Kind == DateTimeKind.Local)
                    {
                        InvalidFormatForLocal(format, dateTime);
                    }
                    break;
                }
                dateTime -= offset;
                break;

            case 'U':
                if (offset != NullOffset)
                {
                    throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                }
                dtfi = (DateTimeFormatInfo)dtfi.Clone();
                if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
                {
                    dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
                }
                dateTime = dateTime.ToUniversalTime();
                goto Label_0160;

            default:
                goto Label_0160;
            }
            dtfi = DateTimeFormatInfo.InvariantInfo;
Label_0160:
            format = GetRealFormat(format, dtfi);
            return(format);
        }
        private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
        {
            switch (format[0])
            {
                case 'o':
                case 'O':
                    dtfi = DateTimeFormatInfo.InvariantInfo;
                    goto Label_0160;

                case 'r':
                case 'R':
                    if (offset != NullOffset)
                    {
                        dateTime -= offset;
                    }
                    else if (dateTime.Kind == DateTimeKind.Local)
                    {
                        InvalidFormatForLocal(format, dateTime);
                    }
                    dtfi = DateTimeFormatInfo.InvariantInfo;
                    goto Label_0160;

                case 's':
                    dtfi = DateTimeFormatInfo.InvariantInfo;
                    goto Label_0160;

                case 'u':
                    if (offset == NullOffset)
                    {
                        if (dateTime.Kind == DateTimeKind.Local)
                        {
                            InvalidFormatForLocal(format, dateTime);
                        }
                        break;
                    }
                    dateTime -= offset;
                    break;

                case 'U':
                    if (offset != NullOffset)
                    {
                        throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                    }
                    dtfi = (DateTimeFormatInfo) dtfi.Clone();
                    if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
                    {
                        dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
                    }
                    dateTime = dateTime.ToUniversalTime();
                    goto Label_0160;

                default:
                    goto Label_0160;
            }
            dtfi = DateTimeFormatInfo.InvariantInfo;
        Label_0160:
            format = GetRealFormat(format, dtfi);
            return format;
        }
Ejemplo n.º 3
0
			public void ConvertToUtc_MatchDateTimeBehavior ()
			{
				for (DateTime date = new DateTime (2007, 01, 01, 0, 0, 0); date < new DateTime (2007, 12, 31, 23, 59, 59); date += new TimeSpan (0,1,0)) {
					Assert.AreEqual (TimeZoneInfo.ConvertTimeToUtc (date), date.ToUniversalTime ());
				}
			}