fix(temporal): fixing time zone issues

This commit is contained in:
Dylan R. E. Moonfire 2022-06-07 09:40:31 -05:00
parent 85fa0fe97e
commit 8da6067bcc
2 changed files with 13 additions and 6 deletions

View file

@ -18,10 +18,10 @@ namespace Nitride.Temporal.Cli;
/// </summary>
public class DatePipelineCommandOption : IPipelineCommandOption
{
private readonly Timekeeper timekeeper;
private readonly ILogger logger;
private readonly Timekeeper timekeeper;
public DatePipelineCommandOption(ILogger logger, Timekeeper timekeeper)
{
this.logger = logger.ForContext<Instant>();
@ -47,7 +47,9 @@ public class DatePipelineCommandOption : IPipelineCommandOption
{
// We have a date, so we need to create a fake clock that has this
// date for the entire run.
Instant instant = this.timekeeper.CreateInstant(value.Value);
var local = LocalDateTime.FromDateTime(value.Value);
ZonedDateTime zoned = local.InZoneStrictly(this.timekeeper.DateTimeZone);
var instant = zoned.ToInstant();
this.timekeeper.Clock = new FakeClock(instant);
}
@ -55,8 +57,11 @@ public class DatePipelineCommandOption : IPipelineCommandOption
// Report the date we are processing.
Instant now = this.timekeeper.Clock.GetCurrentInstant();
ZonedDateTime dateTime = now.InZone(this.timekeeper.DateTimeZone);
string formatted = dateTime.ToString("yyyy-MM-dd HH:mm:ss x", CultureInfo.CurrentCulture);
string formatted = dateTime.ToString("G", CultureInfo.InvariantCulture);
this.logger.Information("Setting date/time to {When:l}", formatted);
this.logger.Information(
"Setting date/time to {When:l} in time zone {Zone:l}",
formatted,
this.timekeeper.DateTimeZone);
}
}

View file

@ -58,9 +58,11 @@ public static class NitrideTemporalBuilderExtensions
builder.ConfigureSite(
(_, scope) =>
{
ILogger logger = scope.Resolve<ILogger>();
Timekeeper timekeeper = scope.Resolve<Timekeeper>();
timekeeper.DateTimeZone = config.DateTimeZone;
logger.Information("Setting time zone to {Zone}", timekeeper.DateTimeZone);
});
}