set time zone

This commit is contained in:
Claudio Schaad 2025-09-03 22:13:50 +02:00
parent 85a4ecb2aa
commit 86667b661a

View file

@ -29,6 +29,8 @@ namespace ShiftScheduler.Services
private readonly string _shiftsFilePath;
private readonly string _transportFilePath;
TimeZoneInfo localTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Zurich");
public ConfigurationService(ApplicationConfiguration initialConfiguration)
{
_configDirectory = Path.Combine(Directory.GetCurrentDirectory(), "config");
@ -212,13 +214,15 @@ namespace ShiftScheduler.Services
DateTimeOffset? afternoonStart = null;
DateTimeOffset? afternoonEnd = null;
TimeSpan offset = localTimeZone.GetUtcOffset(DateTime.UtcNow);
if (!string.IsNullOrEmpty(shift.MorningTime))
{
var times = shift.MorningTime.Split('-');
if (times.Length == 2)
{
var start = $"{date:yyyy-MM-dd}T{times[0]}:00";
var end = $"{date:yyyy-MM-dd}T{times[1]}:00";
var start = $"{date:yyyy-MM-dd}T{times[0]}:00+{offset.Hours}:{offset.Minutes}";
var end = $"{date:yyyy-MM-dd}T{times[1]}:00+{offset.Hours}:{offset.Minutes}";
morningStart = DateTimeOffset.Parse(start);
morningEnd = DateTimeOffset.Parse(end);
}
@ -229,8 +233,8 @@ namespace ShiftScheduler.Services
var times = shift.AfternoonTime.Split('-');
if (times.Length == 2)
{
var start = $"{date:yyyy-MM-dd}T{times[0]}:00";
var end = $"{date:yyyy-MM-dd}T{times[1]}:00";
var start = $"{date:yyyy-MM-dd}T{times[0]}:00+{offset.Hours}:{offset.Minutes}";
var end = $"{date:yyyy-MM-dd}T{times[1]}:00+{offset.Hours}:{offset.Minutes}";
afternoonStart = DateTimeOffset.Parse(start);
afternoonEnd = DateTimeOffset.Parse(end);
}