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) ) )); }
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(); }
void ValidateUI() { var pos = PosixTz.TryParse(posixTZ); if (pos == null) { borderTZ.BorderBrush = Brushes.Red; } else { borderTZ.BorderBrush = Brushes.Transparent; } }
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); }
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(); }
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); }
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()); }
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); } }
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()); }
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(); }
public TimeZoneViewModel(string displayName, string originalString, PosixTz posixTz) { this.displayName = displayName; this.originalString = originalString; this.posixTz = posixTz; }
//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; }
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); }
public bool ReadRule(ref PosixTz.DstRule rule) { return ReadFixedDateRule(ref rule) || ReadDayOfYearRule(ref rule) || ReadDayOfWeekRule(ref rule); }
//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; }
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); } }
//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; }