コード例 #1
0
 public static bool LogicallyEquals(TimeZoneViewModel left, TimeZoneViewModel right)
 {
     return(Object.ReferenceEquals(left, right) || (
                !Object.ReferenceEquals(left, null) && (
                    PosixTz.LogicallyEquals(left.posixTz, right.posixTz) &&
                    ((object)left.posixTz != null || left.originalString == right.originalString)
                    )
                ));
 }
コード例 #2
0
        private void Init(Model model)
        {
            //Save model handle
            this.model = model;

            originPosixTz = PosixTz.TryParse(model.timeZone);
            if (model.utcDateTime != null)
            {
                originUtcDateTime = model.utcDateTime.Value;
            }
            else if ((object)originPosixTz != null && model.localDateTime != null)
            {
                try{
                    originUtcDateTime = originPosixTz.ConvertLocalTimeToUtc(
                        (DateTime)model.localDateTime, model.origin.daylightSavings
                        );
                }catch (Exception err) {
                    dbg.Error(err);
                }
            }


            //Init command
            OnCompleted += () => { disposables.Dispose(); };

            //var applyCommand = new DelegateCommand(
            //    () => OnApplyChanges(),
            //    () => true
            //);
            //ApplyCommand = applyCommand;

            var closeCommand = new DelegateCommand(
                () => Success(new Result.Close()),
                () => true
                );

            CloseCommand = closeCommand;

            var cancelCommand = new DelegateCommand(
                () => {
                OnRevertChanges();
            },
                () => true
                );

            CancelCommand = cancelCommand;

            //init all UI controls
            InitializeComponent();
            //Init time zones
            InitTimeZones();
            //Init and fill
            Init();
            //set up local strings
            Localization();
        }
コード例 #3
0
        void ValidateUI()
        {
            var pos = PosixTz.TryParse(posixTZ);

            if (pos == null)
            {
                borderTZ.BorderBrush = Brushes.Red;
            }
            else
            {
                borderTZ.BorderBrush = Brushes.Transparent;
            }
        }
コード例 #4
0
		public void WriteTime(PosixTz.TimeUnit time) {
			sb.Append(time.hours);
			if (time.minutes == 0 && time.seconds == 0) {
				return;
			}
			sb.Append(":");
			sb.Append(time.minutes);
			if (time.seconds == 0) {
				return;
			}
			sb.Append(":");
			sb.Append(time.seconds);
		}
コード例 #5
0
		private void Init(Model model) {
			//Save model handle
			this.model = model;

			originPosixTz = PosixTz.TryParse(model.timeZone);
			if(model.utcDateTime != null){
				originUtcDateTime = model.utcDateTime.Value;
			} else if ((object)originPosixTz != null && model.localDateTime != null) {
				try{
					originUtcDateTime = originPosixTz.ConvertLocalTimeToUtc(
						(DateTime)model.localDateTime, model.origin.daylightSavings
					);
				}catch(Exception err){
					dbg.Error(err);
				}
			}
			

			//Init command
			OnCompleted += () => {disposables.Dispose();};

			//var applyCommand = new DelegateCommand(
			//    () => OnApplyChanges(),
			//    () => true
			//);
			//ApplyCommand = applyCommand;

			var closeCommand = new DelegateCommand(
				() => Success(new Result.Close()),
				() => true
			);
			CloseCommand = closeCommand;

			var cancelCommand = new DelegateCommand(
				() => {
					OnRevertChanges();
				},
				() => true
			);
			CancelCommand = cancelCommand;

			//init all UI controls
			InitializeComponent();
			//Init time zones
			InitTimeZones();
			//Init and fill
			Init();
			//set up local strings
			Localization();
		}
コード例 #6
0
        public ManualTZ(string posixTZ)
        {
            InitializeComponent();
            this.DataContext = this;
            btnApply.Content = LocalButtons.instance.apply;

            valueTZ.CreateBinding(TextBox.TextProperty, this, t => t.posixTZ,
                                  (m, o) => {
                m.posixTZ = o;
                posix     = PosixTz.TryParse(o);
                ValidateUI();
            }
                                  );
            this.posixTZ = posixTZ;
            Loaded      += new RoutedEventHandler((o, e) => { ValidateUI(); });
            Closing     += new System.ComponentModel.CancelEventHandler(Upgrade_Closing);
        }
コード例 #7
0
        public static TimeZoneViewModel[] GetManualTimeZones(string fileName)
        {
            ManualTimeZones mtzs = null;

            try {
                var doc = new XmlDocument();
                doc.Load(fileName);
                mtzs = doc.DocumentElement.Deserialize <TimeZoneViewModel.ManualTimeZones>();
            } catch (Exception err) {
                dbg.Error(err);
                return(new TimeZoneViewModel[0]);
            }
            if (mtzs == null || mtzs.timeZones == null || mtzs.timeZones.Length == 0)
            {
                return(new TimeZoneViewModel[0]);
            }

            var tz_list = new List <TimeZoneViewModel>(256);

            foreach (var tz in mtzs.timeZones)
            {
                if (tz.posixTz != null)
                {
                    var posixTz = PosixTz.TryParse(tz.posixTz);
                    tz_list.Add(new TimeZoneViewModel(
                                    tz.displayName, tz.posixTz, posixTz
                                    ));
                }
            }

            return(tz_list.OrderBy(x => {
                if (x.posixTz != null)
                {
                    return new Tuple <int, int, string>(0, -x.posixTz.offset, x.displayName);
                }
                else
                {
                    return new Tuple <int, int, string>(1, 0, x.displayName);
                }
            }).ToArray());
        }
コード例 #8
0
		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);
			}
		}
コード例 #9
0
        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());
        }
コード例 #10
0
		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();
		}
コード例 #11
0
		public TimeZoneViewModel(string displayName, string originalString, PosixTz posixTz) {
			this.displayName = displayName;
			this.originalString = originalString;
			this.posixTz = posixTz;
		}
コード例 #12
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;
		}
コード例 #13
0
 public TimeZoneViewModel(string displayName, string originalString, PosixTz posixTz)
 {
     this.displayName    = displayName;
     this.originalString = originalString;
     this.posixTz        = posixTz;
 }
コード例 #14
0
        TimeZoneViewModel GetTimeZoneSelection()
        {
            TimeZoneViewModel timezonemosel = null;

            if (timeZonesComboBox.SelectedIndex == -1)
            {
                timezonemosel = new TimeZoneViewModel(timeZonesComboBox.Text, timeZonesComboBox.Text, PosixTz.TryParse(timeZonesComboBox.Text));
            }
            else
            {
                var tmodel = timeZonesComboBox.SelectedItem as TimeZoneViewModel;
                if (tmodel != null)
                {
                    timezonemosel = tmodel;
                }
            }
            return(timezonemosel);
        }
コード例 #15
0
		public bool ReadRule(ref PosixTz.DstRule rule) {
			return ReadFixedDateRule(ref rule) || ReadDayOfYearRule(ref rule) || ReadDayOfWeekRule(ref rule);
		}
コード例 #16
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;
		}
コード例 #17
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);
			}
		}
コード例 #18
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;
		}