public static TimeZoneViewModel[] GetSystemTimeZones() {
			var tz_list = new List<TimeZoneViewModel>(256);
			var sys_tzs = TimeZoneInfo.GetSystemTimeZones();
			var now = DateTime.Now;
			foreach (var tzi in sys_tzs) {
				PosixTz.Dst dst = null;
				var rule = GetSystemTimeZoneRule(now, tzi);
				var std_offset = -tzi.BaseUtcOffset.TotalSeconds.ToInt32();
				if (rule != null) {
					var start = PosixTzExtensions.GetPosixRuleFromTransitionTime(
						rule.DaylightTransitionStart
					);
					var end = PosixTzExtensions.GetPosixRuleFromTransitionTime(
						rule.DaylightTransitionEnd
					);
					var dst_offset = std_offset - rule.DaylightDelta.TotalSeconds.ToInt32();
					dst = new PosixTz.Dst(
						/*PosixTzWriter.NormalizeName(tzi.DaylightName)*/"DaylightTime", dst_offset, start, end
					);
				}
				var posixTz = new PosixTz(
					PosixTzWriter.NormalizeName(/*tzi.StandardName*/tzi.Id), std_offset, dst
				);
				tz_list.Add(new TimeZoneViewModel(
					tzi.DisplayName, null, posixTz
				));
			}

			return tz_list.OrderBy(x =>
				new Tuple<int, string>(-x.posixTz.offset, x.displayName)
			).ToArray();
		}
예제 #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));
        }
예제 #3
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);
		}