private static bool parseDate(StringCharacterIterator iter, Datetime datetime)
        {
            short num = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            if (iter.current() != '-')
            {
                return(false);
            }
            iter.next();
            short num2 = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            if (iter.current() != '-')
            {
                return(false);
            }
            iter.next();
            short num3 = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            if (num != 1 || num2 != 1 || num3 != 1)
            {
                datetime.Year       = (int)num;
                datetime.Month      = (int)num2;
                datetime.DayOfMonth = (int)num3;
            }
            return(true);
        }
        public static string generateDateTz(Datetime datetime)
        {
            StringBuilder stringBuilder = new StringBuilder(16);

            DatetimeIso8601Util.generateDateTz(stringBuilder, datetime);
            return(stringBuilder.ToString());
        }
 public static void generateDate(StringBuilder sb, Datetime datetime)
 {
     DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)datetime.Year, 4);
     sb.Append('-');
     DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)datetime.Month, 2);
     sb.Append('-');
     DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)datetime.DayOfMonth, 2);
 }
        public static bool parseDatetimeTz(string strDatetime, Datetime datetime)
        {
            int num = strDatetime.IndexOf('T');

            return
                (num >= 0 &&
                 DatetimeIso8601Util.parseDate(new StringCharacterIterator(strDatetime, 0, num, 0), datetime) &&
                 DatetimeIso8601Util.parseTimeTz(new StringCharacterIterator(strDatetime, num + 1, strDatetime.Length, num + 1), datetime));
        }
 public static void generateTimezoneOffset(StringBuilder sb, Datetime datetime)
 {
     if (datetime.HasParts(Datetime.TIME_ZONE_OFFSET))
     {
         int num = datetime.TimezoneOffsetMinutes;
         if (num < 0)
         {
             num = (int)((short)(-(short)num));
             sb.Append('-');
         }
         else
         {
             sb.Append('+');
         }
         DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)(num / 60), 2);
         sb.Append(':');
         DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)(num % 60), 2);
     }
 }
        public static void generateTime(StringBuilder sb, Datetime datetime)
        {
            DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)datetime.Hour, 2);
            sb.Append(':');
            DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)datetime.Minute, 2);
            sb.Append(':');
            DatetimeIso8601Util.appendUnsignedStringValue(sb, (long)datetime.Second, 2);
            sb.Append('.');
            long num  = datetime.PicoSecond;
            int  num2 = 12;

            while (num != 0L && num % 1000L == 0L)
            {
                num  /= 1000L;
                num2 -= 3;
            }
            if (num == 0L)
            {
                num2 = 3;
            }
            DatetimeIso8601Util.appendUnsignedStringValue(sb, num, num2);
        }
        private static bool parseTime(StringCharacterIterator iter, Datetime time)
        {
            short num = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            if (iter.current() != ':')
            {
                return(false);
            }
            iter.next();
            short num2 = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            if (iter.current() != ':')
            {
                return(false);
            }
            iter.next();
            short num3 = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);
            long  num4 = 0L;

            if (iter.current() == '.')
            {
                iter.next();
                num4 = DatetimeIso8601Util.parseUnsignedFixedWidth(iter, 12);
                char c = iter.current();
                while (c != '￿' && char.IsDigit(c))
                {
                    c = iter.next();
                }
            }
            if (num != 24 || num2 != 0 || num3 != 0 || num4 != 0L)
            {
                time.Hour       = (int)num;
                time.Minute     = (int)num2;
                time.Second     = (int)num3;
                time.PicoSecond = num4;
            }
            return(true);
        }
        private static bool parseTimezoneOffset(StringCharacterIterator iter, Datetime datetime)
        {
            short num;

            if (iter.current() == '+')
            {
                num = 1;
            }
            else
            {
                if (iter.current() == '-')
                {
                    num = -1;
                }
                else
                {
                    if (iter.current() == 'Z' || iter.current() == 'z')
                    {
                        datetime.TimezoneOffsetMinutes = 0;
                        return(true);
                    }
                    return(false);
                }
            }
            iter.next();
            short num2 = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            if (iter.current() != ':')
            {
                return(false);
            }
            iter.next();
            short num3 = (short)DatetimeIso8601Util.parseUnsigned(iter, 2147483647);

            datetime.TimezoneOffsetMinutes = (int)(num * (num2 * 60 + num3));
            return(true);
        }
Example #9
0
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder(10);
            char          c             = '\0';

            if (this.HasParts(YEAR_PART) || this.HasParts(MONTH_PART) || this.HasParts(DAY_OF_MONTH_PART))
            {
                stringBuilder.Append(DatetimeIso8601Util.generateDate(this));
                c = 'T';
            }
            if (this.HasParts(HOUR_PART) || this.HasParts(MINUTE_PART) || this.HasParts(SECOND_PART) || this.HasParts(MILLISECOND_PART))
            {
                if (c != '\0')
                {
                    stringBuilder.Append(c);
                }
                stringBuilder.Append(DatetimeIso8601Util.generateTime(this));
            }
            if (this.HasParts(TIME_ZONE_OFFSET))
            {
                DatetimeIso8601Util.generateTimezoneOffset(stringBuilder, this);
            }
            return(stringBuilder.ToString());
        }
 public static void generateDatetimeTz(StringBuilder sb, Datetime datetime)
 {
     DatetimeIso8601Util.generateDatetime(sb, datetime);
     DatetimeIso8601Util.generateTimezoneOffset(sb, datetime);
 }
        public static bool parseTime(string strTime, Datetime time)
        {
            StringCharacterIterator iter = new StringCharacterIterator(strTime);

            return(DatetimeIso8601Util.parseTime(iter, time));
        }
        public static bool parseDateTz(string strDate, Datetime date)
        {
            StringCharacterIterator iter = new StringCharacterIterator(strDate);

            return(DatetimeIso8601Util.parseDateTz(iter, date));
        }
 private static bool parseTimeTz(StringCharacterIterator iter, Datetime timeTz)
 {
     return
         (DatetimeIso8601Util.parseTime(iter, timeTz) &&
          (iter.current() == '￿' || DatetimeIso8601Util.parseTimezoneOffset(iter, timeTz)));
 }