123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace TEAMModelOS.SDK.Extension.SnowFlake
- {
- public static class TimeExtensions
- {
- public static Func<long> currentTimeFunc = InternalCurrentTimeMillis;
- public static long CurrentTimeMillis()
- {
- return currentTimeFunc();
- }
- public static IDisposable StubCurrentTime(Func<long> func)
- {
- currentTimeFunc = func;
- return new DisposableAction(() =>
- {
- currentTimeFunc = InternalCurrentTimeMillis;
- });
- }
- public static IDisposable StubCurrentTime(long millis)
- {
- currentTimeFunc = () => millis;
- return new DisposableAction(() =>
- {
- currentTimeFunc = InternalCurrentTimeMillis;
- });
- }
- private static readonly DateTime Jan1st1970 = new DateTime
- (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- private static long InternalCurrentTimeMillis()
- {
- return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
- }
- }
- }
|