DateExtensions.cs 608 B

123456789101112131415161718192021222324
  1. namespace Jint.Native.Date;
  2. internal static class DateExtensions
  3. {
  4. public static DateTime ToDateTime(this double t)
  5. {
  6. return DateConstructor.Epoch.AddMilliseconds(t);
  7. }
  8. internal static DatePresentation TimeClip(this double time)
  9. {
  10. if (double.IsInfinity(time) || double.IsNaN(time))
  11. {
  12. return new DatePresentation(0, DateFlags.NaN);
  13. }
  14. if (System.Math.Abs(time) > 8640000000000000)
  15. {
  16. return new DatePresentation(0, DateFlags.NaN);
  17. }
  18. return new DatePresentation((long) time, DateFlags.None);
  19. }
  20. }