| 1305 | } |
| 1306 | |
| 1307 | txNumber fxDateMerge(txDateTime* dt, txBoolean utc) |
| 1308 | { |
| 1309 | txNumber year, month; |
| 1310 | txInteger monthIndex; |
| 1311 | txBoolean leap; |
| 1312 | txNumber value; |
| 1313 | if ((!c_isfinite(dt->year)) |
| 1314 | || (!c_isfinite(dt->month)) |
| 1315 | || (!c_isfinite(dt->date)) |
| 1316 | || (!c_isfinite(dt->hours)) |
| 1317 | || (!c_isfinite(dt->minutes)) |
| 1318 | || (!c_isfinite(dt->seconds)) |
| 1319 | || (!c_isfinite(dt->milliseconds))) |
| 1320 | return C_NAN; |
| 1321 | year = c_trunc(dt->year); |
| 1322 | month = c_trunc(dt->month); |
| 1323 | year += c_floor(month / 12); |
| 1324 | monthIndex = (txInteger)c_fmod(month, 12.0); |
| 1325 | if (monthIndex < 0) |
| 1326 | monthIndex += 12; |
| 1327 | leap = (c_fmod(year, 4) == 0) && ((c_fmod(year, 100) != 0) || (c_fmod(year, 400) == 0)); |
| 1328 | year += mxYearsOffset - 1; |
| 1329 | value = (365 * year) + c_floor(year / 4) - c_floor(year / 100) + c_floor(year / 400) + 1; |
| 1330 | value -= (txNumber)mxYearDays(1970 + mxYearsOffset - 1); |
| 1331 | if (leap) |
| 1332 | value += gxLeapYearMonthsDays[monthIndex]; |
| 1333 | else |
| 1334 | value += gxCommonYearMonthsDays[monthIndex]; |
| 1335 | value += c_trunc(dt->date) - 1; |
| 1336 | value *= mxDayMilliseconds; |
| 1337 | value += c_trunc(dt->hours) * 60 * 60 * 1000; |
| 1338 | value += c_trunc(dt->minutes) * 60 * 1000; |
| 1339 | value += c_trunc(dt->seconds) * 1000; |
| 1340 | value += c_trunc(dt->milliseconds); |
| 1341 | if (!utc) { |
| 1342 | txNumber former = value; |
| 1343 | txInteger similar; |
| 1344 | c_tm tm; |
| 1345 | c_time_t time; |
| 1346 | fxDateSplit(value, 1, dt); |
| 1347 | similar = fxDateSimilarYear((txInteger)dt->year); |
| 1348 | c_memset(&tm, 0, sizeof(c_tm)); |
| 1349 | tm.tm_year = similar - 1900; |
| 1350 | tm.tm_mon = (txInteger)dt->month; |
| 1351 | tm.tm_mday = (txInteger)dt->date; |
| 1352 | tm.tm_hour = (txInteger)dt->hours; |
| 1353 | tm.tm_min = (txInteger)dt->minutes; |
| 1354 | tm.tm_sec = (txInteger)dt->seconds; |
| 1355 | tm.tm_isdst =-1; |
| 1356 | time = c_mktime(&tm); |
| 1357 | if (time == -1) |
| 1358 | value = NAN; |
| 1359 | else { |
| 1360 | value = (txNumber)time; |
| 1361 | value *= 1000; |
| 1362 | value += dt->milliseconds; |
| 1363 | if (similar != year) { |
| 1364 | dt->year = similar; |
no test coverage detected