|
1 | 1 | /* ModelicaInternal.c - External functions for Modelica.Utilities |
2 | 2 |
|
3 | | - Copyright (C) 2002-2020, Modelica Association and contributors |
| 3 | + Copyright (C) 2002-2023, Modelica Association and contributors |
4 | 4 | All rights reserved. |
5 | 5 |
|
6 | 6 | Redistribution and use in source and binary forms, with or without |
|
38 | 38 | Added getcwd fallback in ModelicaInternal_fullPathName if |
39 | 39 | realpath fails for non-existing path (ticket #3660) |
40 | 40 |
|
| 41 | + Dec. 02, 2019: by Thomas Beutlich |
| 42 | + Removed call of localtime in ModelicaInternal_getTime |
| 43 | + (ticket #3246) |
| 44 | +
|
41 | 45 | Nov. 13, 2019: by Thomas Beutlich |
42 | 46 | Utilized blockwise I/O in ModelicaInternal_copyFile |
43 | 47 | (ticket #3229) |
@@ -1332,40 +1336,51 @@ void ModelicaInternal_getTime(_Out_ int* ms, _Out_ int* sec, _Out_ int* min, _Ou |
1332 | 1336 | *year = 0; |
1333 | 1337 | #else |
1334 | 1338 | struct tm* tlocal; |
1335 | | - time_t calendarTime; |
1336 | 1339 | int ms0; |
1337 | 1340 | #if defined(_POSIX_) || (defined(_MSC_VER) && _MSC_VER >= 1400) |
1338 | 1341 | struct tm tres; |
1339 | 1342 | #endif |
1340 | 1343 |
|
1341 | | - time(&calendarTime); /* Retrieve sec time */ |
1342 | | -#if defined(_POSIX_) |
1343 | | - tlocal = localtime_r(&calendarTime, &tres); /* Time fields in local time zone */ |
1344 | | -#elif defined(_MSC_VER) && _MSC_VER >= 1400 |
1345 | | - localtime_s(&tres, &calendarTime); /* Time fields in local time zone */ |
1346 | | - tlocal = &tres; |
1347 | | -#else |
1348 | | - tlocal = localtime(&calendarTime); /* Time fields in local time zone */ |
1349 | | -#endif |
1350 | | - |
1351 | | - /* Get millisecond resolution depending on platform */ |
1352 | 1344 | #if defined(_WIN32) |
1353 | | - { |
1354 | 1345 | #if defined(__BORLANDC__) |
1355 | | - struct timeb timebuffer; |
| 1346 | + struct timeb timebuffer; |
1356 | 1347 | ftime( &timebuffer ); /* Retrieve ms time */ |
1357 | 1348 | #else |
1358 | | - struct _timeb timebuffer; |
| 1349 | + struct _timeb timebuffer; |
1359 | 1350 | _ftime( &timebuffer ); /* Retrieve ms time */ |
1360 | 1351 | #endif |
1361 | | - ms0 = (int)(timebuffer.millitm); /* Convert unsigned int to int */ |
1362 | | - } |
| 1352 | +#if defined(__BORLANDC__) |
| 1353 | + ftime(&timebuffer); |
| 1354 | + timebuffer.time -= 60 * timebuffer.timezone; |
| 1355 | + if (timebuffer.dstflag != 0) |
| 1356 | + timebuffer.time += 3600; |
| 1357 | + tlocal = gmtime(&timebuffer.time); |
| 1358 | +#elif defined(_MSC_VER) && _MSC_VER >= 1400 |
| 1359 | + _ftime_s(&timebuffer); |
| 1360 | + timebuffer.time -= 60 * timebuffer.timezone; |
| 1361 | + if (timebuffer.dstflag != 0) { |
| 1362 | + int hours = 0; |
| 1363 | + _get_daylight(&hours); |
| 1364 | + timebuffer.time += 3600 * hours; |
| 1365 | + } |
| 1366 | + gmtime_s(&tres, &timebuffer.time); |
| 1367 | + tlocal = &tres; |
1363 | 1368 | #else |
1364 | | - { |
1365 | | - struct timeval tv; |
1366 | | - gettimeofday(&tv, NULL); |
1367 | | - ms0 = (int)(tv.tv_usec/1000); /* Convert microseconds to milliseconds */ |
1368 | | - } |
| 1369 | + _ftime(&timebuffer); |
| 1370 | + timebuffer.time -= 60 * timebuffer.timezone; |
| 1371 | + if (timebuffer.dstflag != 0) |
| 1372 | + timebuffer.time += 3600; |
| 1373 | + tlocal = gmtime(&timebuffer.time); |
| 1374 | +#endif |
| 1375 | + ms0 = (int)(timebuffer.millitm); /* Convert unsigned int to int */ |
| 1376 | +#else |
| 1377 | + struct timeval tv; |
| 1378 | + struct timezone tz; |
| 1379 | + gettimeofday(&tv, &tz); |
| 1380 | + tv.tv_sec -= 60 * tz.tz_minuteswest; |
| 1381 | + gmtime_r(&tv.tv_sec, &tres); |
| 1382 | + tlocal = &tres; |
| 1383 | + ms0 = (int)(tv.tv_usec / 1000); /* Convert microseconds to milliseconds */ |
1369 | 1384 | #endif |
1370 | 1385 |
|
1371 | 1386 | /* Do not memcpy as you do not know which sizes are in the struct */ |
|
0 commit comments