internal static unsafe bool IsValidTimeWithLeapSeconds(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) { DateTime dt = new DateTime(year, month, day); FullSystemTime time = new FullSystemTime(year, month, dt.DayOfWeek, day, hour, minute, second); if (kind != DateTimeKind.Utc) { Interop.Kernel32.SYSTEMTIME st; if (Interop.Kernel32.TzSpecificLocalTimeToSystemTime(IntPtr.Zero, &time.systemTime, &st) != Interop.BOOL.FALSE) { return(true); } } if (kind != DateTimeKind.Local) { long ft; if (Interop.Kernel32.SystemTimeToFileTime(&time.systemTime, &ft) != Interop.BOOL.FALSE) { return(true); } } return(false); }
internal static long ToFileTimeLeapSecondsAware(long ticks) { FullSystemTime time = new FullSystemTime(ticks); if (Interop.Kernel32.SystemTimeToFileTime(in time.systemTime, out long fileTime)) { return(fileTime + ticks % TicksPerMillisecond); } throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_FileTimeInvalid); }
internal static unsafe bool IsValidTimeWithLeapSeconds(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) { DateTime dt = new DateTime(year, month, day); FullSystemTime time = new FullSystemTime(year, month, dt.DayOfWeek, day, hour, minute, second); return(kind switch { DateTimeKind.Local => ValidateSystemTime(&time.systemTime, localTime: true), DateTimeKind.Utc => ValidateSystemTime(&time.systemTime, localTime: false), _ => ValidateSystemTime(&time.systemTime, localTime: true) || ValidateSystemTime(&time.systemTime, localTime: false), });
private static unsafe long ToFileTimeLeapSecondsAware(long ticks) { FullSystemTime time = new FullSystemTime(ticks); long fileTime; if (SystemTimeToFileTime(&time.systemTime, &fileTime)) { return(fileTime + ticks % TicksPerMillisecond); } throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_FileTimeInvalid); }
private static unsafe long ToFileTimeLeapSecondsAware(long ticks) { FullSystemTime time = new FullSystemTime(ticks); long fileTime; if (Interop.Kernel32.SystemTimeToFileTime(&time.systemTime, &fileTime) == Interop.BOOL.FALSE) { throw new ArgumentOutOfRangeException(null, SR.ArgumentOutOfRange_FileTimeInvalid); } return(fileTime + ticks % TicksPerMillisecond); }
internal static unsafe bool IsValidTimeWithLeapSeconds(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) { DateTime dt = new DateTime(year, month, day); FullSystemTime time = new FullSystemTime(year, month, dt.DayOfWeek, day, hour, minute, second); switch (kind) { case DateTimeKind.Local: return ValidateSystemTime(&time.systemTime, localTime: true); case DateTimeKind.Utc: return ValidateSystemTime(&time.systemTime, localTime: false); default: return ValidateSystemTime(&time.systemTime, localTime: true) || ValidateSystemTime(&time.systemTime, localTime: false); } }