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