| 1264 | */ |
| 1265 | |
| 1266 | bool |
| 1267 | calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, |
| 1268 | int l_sign, longlong *seconds_out, long *microseconds_out) |
| 1269 | { |
| 1270 | long days; |
| 1271 | bool neg; |
| 1272 | longlong microseconds; |
| 1273 | |
| 1274 | /* |
| 1275 | We suppose that if first argument is MYSQL_TIMESTAMP_TIME |
| 1276 | the second argument should be TIMESTAMP_TIME also. |
| 1277 | We should check it before calc_time_diff call. |
| 1278 | */ |
| 1279 | if (l_time1->time_type == MYSQL_TIMESTAMP_TIME) // Time value |
| 1280 | days= (long)l_time1->day - l_sign * (long)l_time2->day; |
| 1281 | else |
| 1282 | { |
| 1283 | days= calc_daynr((uint) l_time1->year, |
| 1284 | (uint) l_time1->month, |
| 1285 | (uint) l_time1->day); |
| 1286 | if (l_time2->time_type == MYSQL_TIMESTAMP_TIME) |
| 1287 | days-= l_sign * (long)l_time2->day; |
| 1288 | else |
| 1289 | days-= l_sign*calc_daynr((uint) l_time2->year, |
| 1290 | (uint) l_time2->month, |
| 1291 | (uint) l_time2->day); |
| 1292 | } |
| 1293 | |
| 1294 | microseconds= ((longlong)days * SECONDS_IN_24H + |
| 1295 | (longlong)(l_time1->hour*3600L + |
| 1296 | l_time1->minute*60L + |
| 1297 | l_time1->second) - |
| 1298 | l_sign*(longlong)(l_time2->hour*3600L + |
| 1299 | l_time2->minute*60L + |
| 1300 | l_time2->second)) * LL(1000000) + |
| 1301 | (longlong)l_time1->second_part - |
| 1302 | l_sign*(longlong)l_time2->second_part; |
| 1303 | |
| 1304 | neg= 0; |
| 1305 | if (microseconds < 0) |
| 1306 | { |
| 1307 | microseconds= -microseconds; |
| 1308 | neg= 1; |
| 1309 | } |
| 1310 | *seconds_out= microseconds/1000000L; |
| 1311 | *microseconds_out= (long) (microseconds%1000000L); |
| 1312 | return neg; |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | /* |
no test coverage detected