oleaut32: Fix handling of negative fractional variant dates.
The integer part is the number of days to be added to the epoch (1899-12-30), and the fractional part (disregarding sign) represents the fraction of that day that has elapsed.
This commit is contained in:
parent
25118e5383
commit
c8a4983ed9
|
@ -1609,14 +1609,12 @@ static void test_VarUdateFromDate(void)
|
|||
DT2UD(29221.7508765432,0,S_OK,1,1,1980,18,1,16,0,2,1); /* 6:18:02 PM */
|
||||
|
||||
/* Test handling of times on dates prior to the epoch */
|
||||
todo_wine {
|
||||
DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
|
||||
DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
|
||||
}
|
||||
DT2UD(-5.25,0,S_OK,25,12,1899,6,0,0,0,1,359);
|
||||
DT2UD(-5.9999884259259,0,S_OK,25,12,1899,23,59,59,0,1,359);
|
||||
/* This just demostrates the non-linear nature of values prior to the epoch */
|
||||
DT2UD(-4.0,0,S_OK,26,12,1899,0,0,0,0,2,360);
|
||||
/* Numerical oddity: for 0.0 < x < 1.0, x and -x represent the same datetime */
|
||||
todo_wine DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
|
||||
DT2UD(-0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
|
||||
DT2UD(0.25,0,S_OK,30,12,1899,6,0,0,0,6,364);
|
||||
}
|
||||
|
||||
|
@ -1683,10 +1681,8 @@ static void test_VarDateFromUdate(void)
|
|||
UD2T(1,13,1980,0,0,0,0,2,1,0,S_OK,29587.0); /* Rolls fwd to 1/1/1981 */
|
||||
|
||||
/* Test handling of times on dates prior to the epoch */
|
||||
todo_wine {
|
||||
UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
|
||||
UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
|
||||
}
|
||||
UD2T(25,12,1899,6,0,0,0,1,359,0,S_OK,-5.25);
|
||||
UD2T(25,12,1899,23,59,59,0,1,359,0,S_OK,-5.9999884259259);
|
||||
/* This just demostrates the non-linear nature of values prior to the epoch */
|
||||
UD2T(26,12,1899,0,0,0,0,2,360,0,S_OK,-4.0);
|
||||
/* for DATE values 0.0 < x < 1.0, x and -x represent the same datetime */
|
||||
|
|
|
@ -1359,7 +1359,7 @@ INT WINAPI VariantTimeToSystemTime(double dateIn, LPSYSTEMTIME lpSt)
|
|||
HRESULT WINAPI VarDateFromUdateEx(UDATE *pUdateIn, LCID lcid, ULONG dwFlags, DATE *pDateOut)
|
||||
{
|
||||
UDATE ud;
|
||||
double dateVal;
|
||||
double dateVal, dateSign;
|
||||
|
||||
TRACE("(%p->%d/%d/%d %d:%d:%d:%d %d %d,0x%08x,0x%08x,%p)\n", pUdateIn,
|
||||
pUdateIn->st.wMonth, pUdateIn->st.wDay, pUdateIn->st.wYear,
|
||||
|
@ -1381,10 +1381,13 @@ HRESULT WINAPI VarDateFromUdateEx(UDATE *pUdateIn, LCID lcid, ULONG dwFlags, DAT
|
|||
/* Date */
|
||||
dateVal = VARIANT_DateFromJulian(VARIANT_JulianFromDMY(ud.st.wYear, ud.st.wMonth, ud.st.wDay));
|
||||
|
||||
/* Sign */
|
||||
dateSign = (dateVal < 0.0) ? -1.0 : 1.0;
|
||||
|
||||
/* Time */
|
||||
dateVal += ud.st.wHour / 24.0;
|
||||
dateVal += ud.st.wMinute / 1440.0;
|
||||
dateVal += ud.st.wSecond / 86400.0;
|
||||
dateVal += ud.st.wHour / 24.0 * dateSign;
|
||||
dateVal += ud.st.wMinute / 1440.0 * dateSign;
|
||||
dateVal += ud.st.wSecond / 86400.0 * dateSign;
|
||||
|
||||
TRACE("Returning %g\n", dateVal);
|
||||
*pDateOut = dateVal;
|
||||
|
@ -1447,7 +1450,7 @@ HRESULT WINAPI VarUdateFromDate(DATE dateIn, ULONG dwFlags, UDATE *lpUdate)
|
|||
|
||||
datePart = dateIn < 0.0 ? ceil(dateIn) : floor(dateIn);
|
||||
/* Compensate for int truncation (always downwards) */
|
||||
timePart = dateIn - datePart + 0.00000000001;
|
||||
timePart = fabs(dateIn - datePart) + 0.00000000001;
|
||||
if (timePart >= 1.0)
|
||||
timePart -= 0.00000000001;
|
||||
|
||||
|
|
Loading…
Reference in New Issue