Exemple #1
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 #2
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();
        }
Exemple #4
0
        private void CalculateTime()
        {
            var dateTimeOffset = _timeZoneService.ConvertTime(DateTime.Now);

            Date = dateTimeOffset.DateTime + _timeShiftProvider.TimeShift;
        }
 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);
        }