Skip to content

Commit a41010f

Browse files
bahusoidfredericDelaporte
authored andcommitted
Use DateTime.UtcNow for timestamps
1 parent 8a8c3f2 commit a41010f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/NHibernate/Cache/NoCacheProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public long NextTimestamp()
4141
// This is used by SessionFactoryImpl to hand to the generated SessionImpl;
4242
// was the only reason I could see that we cannot just use null as
4343
// Settings.CacheProvider
44-
return DateTime.Now.Ticks / (100 * TimeSpan.TicksPerMillisecond);
44+
return DateTime.UtcNow.Ticks / (100 * TimeSpan.TicksPerMillisecond);
4545
}
4646

4747
/// <summary>

src/NHibernate/Cache/Timestamper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static long Next()
3434
{
3535
// Ticks is accurate down to 100 nanoseconds - hibernate uses milliseconds
3636
// to help calculate next time so drop the nanoseconds portion.(1ms==1000000ns)
37-
long newTime = ((DateTime.Now.Ticks / 10000) - baseDateMs) << BinDigits;
37+
long newTime = ((DateTime.UtcNow.Ticks / 10000) - baseDateMs) << BinDigits;
3838
if (time < newTime)
3939
{
4040
time = newTime;
@@ -48,4 +48,4 @@ public static long Next()
4848
}
4949
}
5050
}
51-
}
51+
}

src/NHibernate/Id/CounterGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public object Generate(ISessionImplementor cache, object obj)
3333
// one year Count only serves to avoid collision for entities persisted in the same 100ns. Maybe it should
3434
// have been (DateTime.Now.Ticks && 0xffff) instead, with count serving to avoid collision for up to 37767
3535
// entities in the same 6.5535ms. But changing this would be a breaking change for existing values.
36-
return unchecked ((DateTime.Now.Ticks << 16) + Count);
36+
return unchecked ((DateTime.UtcNow.Ticks << 16) + Count);
3737
}
3838
}
3939
}

0 commit comments

Comments
 (0)