public void WriteRule(PosixTz.DstRule rule)
 {
     rule.Match(
         fixedDateRule => {
         sb.Append("J");
         sb.Append(fixedDateRule.day);
     },
         dayOfYearRule => {
         sb.Append(dayOfYearRule.day);
     },
         dayOfWeekRule => {
         sb.Append("M");
         sb.Append(dayOfWeekRule.month);
         sb.Append(".");
         sb.Append(dayOfWeekRule.week);
         sb.Append(".");
         sb.Append(dayOfWeekRule.day);
     }
         );
     if (rule.time != PosixTz.DEFAULT_RULE_TIME)
     {
         sb.Append("/");
         WriteTime(rule.time);
     }
 }
Exemple #2
0
        //Mm.n.d (the d'th day of week n of month m of the year)
        public bool ReadDayOfWeekRule(ref PosixTz.DstRule rule)
        {
            int saved_pos = pos;

            if (!ReadSpecChar('M'))
            {
                return(false);
            }
            SkipWhiteSpaces();
            int month = 0;

            if (!ReadNum(ref month) || month < 1 || month > 12)
            {
                RaiseParseError();
            }
            ;

            SkipWhiteSpaces();
            if (!ReadSpecChar('.'))
            {
                //week is missing
                RaiseParseError();
            }

            SkipWhiteSpaces();
            int week = 0;

            if (!ReadNum(ref week) || week < 1 || week > 5)
            {
                //1 <= n <= 5
                RaiseParseError();
            }
            ;

            SkipWhiteSpaces();
            if (!ReadSpecChar('.'))
            {
                //day is missing
                RaiseParseError();
            }

            SkipWhiteSpaces();
            int day = 0;

            if (!ReadNum(ref day) || day > 6)
            {
                //0 <= d <= 6
                RaiseParseError();
            }
            ;
            var time = ReadRuleTime();

            rule = new PosixTz.DstRule.DayOfWeekRule(month, week, day, time);
            return(true);
        }
Exemple #3
0
        //n (the zero-based Julian day)
        public bool ReadDayOfYearRule(ref PosixTz.DstRule rule)
        {
            int day = 0;

            if (!ReadNum(ref day))
            {
                return(false);
            }
            if (day > 365)
            {
                //0 <= n <= 365
                RaiseParseError();
            }
            ;
            var time = ReadRuleTime();

            rule = new PosixTz.DstRule.DayOfYearRule(day, time);
            return(true);
        }
Exemple #4
0
        //Jn (the Julian day n)
        public bool ReadFixedDateRule(ref PosixTz.DstRule rule)
        {
            int saved_pos = pos;

            if (!ReadSpecChar('J'))
            {
                return(false);
            }
            SkipWhiteSpaces();
            int day = 0;

            if (!ReadNum(ref day) || day < 1 || day > 365)
            {
                //1 <= n <= 365
                RaiseParseError();
            }
            ;
            var time = ReadRuleTime();

            rule = new PosixTz.DstRule.FixedDateRule(day, time);
            return(true);
        }
 public static TimeZoneInfo.TransitionTime ToSystemTransitionTime(this PosixTz.DstRule rule, int year)
 {
     return(rule.Match <TimeZoneInfo.TransitionTime>(
                fixedDate => {
         var date = fixedDate.GetDate();
         return TimeZoneInfo.TransitionTime.CreateFixedDateRule(
             fixedDate.time.ToSystemDateTime(),
             date.month + 1, date.day + 1
             );
     },
                dayOfYear => {
         var date = dayOfYear.GetDate(year);
         return TimeZoneInfo.TransitionTime.CreateFixedDateRule(
             dayOfYear.time.ToSystemDateTime(),
             date.month + 1, date.day + 1
             );
     },
                dayOfWeek => TimeZoneInfo.TransitionTime.CreateFloatingDateRule(
                    dayOfWeek.time.ToSystemDateTime(),
                    dayOfWeek.month, dayOfWeek.week, (DayOfWeek)dayOfWeek.day
                    )
                ));
 }
Exemple #6
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));
        }
Exemple #7
0
 public bool ReadRule(ref PosixTz.DstRule rule)
 {
     return(ReadFixedDateRule(ref rule) || ReadDayOfYearRule(ref rule) || ReadDayOfWeekRule(ref rule));
 }