2025-05-01 01:48:08 -07:00

46 lines
1.5 KiB
C#

using System;
namespace UnityEngine.Localization.SmartFormat.Net.Utilities
{
/// <summary>
/// Used for getting DateTime.Now or DateOffset.Now. Time is changeable for unit testing
/// </summary>
internal static class SystemTime
{
/// <summary>
/// Normally this is a pass-through to DateTime.Now, but it can be overridden with SetDateTime( .. ) for unit testing and debugging.
/// </summary>
public static Func<DateTime> Now = () => DateTime.Now;
/// <summary>
/// Set time to return when SystemTime.Now() is called.
/// </summary>
public static void SetDateTime(DateTime dateTimeNow)
{
Now = () => dateTimeNow;
}
/// <summary>
/// Normally this is a pass-through to DateTimeOffset.Now, but it can be overridden with SetDateTime( .. ) for unit testing and debugging.
/// </summary>
public static Func<DateTimeOffset> OffsetNow = () => DateTimeOffset.Now;
/// <summary>
/// Set time to return when SystemTime.OffsetNow() is called.
/// </summary>
public static void SetDateTimeOffset(DateTimeOffset dateTimeOffset)
{
OffsetNow = () => dateTimeOffset;
}
/// <summary>
/// Resets SystemTime.Now() to return DateTime.Now.
/// </summary>
public static void ResetDateTime()
{
Now = () => DateTime.Now;
OffsetNow = () => DateTimeOffset.Now;
}
}
}