mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-20 09:35:40 -05:00
Add parameter for time zone
This commit is contained in:
@@ -21,9 +21,26 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("recent")]
|
||||
public async Task<ActionResult<WeatherReading>> GetRecent()
|
||||
public async Task<ActionResult<WeatherReading>> GetRecent([FromQuery] string tz)
|
||||
{
|
||||
return await _database.GetRecentReading();
|
||||
var recentReading = await _database.GetRecentReading();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tz))
|
||||
return recentReading;
|
||||
|
||||
try
|
||||
{
|
||||
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tz);
|
||||
|
||||
recentReading.Timestamp = recentReading.Timestamp.ToOffset(timeZoneInfo.GetUtcOffset(recentReading.Timestamp));
|
||||
recentReading.GpsTimestamp = recentReading.GpsTimestamp.ToOffset(timeZoneInfo.GetUtcOffset(recentReading.GpsTimestamp));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
|
||||
return recentReading;
|
||||
}
|
||||
|
||||
[HttpGet("history")]
|
||||
|
||||
Reference in New Issue
Block a user