using System; using MfGames.Nitride.Generators; using NodaTime; namespace MfGames.Nitride.Temporal.Setup; /// /// Configures the temporal settings for use with `UseTemporal`. /// [WithProperties] public partial class NitrideTemporalConfiguration { /// /// Adds the "--date=XXXX-XX-XX" option into the pipeline commands. /// public bool AddDateOptionToCommandLine { get; set; } public bool AddExpireOptionToCommandLine { get; set; } /// /// Gets or sets the time zone to use for date time operations. Examples would be /// "America/Chicago". /// public DateTimeZone? DateTimeZone { get; set; } public string? Expiration { get; set; } public NitrideTemporalConfiguration WithDateOptionCommandLineOption() { return this.WithAddDateOptionToCommandLine(true); } public NitrideTemporalConfiguration WithDateTimeZone(string zoneName) { this.DateTimeZone = DateTimeZoneProviders.Tzdb[zoneName]; return this; } /// /// Adds the "--expire" option into the pipeline commands where with the value set /// to /// the current timestamp (or the one provided by --date) plus the given timespan /// such /// as "500000:00:00.0". /// public NitrideTemporalConfiguration WithExpiresCommandLineOption( TimeSpan? timeSpan) { return this.WithExpiresCommandLineOption(timeSpan?.ToString()); } /// /// Adds the "--expire=XXXX" option into the pipeline commands where /// "XXX" is a format like "5y" or "500000:00:00.0". This is parsed by /// TimeSpanParser which gives an easy format. /// public NitrideTemporalConfiguration WithExpiresCommandLineOption( string? defaultValue) { this.AddExpireOptionToCommandLine = defaultValue != null; this.Expiration = defaultValue; return this; } }