Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug: デバッグ時刻を環境から設定できるように #36

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
9 changes: 7 additions & 2 deletions Common/EnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ public class EnvironmentManager
public static string GoogleCredentialFilePath => Get("GoogleCredentialFilePath");
public static string GoogleMasterSheetId => Get("GoogleMasterSheetId");
public static string SqliteConnectionString => Get("SqliteConnectionString");
public static string? DebugDateTime => GetOrDefault("DebugDateTime");

private static string Get(string name)
{
return Configuration[name] ??
throw new Exception($"Environment variable {name} is not set.");
return Configuration[name] ?? throw new Exception($"Environment variable {name} is not set.");
}

private static string? GetOrDefault(string name)
{
return Configuration[name] ?? default;
}
}
22 changes: 13 additions & 9 deletions Common/TimeManager.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
namespace Approvers.King.Common;

public static class TimeManager
public class TimeManager : Singleton<TimeManager>
{
public static TimeSpan DailyResetTime => TimeSpan.FromMilliseconds(MasterManager.SettingMaster.DailyResetTime);
public static int MonthlyResetDay => MasterManager.SettingMaster.MonthlyResetDay;
public static DateTime Birthday => new(1, MasterManager.SettingMaster.BirthdayMonth, MasterManager.SettingMaster.BirthdayDay);

public static DateTime Birthday => new DateTime(1, MasterManager.SettingMaster.BirthdayMonth,
MasterManager.SettingMaster.BirthdayDay);
private DateTime? _debugBaseTime;
private TimeSpan _debugTimeOffset;

private static readonly DateTime? DebugBaseTime = null;
private static TimeSpan _debugTimeOffset;

public static void Initialize()
public void Initialize()
{
_debugTimeOffset = DebugBaseTime.HasValue ? DebugBaseTime.Value - DateTime.Now.ToLocalTime() : TimeSpan.Zero;
var debugDateTime = EnvironmentManager.DebugDateTime;
if (string.IsNullOrEmpty(debugDateTime) == false)
{
_debugBaseTime = DateTime.Parse(debugDateTime);
}

_debugTimeOffset = _debugBaseTime.HasValue ? _debugBaseTime.Value - DateTime.Now.ToLocalTime() : TimeSpan.Zero;
}

/// <summary>
Expand All @@ -22,7 +26,7 @@ public static void Initialize()
/// </summary>
public static DateTime GetNow()
{
return DateTime.Now.ToLocalTime() + _debugTimeOffset;
return DateTime.Now.ToLocalTime() + Instance._debugTimeOffset;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private static void Main(string[] args)

private static async Task BuildAsync(string[] args)
{
TimeManager.Initialize();
TimeManager.Instance.Initialize();
await MasterManager.FetchAsync();

await GachaManager.Instance.LoadAsync();
Expand Down