From b27ccc1f491ff5ea84f53143f2b7babc64ee58f6 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Sat, 21 Dec 2024 22:09:32 -0500 Subject: [PATCH] Add timezone to national days API --- Calendar/Calendar.sln.DotSettings | 4 ++++ Calendar/Service/Calendar.http | 5 +++++ Calendar/Service/Controllers/NationalDaysController.cs | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Calendar/Calendar.sln.DotSettings b/Calendar/Calendar.sln.DotSettings index 52c4ba6..194b5d3 100644 --- a/Calendar/Calendar.sln.DotSettings +++ b/Calendar/Calendar.sln.DotSettings @@ -1,4 +1,8 @@  NEVER NEVER + True + True + True + True True \ No newline at end of file diff --git a/Calendar/Service/Calendar.http b/Calendar/Service/Calendar.http index 1bfc3ec..d04312f 100644 --- a/Calendar/Service/Calendar.http +++ b/Calendar/Service/Calendar.http @@ -34,3 +34,8 @@ GET {{Calendar_HostAddress}}/national-days/today Accept: application/json ### + +GET {{Calendar_HostAddress}}/national-days/today?timezone=America/New_York +Accept: application/json + +### diff --git a/Calendar/Service/Controllers/NationalDaysController.cs b/Calendar/Service/Controllers/NationalDaysController.cs index 710fc76..52a51e4 100644 --- a/Calendar/Service/Controllers/NationalDaysController.cs +++ b/Calendar/Service/Controllers/NationalDaysController.cs @@ -9,10 +9,14 @@ namespace ChrisKaczor.HomeMonitor.Calendar.Service.Controllers; public class NationalDaysController(IConfiguration configuration, RestClient restClient) : ControllerBase { [HttpGet("today")] - public async Task> GetToday() + public async Task> GetToday([FromQuery] string timezone = "Etc/UTC") { + var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timezone); + var timeZoneOffset = timeZoneInfo.GetUtcOffset(DateTimeOffset.Now).TotalHours; + var restRequest = new RestRequest(configuration["Calendar:NationalDays:Url"]); restRequest.AddHeader("X-Api-Key", configuration["Calendar:NationalDays:Key"] ?? string.Empty); + restRequest.AddQueryParameter("timezone_offset", timeZoneOffset); var response = await restClient.GetAsync(restRequest);