fix(temporal): fixing time zone issues
This commit is contained in:
parent
85fa0fe97e
commit
8da6067bcc
2 changed files with 13 additions and 6 deletions
|
@ -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>();
|
||||
|
@ -42,12 +42,14 @@ public class DatePipelineCommandOption : IPipelineCommandOption
|
|||
// If we got a date, then use NodaTime's fake clock to set it so
|
||||
// everything will use that.
|
||||
var value = (DateTime?)context.ParseResult.GetValueForOption(this.Option);
|
||||
|
||||
|
||||
if (value.HasValue && value.Value != DateTime.MinValue)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue