How can we help you today? How can we help you today?
lbarbisan
Until a configuration parameter can be set here is the worst hack I've ever wrote : DateTime simulationTime = new DateTime(2008, 06, 06); Stopwatch elapsedTime = new Stopwatch(); elapsedTime.Start(); DateTime currentTime = DateTime.Now.ToUniversalTime(); SystemDateTime.SetSystemDateTime(simulationTime.ToUniversalTime()); IServiceProvider serviceProvider = new ApplicationManager(null); elapsedTime.Stop(); TimeSpan timespan = new TimeSpan(elapsedTime.ElapsedTicks); currentTime.Add(timespan); SystemDateTime.SetSystemDateTime(currentTime.ToUniversalTime()); And the class to set time (thanks to http://pinvoke.net/default.aspx/kernel32.SetLocalTime ) : using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace Posttrade.Rate.Accounting.RulesExplorer.Sources.Business { public static class SystemDateTime { public struct SystemTime { public ushort Year; public ushort Month; public ushort DayOfWeek; public ushort Day; public ushort Hour; public ushort Minute; public ushort Second; public ushort Millisecond; }; [DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)] public extern static void Win32GetSystemTime(ref SystemTime sysTime); [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)] public extern static bool Win32SetSystemTime(ref SystemTime sysTime); public static void SetSystemDateTime(DateTime datetime) { // Set system date and time SystemTime updatedTime = new SystemTime(); updatedTime.Year = (ushort)datetime.Year; updatedTime.Month = (ushort)datetime.Month; updatedTime.Day = (ushort)datetime.Day; // UTC time; it will be modified according to the regional settings of the target computer so the actual hour might differ updatedTime.Hour = (ushort)datetime.Hour; updatedTime.Minute = (ushort)datetime.Minute; updatedTime.Second = (ushort)datetime.Second; // Call the unmanaged function that sets the new date and time instantly Win32SetSystemTime(ref updatedTime); } } } / comments
Until a configuration parameter can be set here is the worst hack I've ever wrote :DateTime simulationTime = new DateTime(2008, 06, 06); Stopwatch elapsedTime = new Stopwatch(); el...
0 votes