public IActionResult GetTimezoneInfo() { List <TimezoneInfo> TimezoneInfoList = new List <TimezoneInfo>(); var userTimezoneInfo = new TimezoneInfo(); //collect timezone list foreach (var item in TimeZoneInfo.GetSystemTimeZones()) { TimezoneInfoList.Add(new TimezoneInfo { Id = item.Id , Name = item.Id + "-" + item.DisplayName }); //get user timezone for default value if (TimeZoneInfo.Local.Id == item.Id) { userTimezoneInfo = new TimezoneInfo() { Id = item.Id , Name = item.DisplayName }; } } return(Ok(new { userTimezone = userTimezoneInfo , TimezoneList = TimezoneInfoList })); }
/// <summary> /// Updates information about TimezoneDetails with the given GMT offset /// </summary> /// <param name="offset">int</param> public static void UpdateCityRecord(int offset) { TimezoneInfo result = GetTimezoneInformation(offset); detail.CityTime = GetFormattedTime(result.newTime); detail.CityAmPm = result.newTime.ToString("tt", CultureInfo.InvariantCulture); detail.RelativeToLocalCountry = result.relative; detail.Offset = offset; }
protected override void HandleInternal(ITwitchClient client, IChatCommand command) { if (this.zoneLoader.TryLoad(command.ArgumentsAsString, out Timezone timezone)) { TimezoneInfo timezoneInfo = this.timeLoader.GetTime(timezone); this.SendMessage(client, $"{command.ChatMessage.UserName}: {timezoneInfo.Timezone} {timezoneInfo.DateTime:G}"); } else { this.SendMessage(client, $"Sorry {command.ChatMessage.UserName}, can't find timezone info for '{command.ArgumentsAsString}'."); } }
public void GetTimeShouldMapTimezone() { Timezone timezone = new Timezone { Area = "area", Location = "location", Region = "region" }; TimezoneInfo timezoneInfo = this.timeLoader.GetTime(timezone); this.httpService.Verify(s => s.GetAsync <TimezoneInfo>($"http://worldtimeapi.org/api/timezone/{timezone}")); }
/// <summary> /// Generate CityRecord instance related to the given GMT offset /// </summary> /// <param name="offset">int</param> /// <returns>CityRecord</returns> public static CityRecord GenerateCityRecord(int offset) { TimezoneInfo result = GetTimezoneInformation(offset); CityRecord record = new CityRecord { CityTime = GetFormattedTime(result.newTime), CityAmPm = result.newTime.ToString("tt", CultureInfo.InvariantCulture), CityDate = String.Format("{0:ddd, d MMM}", result.newTime), RelativeToLocalCountry = result.relative, Offset = offset, Delete = false, }; return(record); }
public void GetTimezoneInfo_IoT() { TestHelpers.MockHttpResponder.AddMockResponse( DevicePortal.TimezoneInfoApi, this.PlatformType, this.FriendlyOperatingSystemVersion, HttpMethods.Get); Task <TimezoneInfo> getTask = TestHelpers.Portal.GetTimezoneInfoAsync(); getTask.Wait(); Assert.AreEqual(TaskStatus.RanToCompletion, getTask.Status); TimezoneInfo timezone = getTask.Result; // Check some known things about this response. Assert.AreEqual("(UTC-06:00) Central Time (US & Canada)", timezone.CurrentTimeZone.Description); Assert.AreEqual("(UTC-11:00) Coordinated Universal Time-11", timezone.Timezones[1].Description); }
public void HandleShouldLoadTimeForTimezone() { Settings.ApplicationSettings.Default.Channel = "channel"; this.chatCommand.Setup(c => c.CommandText).Returns("timezone"); this.chatCommand.Setup(c => c.ArgumentsAsList).Returns(new List <string> { "zone" }); this.chatCommand.Setup(c => c.ArgumentsAsString).Returns("zone"); this.chatMessage.Setup(m => m.UserName).Returns("user"); Timezone zone = new Timezone(); this.timezoneLoader.Setup(l => l.TryLoad("zone", out zone)).Returns(true); TimezoneInfo timezoneInfo = new TimezoneInfo { Timezone = "area/location/region", DateTime = new DateTime(2020, 01, 01) }; this.timeLoader.Setup(l => l.GetTime(zone)).Returns(timezoneInfo); this.commandHandler.Handle(this.twitchClient.Object, this.chatCommand.Object); this.twitchClient.Verify(c => c.SendMessage("channel", $@"user: area/location/region {timezoneInfo.DateTime:G}", false)); }
public void Init() { instance = new TimezoneInfo(); }