Fix timezone offset calculation and add tests

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-04 13:56:03 +00:00
parent 03ba304aeb
commit 3409bd9532
2 changed files with 46 additions and 2 deletions

View file

@ -38,7 +38,7 @@ namespace ShiftScheduler.Services
var startTime = TimeOnly.Parse(times[0]); var startTime = TimeOnly.Parse(times[0]);
var endTime = TimeOnly.Parse(times[1]); var endTime = TimeOnly.Parse(times[1]);
TimeSpan offset = localTimeZone.GetUtcOffset(DateTime.UtcNow); TimeSpan offset = localTimeZone.GetUtcOffset(date.ToDateTime(startTime));
return (new DateTimeOffset(date, startTime, offset), new DateTimeOffset(date, endTime, offset)); return (new DateTimeOffset(date, startTime, offset), new DateTimeOffset(date, endTime, offset));
} }
@ -225,7 +225,7 @@ namespace ShiftScheduler.Services
DateTimeOffset? afternoonStart = null; DateTimeOffset? afternoonStart = null;
DateTimeOffset? afternoonEnd = null; DateTimeOffset? afternoonEnd = null;
TimeSpan offset = localTimeZone.GetUtcOffset(DateTime.UtcNow); TimeSpan offset = localTimeZone.GetUtcOffset(date);
if (!string.IsNullOrEmpty(shift.MorningTime)) if (!string.IsNullOrEmpty(shift.MorningTime))
{ {

View file

@ -40,6 +40,50 @@ public class ConfigurationServiceTests
shiftTimes.AfternoonEnd.ShouldBeNull(); shiftTimes.AfternoonEnd.ShouldBeNull();
} }
[Fact]
public void ParseShiftTimes_WithWinterDate_ShouldUseCorrectOffset()
{
var applicationConfig = new ApplicationConfiguration();
var configurationService = new ConfigurationService(applicationConfig);
var shift = new Shift
{
MorningTime = "06:00-12:30",
AfternoonTime = "13:00-17:30"
};
var shiftTimes = configurationService.ParseShiftTimes(DateTime.Parse("2025-11-15T13:00:00"), shift);
shiftTimes.MorningStart.ShouldBe(T("2025-11-15T06:00:00+01:00"));
shiftTimes.MorningEnd.ShouldBe(T("2025-11-15T12:30:00+01:00"));
shiftTimes.AfternoonStart.ShouldBe(T("2025-11-15T13:00:00+01:00"));
shiftTimes.AfternoonEnd.ShouldBe(T("2025-11-15T17:30:00+01:00"));
}
[Fact]
public void GetZurichTime_WithSummerDate_ShouldUseCorrectOffset()
{
var applicationConfig = new ApplicationConfiguration();
var configurationService = new ConfigurationService(applicationConfig);
var date = DateOnly.Parse("2025-07-13");
var timeRange = "06:00-12:30";
var (startTime, endTime) = configurationService.GetZurichTime(date, timeRange);
startTime.ShouldBe(T("2025-07-13T06:00:00+02:00"));
endTime.ShouldBe(T("2025-07-13T12:30:00+02:00"));
}
[Fact]
public void GetZurichTime_WithWinterDate_ShouldUseCorrectOffset()
{
var applicationConfig = new ApplicationConfiguration();
var configurationService = new ConfigurationService(applicationConfig);
var date = DateOnly.Parse("2025-11-15");
var timeRange = "06:00-12:30";
var (startTime, endTime) = configurationService.GetZurichTime(date, timeRange);
startTime.ShouldBe(T("2025-11-15T06:00:00+01:00"));
endTime.ShouldBe(T("2025-11-15T12:30:00+01:00"));
}
private DateTimeOffset T(string dateTimeString) private DateTimeOffset T(string dateTimeString)
{ {
return DateTimeOffset.Parse(dateTimeString); return DateTimeOffset.Parse(dateTimeString);