public void ShouldThrowExceptionForUnknownWindowsTimezoneId() { Should.Throw <Exception>(() => { TimezoneHelper.WindowsToIana("abc"); }); }
public void AllWindowsTimezonesShouldBeConvertableToIana() { var allTimezones = TimeZoneInfo.GetSystemTimeZones(); Should.NotThrow(() => { var exceptions = new List <string>(); foreach (var timezone in allTimezones) { try { TimezoneHelper.WindowsToIana(timezone.Id); } catch (Exception ex) { exceptions.Add(ex.Message); } } if (exceptions.Any()) { throw new Exception(exceptions.JoinAsString(Environment.NewLine)); } }); }
public void Should_Throw_Exception_For_Unknown_Windows_Timezone_Id() { Should.Throw <Exception>(() => { TimezoneHelper.WindowsToIana("abc"); }); }
public async Task <IActionResult> SendPost([FromRoute] int id, [FromForm, Bind(nameof(PostsSendViewModel.ChannelId), nameof(PostsSendViewModel.Schedule), nameof(PostsSendViewModel.ScheduleDate))] PostsSendViewModel model) { if (model.Schedule && model.ScheduleDate.HasValue) { model.ScheduleDate = TimezoneHelper.ConvertTimeToUtcByIanaTimeZoneId( DateTime.SpecifyKind(model.ScheduleDate.Value, DateTimeKind.Unspecified), TimezoneHelper.WindowsToIana( await SettingManager.GetSettingValueAsync(TimingSettingNames.TimeZone))); await _scheduleService.Create(new ScheduleItemDto { PostId = id, ChannelId = model.ChannelId, ScheduleDate = model.ScheduleDate.Value }); return(RedirectToAction(nameof(Index))); } var post = await _postApplicationService.GetById(id); if (post == null) { return(NotFound()); } var channel = await _channelApplicationService.Get(new EntityDto <long>(model.ChannelId)); if (channel == null) { return(NotFound()); } await _bot.Client.SendTextMessageAsync(new ChatId(channel.Id), post.Body); return(RedirectToAction(nameof(Index))); }
public void All_Windows_Timezones_Should_Be_Convertable_To_Iana() { var allTimezones = TimeZoneInfo.GetSystemTimeZones(); foreach (var timezone in allTimezones) { Should.NotThrow(() => { TimezoneHelper.WindowsToIana(timezone.Id); }); } }
private async Task <string> GetUsersTimezoneScriptsAsync() { var timezoneId = await _settingManager.GetSettingValueAsync(TimingSettingNames.TimeZone); var timezone = TimeZoneInfo.FindSystemTimeZoneById(timezoneId); return(" {" + " windows: {" + " timeZoneId: '" + timezoneId + "'," + " baseUtcOffsetInMilliseconds: '" + timezone.BaseUtcOffset.TotalMilliseconds + "'," + " currentUtcOffsetInMilliseconds: '" + timezone.GetUtcOffset(Clock.Now).TotalMilliseconds + "'," + " isDaylightSavingTimeNow: '" + timezone.IsDaylightSavingTime(Clock.Now) + "'" + " }," + " iana: {" + " timeZoneId:'" + TimezoneHelper.WindowsToIana(timezoneId) + "'" + " }," + " }"); }
private async Task <UserTimingConfigDto> GetUserTimingConfig() { var timezoneId = await _settingManager.GetSettingValueAsync(TimingSettingNames.TimeZone); var timezone = TimeZoneInfo.FindSystemTimeZoneById(timezoneId); return(new UserTimingConfigDto { TimeZoneInfo = new UserTimeZoneConfigDto { Windows = new UserWindowsTimeZoneConfigDto { TimeZoneId = timezoneId, BaseUtcOffsetInMilliseconds = timezone.BaseUtcOffset.TotalMilliseconds, CurrentUtcOffsetInMilliseconds = timezone.GetUtcOffset(Clock.Now).TotalMilliseconds, IsDaylightSavingTimeNow = timezone.IsDaylightSavingTime(Clock.Now) }, Iana = new UserIanaTimeZoneConfigDto { TimeZoneId = TimezoneHelper.WindowsToIana(timezoneId) } } }); }
public void WindowsTimezoneIdToIanaTests(string windowsTimezoneId, string ianaTimezoneId) { TimezoneHelper.WindowsToIana(windowsTimezoneId).ShouldBe(ianaTimezoneId); }