Skip to content

Commit

Permalink
Debug: デバッグ時刻を環境から設定できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
2RiniaR committed Nov 27, 2024
1 parent d2440a1 commit b636e53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
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

0 comments on commit b636e53

Please sign in to comment.