Fix timezone offset calculation to respect DST for target dates (#59)
* Initial plan * Fix timezone offset calculation and add tests Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
parent
252e588375
commit
71717cccc1
2 changed files with 46 additions and 2 deletions
|
|
@ -38,7 +38,7 @@ namespace ShiftScheduler.Services
|
|||
var startTime = TimeOnly.Parse(times[0]);
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ namespace ShiftScheduler.Services
|
|||
DateTimeOffset? afternoonStart = null;
|
||||
DateTimeOffset? afternoonEnd = null;
|
||||
|
||||
TimeSpan offset = localTimeZone.GetUtcOffset(DateTime.UtcNow);
|
||||
TimeSpan offset = localTimeZone.GetUtcOffset(date);
|
||||
|
||||
if (!string.IsNullOrEmpty(shift.MorningTime))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,6 +40,50 @@ public class ConfigurationServiceTests
|
|||
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)
|
||||
{
|
||||
return DateTimeOffset.Parse(dateTimeString);
|
||||
|
|
|
|||
Loading…
Reference in a new issue