Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable RedundantUsingDirective

using Nuke.Common;
using Nuke.Common.Execution;
using Nuke.Common.IO;
Expand All @@ -16,19 +17,22 @@ class Build : NukeBuild
{
const string CiBranchNameEnvVariable = "OCTOVERSION_CurrentBranch";

[Parameter(
"Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI.")]
readonly bool AutoDetectBranch = IsLocalBuild;

readonly Configuration Configuration = Configuration.Release;

[Solution] readonly Solution Solution;

[Parameter("Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI.")]
readonly bool AutoDetectBranch = IsLocalBuild;

[Parameter("Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable " + CiBranchNameEnvVariable + ".", Name = CiBranchNameEnvVariable)]
string BranchName { get; set; }

[OctoVersion(BranchParameter = nameof(BranchName), AutoDetectBranchParameter = nameof(AutoDetectBranch))]
[OctoVersion(BranchParameter = nameof(BranchName), AutoDetectBranchParameter = nameof(AutoDetectBranch))]
public OctoVersionInfo OctoVersionInfo;

[Parameter(
"Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable " +
CiBranchNameEnvVariable + ".", Name = CiBranchNameEnvVariable)]
string BranchName { get; set; }

AbsolutePath SourceDirectory => RootDirectory / "source";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath LocalPackagesDirectory => RootDirectory / ".." / "LocalPackages";
Expand Down Expand Up @@ -105,4 +109,4 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => x.Default);
}
}
12 changes: 4 additions & 8 deletions build/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System.ComponentModel;
using Nuke.Common.Tooling;

[TypeConverter(typeof(TypeConverter<Configuration>))]
public class Configuration : Enumeration
{
public static Configuration Debug = new Configuration { Value = nameof(Debug) };
public static Configuration Release = new Configuration { Value = nameof(Release) };
public static Configuration Debug = new() { Value = nameof(Debug) };
public static Configuration Release = new() { Value = nameof(Release) };

public static implicit operator string(Configuration configuration)
{
return configuration.Value;
}
}
public static implicit operator string(Configuration configuration) => configuration.Value;
}
32 changes: 25 additions & 7 deletions source/Octopus.Time/FixedClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@ public class FixedClock : IClock
{
private DateTimeOffset now;

public FixedClock(DateTimeOffset now) => this.now = now;
public FixedClock(DateTimeOffset now)
{
this.now = now;
}

public void Set(DateTimeOffset value) => this.now = value;
public DateTimeOffset GetUtcTime()
{
return Clone().now.ToUniversalTime();
}

public void WindForward(TimeSpan time) => this.now = this.now.Add(time);
public DateTimeOffset GetLocalTime()
{
return Clone().now.ToLocalTime();
}

public DateTimeOffset GetUtcTime() => this.Clone().now.ToUniversalTime();
public void Set(DateTimeOffset value)
{
now = value;
}

public DateTimeOffset GetLocalTime() => this.Clone().now.ToLocalTime();
public void WindForward(TimeSpan time)
{
now = now.Add(time);
}

private FixedClock Clone() => (FixedClock) this.MemberwiseClone();
private FixedClock Clone()
{
return (FixedClock)MemberwiseClone();
}
}
}
}
12 changes: 9 additions & 3 deletions source/Octopus.Time/SystemClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ namespace Octopus.Time
{
public class SystemClock : IClock
{
public DateTimeOffset GetUtcTime() => DateTimeOffset.UtcNow;
public DateTimeOffset GetUtcTime()
{
return DateTimeOffset.UtcNow;
}

public DateTimeOffset GetLocalTime() => DateTimeOffset.Now;
public DateTimeOffset GetLocalTime()
{
return DateTimeOffset.Now;
}
}
}
}