Ver Fonte

Move WinRT date code to (full) file in which it is used.

Ed Maurer há 9 anos atrás
pai
commit
e28a2ad595
2 ficheiros alterados com 5 adições e 82 exclusões
  1. 0 76
      lib/Common/Common/DateUtilities.cpp
  2. 5 6
      lib/Common/Common/DateUtilities.h

+ 0 - 76
lib/Common/Common/DateUtilities.cpp

@@ -68,29 +68,6 @@ namespace Js
         _u("PDT")
     };
 
-    //
-    // Convert a WinRT DateTime date (in 100ns precision ticks) to an ES5 date
-    //
-    // We convert ticks to milliseconds and shift by JS epoch to get the double date
-    // We go in that order to skip doing underflow checks
-    //
-    HRESULT DateUtilities::WinRTDateToES5Date(INT64 ticks, __out double* pRet)
-    {
-        Assert(pRet != NULL);
-
-        if (pRet == NULL)
-        {
-            return E_INVALIDARG;
-        }
-
-        // Divide as INT64 to ensure truncation of all decimal digits,
-        // since any remaining after conversion will be truncated as a Date value.
-        INT64 milliseconds = ticks / ticksPerMillisecond;
-
-        (*pRet) = (double)(milliseconds - jsEpochMilliseconds);
-
-        return S_OK;
-    }
 
     //
     // Convert an ES5 date based on double to a WinRT DateTime
@@ -126,59 +103,6 @@ namespace Js
          return INTSAFE_E_ARITHMETIC_OVERFLOW;
     }
 
-    //
-    // Version 6 Change:
-    // Previously we would round the TimeSpan to ms precision in order to avoid having the double contain decimal digits.
-    // Now we allow for the timespan to be represented with integers and digits (no truncation).
-    //
-    HRESULT DateUtilities::WinRTTimeSpanToNumberV6(INT64 ticks, __out double* pRet)
-    {
-        Assert(pRet != NULL);
-
-        if (pRet == NULL)
-        {
-            return E_INVALIDARG;
-        }
-
-        // We want to preserve precision as best we could, and for low enough timespan values
-        // Hence perform a division of doubles, to convert from ticks to milliseconds.
-        double result = (double)ticks / ticksPerMillisecondDouble;
-        *pRet = result;
-
-        return S_OK;
-    }
-
-    //
-    // Version 6 Change:
-    // Same as for WinRTTimeSpanToNumberV6, remove truncation when converting between Number and WinRT TimeSpan.
-    //
-    HRESULT DateUtilities::NumberToWinRTTimeSpanV6(double span, __out INT64* pRet)
-    {
-        Assert(pRet != NULL);
-
-        if (pRet == NULL)
-        {
-            return E_INVALIDARG;
-        }
-
-        //Otherwise the double multiplication might overflow
-        if (span > INT64_MAX / ticksPerMillisecond)
-        {
-            return INTSAFE_E_ARITHMETIC_OVERFLOW;
-        }
-
-        //Multiply before converting to Int64, in order to get the 100-nanosecond precision which will get truncated
-        INT64 spanAsInt64 = NumberUtilities::TryToInt64(span * ticksPerMillisecondDouble);
-
-        if (!NumberUtilities::IsValidTryToInt64(spanAsInt64))
-        {
-            return INTSAFE_E_ARITHMETIC_OVERFLOW;
-        }
-
-        (*pRet) = spanAsInt64;
-        return S_OK;
-    }
-
     ///------------------------------------------------------------------------------
     /// Get a time value from SYSTEMTIME structure.
     ///

+ 5 - 6
lib/Common/Common/DateUtilities.h

@@ -17,20 +17,19 @@ namespace Js
     // Utility methods to manipulate various date formats
     class DateUtilities
     {
-        static const INT64 ticksPerMillisecond;
-        static const double ticksPerMillisecondDouble;
         static const INT64 ticksPerSecond;
         static const INT64 ticksPerMinute;
         static const INT64 ticksPerHour;
         static const INT64 ticksPerDay;
         static const INT64 jsEpochTicks;
-        static const INT64 jsEpochMilliseconds;
 
     public:
-        static HRESULT WinRTDateToES5Date(INT64 winrtDate, __out double* pResult);
+
+        static const INT64 ticksPerMillisecond;
+        static const double ticksPerMillisecondDouble;
+        static const INT64 jsEpochMilliseconds;
+
         static HRESULT ES5DateToWinRTDate(double es5Date, __out INT64* pResult);
-        static HRESULT WinRTTimeSpanToNumberV6(INT64 span, __out double* pResult);
-        static HRESULT NumberToWinRTTimeSpanV6(double span, __out INT64* pResult);
 
         static double TimeFromSt(SYSTEMTIME *pst);
         static double DayTimeFromSt(SYSTEMTIME *pst);