fix(temporal): set the date time zone properly
This commit is contained in:
parent
3a009b05cf
commit
85fa0fe97e
5 changed files with 27 additions and 39 deletions
|
@ -39,8 +39,7 @@ public partial class IdentifyMarkdown : IOperation
|
|||
|
||||
private Entity MarkBinaryEntities(Entity entity, UPath path, IBinaryContent binary)
|
||||
{
|
||||
// If we aren't a Markdown file, then there is nothing
|
||||
// we can do about that.
|
||||
// If we aren't a Markdown file, then there is nothing we can do about that.
|
||||
if (!this.IsMarkdownTest(entity, path))
|
||||
{
|
||||
return entity;
|
||||
|
|
|
@ -18,14 +18,14 @@ namespace Nitride.Temporal.Cli;
|
|||
/// </summary>
|
||||
public class DatePipelineCommandOption : IPipelineCommandOption
|
||||
{
|
||||
private readonly Timekeeper clock;
|
||||
private readonly Timekeeper timekeeper;
|
||||
|
||||
private readonly ILogger logger;
|
||||
|
||||
public DatePipelineCommandOption(ILogger logger, Timekeeper clock)
|
||||
public DatePipelineCommandOption(ILogger logger, Timekeeper timekeeper)
|
||||
{
|
||||
this.logger = logger.ForContext<Instant>();
|
||||
this.clock = clock;
|
||||
this.timekeeper = timekeeper;
|
||||
this.Option = new Option<DateTime>("--date")
|
||||
{
|
||||
Description = "Sets the date to something other than now",
|
||||
|
@ -42,19 +42,19 @@ 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.clock.CreateInstant(value.Value);
|
||||
Instant instant = this.timekeeper.CreateInstant(value.Value);
|
||||
|
||||
this.clock.Clock = new FakeClock(instant);
|
||||
this.timekeeper.Clock = new FakeClock(instant);
|
||||
}
|
||||
|
||||
// Report the date we are processing.
|
||||
Instant now = this.clock.Clock.GetCurrentInstant();
|
||||
ZonedDateTime dateTime = now.InZone(this.clock.DateTimeZone);
|
||||
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);
|
||||
|
||||
this.logger.Information("Setting date/time to {When:l}", formatted);
|
||||
|
|
|
@ -53,13 +53,16 @@ public static class NitrideTemporalBuilderExtensions
|
|||
}
|
||||
});
|
||||
|
||||
builder.ConfigureSite(
|
||||
(_, scope) =>
|
||||
{
|
||||
Timekeeper timekeeper = scope.Resolve<Timekeeper>();
|
||||
if (config.DateTimeZone != null)
|
||||
{
|
||||
builder.ConfigureSite(
|
||||
(_, scope) =>
|
||||
{
|
||||
Timekeeper timekeeper = scope.Resolve<Timekeeper>();
|
||||
|
||||
timekeeper.DateTimeZone = timekeeper.DateTimeZone;
|
||||
});
|
||||
timekeeper.DateTimeZone = config.DateTimeZone;
|
||||
});
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
namespace Nitride.Temporal;
|
||||
|
||||
/// <summary>
|
||||
|
@ -19,7 +21,7 @@ public partial class NitrideTemporalConfiguration
|
|||
/// Gets or sets the time zone to use for date time operations. Examples would be
|
||||
/// "America/Chicago".
|
||||
/// </summary>
|
||||
public string? DateTimeZone { get; set; }
|
||||
public DateTimeZone? DateTimeZone { get; set; }
|
||||
|
||||
public string? Expiration { get; set; }
|
||||
|
||||
|
@ -28,6 +30,12 @@ public partial class NitrideTemporalConfiguration
|
|||
return this.WithAddDateOptionToCommandLine(true);
|
||||
}
|
||||
|
||||
public NitrideTemporalConfiguration WithDateTimeZone(string zoneName)
|
||||
{
|
||||
this.DateTimeZone = DateTimeZoneProviders.Tzdb[zoneName];
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the "--expire" option into the pipeline commands where with the value set
|
||||
/// to
|
||||
|
|
|
@ -113,26 +113,4 @@ public class Timekeeper
|
|||
{
|
||||
return instant.InZone(this.DateTimeZone).ToDateTimeOffset().DateTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the clock used for time calculations.
|
||||
/// </summary>
|
||||
/// <param name="clock">The new clock to use.</param>
|
||||
/// <returns>The instance for chaining methods.</returns>
|
||||
public Timekeeper WithClock(IClock clock)
|
||||
{
|
||||
this.Clock = clock;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the date time zone and returns itself for chaining.
|
||||
/// </summary>
|
||||
/// <param name="timeZoneName">The name of the time zone.</param>
|
||||
/// <returns>The instance for chaining methods.</returns>
|
||||
public Timekeeper WithDateTimeZone(string timeZoneName)
|
||||
{
|
||||
this.DateTimeZone = DateTimeZoneProviders.Tzdb[timeZoneName];
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue