Example #1
0
            public TimeSpan Execute()
            {
                int num = 0;

                this.ParseWhiteSpace();
                bool flag = this.ParseSign();
                int  num2 = this.ParseInt(false);

                if (this.ParseOptDot())
                {
                    num = this.ParseInt(true);
                }
                else if (!this.AtEnd)
                {
                    num  = num2;
                    num2 = 0;
                }
                this.ParseOptColon();
                int num3 = this.ParseInt(true);

                this.ParseOptColon();
                int  num4 = this.ParseInt(true);
                long num5;

                if (this.ParseOptDot())
                {
                    num5 = this.ParseTicks();
                }
                else
                {
                    num5 = 0L;
                }
                this.ParseWhiteSpace();
                if (!this.AtEnd)
                {
                    this.formatError = true;
                }
                if (num > 23 || num3 > 59 || num4 > 59)
                {
                    throw new OverflowException(Locale.GetText("Invalid time data."));
                }
                if (this.formatError)
                {
                    throw new FormatException(Locale.GetText("Invalid format for TimeSpan.Parse."));
                }
                long num6 = TimeSpan.CalculateTicks(num2, num, num3, num4, 0);

                num6 = checked ((!flag) ? (num6 + num5) : ((long)(unchecked ((ulong)0) - (ulong)num6 - (ulong)num5)));
                return(new TimeSpan(num6));
            }
Example #2
0
            public TimeSpan Execute()
            {
                bool sign;
                int  days;
                int  hours = 0;
                int  minutes;
                int  seconds;
                long ticks;

                // documented as...
                // Parse [ws][-][dd.]hh:mm:ss[.ff][ws]
                // ... but not entirely true as an lonely
                // integer will be parsed as a number of days
                ParseWhiteSpace();
                sign = ParseSign();
                days = ParseInt(false);
                if (ParseOptDot())
                {
                    hours = ParseInt(true);
                }
                else if (!AtEnd)
                {
                    hours = days;
                    days  = 0;
                }
                ParseOptColon();
                minutes = ParseInt(true);
                ParseOptColon();
                seconds = ParseInt(true);
                if (ParseOptDot())
                {
                    ticks = ParseTicks();
                }
                else
                {
                    ticks = 0;
                }
                ParseWhiteSpace();

                if (!AtEnd)
                {
                    formatError = true;
                }

                // Overflow has presceance over FormatException
                if (hours > 23 || minutes > 59 || seconds > 59)
                {
                    throw new OverflowException(
                              Locale.GetText("Invalid time data."));
                }
                else if (formatError)
                {
                    throw new FormatException(
                              Locale.GetText("Invalid format for TimeSpan.Parse."));
                }

                long t = TimeSpan.CalculateTicks(days, hours, minutes, seconds, 0);

                t = checked ((sign) ? (-t - ticks) : (t + ticks));
                return(new TimeSpan(t));
            }