Exemple #1
0
 public ClockViewModel(ClockInfo info, TimeShiftProvider timeShiftProvider)
 {
     _info = info;
     _timeShiftProvider = timeShiftProvider;
     _timeZoneService   = TimeZoneService.FindSystemTimeZoneById(_info.TimeZoneId);
     _timer.Tick       += OnTimerTick;
     Delete             = new RelayCommand(() => ViewModelStorage.Main.DeleteClock(_info)); //Clean-up
     CalculateTime();
     _timeShiftProvider.PropertyChanged += (s, e) => CalculateTime();
 }
 public bool Equals(ITimeZoneEx other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Id.Equals(other.Id));
 }
Exemple #3
0
 public static TimeZoneSelectItem ToTimeZoneSelectItem(this ITimeZoneEx tz)
 {
     return(new TimeZoneSelectItem()
     {
         Id = tz.Id,
         DisplayName = string.Format("(UTC{0}{1}) {2}",
                                     tz.BaseUtcOffset.Hours > 0 ? "+" : string.Empty,
                                     tz.BaseUtcOffset,
                                     tz.DaylightName),
         UtcOffset = tz.BaseUtcOffset
     });
 }
Exemple #4
0
        /// <summary>
        /// Sets the specified timezone on the date without converting the time
        /// </summary>
        /// <param name="dateTimeOffset"></param>
        /// <param name="timeZone"></param>
        /// <returns></returns>
        public static DateTimeOffset SpecifyTimeZone(DateTimeOffset dateTimeOffset, ITimeZoneEx timeZone)
        {
            if (timeZone == null)
            {
                throw new ArgumentNullException("timeZone");
            }

            // Treat the date as UTC
            var dateAsUtc = DateTime.SpecifyKind(dateTimeOffset.DateTime, DateTimeKind.Utc);

            // This is to find the correct offset
            var asLocal = timeZone.ConvertTime(dateAsUtc);

            return(new DateTimeOffset(DateTime.SpecifyKind(dateAsUtc, DateTimeKind.Unspecified), asLocal.Offset));
        }
Exemple #5
0
        public ClockItem(string tzoneId)
        {
            _tz = TimeZoneService.FindSystemTimeZoneById(tzoneId);
            TimeZone = _tz.ToTimeZoneSelectItem();
            //TimerTask = new AsyncTimer(1000).WhenTick(i => OnOneSecondPassed()).StartAsync();

            var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
            timer.Tick += (sender, o) =>
            {
                var offset = _tz.ConvertTime(DateTime.Now);
                Time = offset.DateTime;
                OnPropertyChanged("Time");
            };

            timer.Start();
        }
        public ClockItem(string tzoneId)
        {
            _tz      = TimeZoneService.FindSystemTimeZoneById(tzoneId);
            TimeZone = _tz.ToTimeZoneSelectItem();
            //TimerTask = new AsyncTimer(1000).WhenTick(i => OnOneSecondPassed()).StartAsync();

            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(1)
            };

            timer.Tick += (sender, o) =>
            {
                var offset = _tz.ConvertTime(DateTime.Now);
                Time = offset.DateTime;
                OnPropertyChanged("Time");
            };

            timer.Start();
        }
 private DateTime CalculateTime(ITimeZoneEx timeService)
 {
     var dateTimeOffset = timeService.ConvertTime(DateTime.Now);
     return dateTimeOffset.DateTime + _timeShiftProvider.TimeShift;
 }
        /// <summary>
        /// Sets the specified timezone on the date without converting the time
        /// </summary>
        /// <param name="dateTimeOffset"></param>
        /// <param name="timeZone"></param>
        /// <returns></returns>
        public static DateTimeOffset SpecifyTimeZone(DateTimeOffset dateTimeOffset, ITimeZoneEx timeZone)
        {
            if (timeZone == null)
                throw new ArgumentNullException("timeZone");

            // Treat the date as UTC
            var dateAsUtc = DateTime.SpecifyKind(dateTimeOffset.DateTime, DateTimeKind.Utc);

            // This is to find the correct offset
            var asLocal = timeZone.ConvertTime(dateAsUtc);

            return new DateTimeOffset(DateTime.SpecifyKind(dateAsUtc, DateTimeKind.Unspecified), asLocal.Offset);
        }