Exemplo n.º 1
0
        public void WriteTimeZone(PosixTz tz)
        {
            WriteName(tz.name);
            WriteTimeOffset(tz.offset);
            var dst = tz.dst;

            if (dst != null)
            {
                WriteName(dst.name);
                if (dst.offset != PosixTz.GetDefaultDstOffset(tz.offset))
                {
                    WriteTimeOffset(dst.offset);
                }
                sb.Append(",");
                WriteRule(dst.start);
                sb.Append(",");
                WriteRule(dst.end);
            }
        }
Exemplo n.º 2
0
        //std offset [dst[offset],start[/time],end[/time]]
        public PosixTz ReadExpandedTimeZone()
        {
            SkipWhiteSpaces();
            string std_name = null;

            if (!ReadName(ref std_name) || std_name.Length < 3)
            {
                //std is required and should be no less than three characters
                RaiseParseError();
            }

            SkipWhiteSpaces();
            int std_ofs = 0;

            if (!ReadTimeOffset(ref std_ofs))
            {
                //The offset following std shall be required.
                RaiseParseError();
            }

            SkipWhiteSpaces();
            if (AtEnd())
            {
                //if dst is missing, then the alternative time does not apply in this locale.
                return(new PosixTz(std_name, std_ofs, null));
            }

            //parse dst clause
            string dst_name = null;

            if (!ReadName(ref dst_name))
            {
                //dst clause should begin with dst name which should be no less than three characters
                RaiseParseError();
            }

            SkipWhiteSpaces();
            int dst_offset = 0;

            if (!ReadTimeOffset(ref dst_offset))
            {
                //if no offset follows dst, the alternative time is assumed to be one hour ahead
                //of standard time.
                dst_offset = PosixTz.GetDefaultDstOffset(std_ofs);
            }

            SkipWhiteSpaces();
            if (!ReadSpecChar(',', ';'))
            {
                //no rules is specified
                RaiseParseError();
            }

            SkipWhiteSpaces();
            PosixTz.DstRule start = null;
            if (!ReadRule(ref start))
            {
                //start rule is not specified
                RaiseParseError();
            }

            SkipWhiteSpaces();
            if (!ReadSpecChar(',', ';'))
            {
                //end rule is not specified
                RaiseParseError();
            }

            SkipWhiteSpaces();
            PosixTz.DstRule end = null;
            if (!ReadRule(ref end))
            {
                //end rule is not specified
                RaiseParseError();
            }

            var dst = new PosixTz.Dst(dst_name, dst_offset, start, end);

            SkipWhiteSpaces();
            if (!AtEnd())
            {
                //unexpected
                RaiseParseError();
            }

            return(new PosixTz(std_name, std_ofs, dst));
        }