MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / timegm

Function timegm

components/libc/compilers/common/ctime.c:382–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380RTM_EXPORT(stime);
381
382time_t timegm(struct tm * const t)
383{
384 time_t day;
385 time_t i;
386 time_t years;
387
388 if(t == RT_NULL)
389 {
390 rt_set_errno(EFAULT);
391 return (time_t)-1;
392 }
393
394 years = (time_t)t->tm_year - 70;
395 if (t->tm_sec > 60) /* seconds after the minute - [0, 60] including leap second */
396 {
397 t->tm_min += t->tm_sec / 60;
398 t->tm_sec %= 60;
399 }
400 if (t->tm_min >= 60) /* minutes after the hour - [0, 59] */
401 {
402 t->tm_hour += t->tm_min / 60;
403 t->tm_min %= 60;
404 }
405 if (t->tm_hour >= 24) /* hours since midnight - [0, 23] */
406 {
407 t->tm_mday += t->tm_hour / 24;
408 t->tm_hour %= 24;
409 }
410 if (t->tm_mon >= 12) /* months since January - [0, 11] */
411 {
412 t->tm_year += t->tm_mon / 12;
413 t->tm_mon %= 12;
414 }
415 while (t->tm_mday > __spm[1 + t->tm_mon])
416 {
417 if (t->tm_mon == 1 && __isleap(t->tm_year + 1900))
418 {
419 --t->tm_mday;
420 }
421 t->tm_mday -= __spm[t->tm_mon];
422 ++t->tm_mon;
423 if (t->tm_mon > 11)
424 {
425 t->tm_mon = 0;
426 ++t->tm_year;
427 }
428 }
429
430 if (t->tm_year < 70)
431 {
432 rt_set_errno(EINVAL);
433 return (time_t) -1;
434 }
435
436 /* Days since 1970 is 365 * number of years + number of leap years since 1970 */
437 day = years * 365 + (years + 1) / 4;
438
439 /* After 2100 we have to substract 3 leap years for every 400 years

Callers 15

__initdataFunction · 0.85
alarm_wakeupFunction · 0.85
rt_soft_rtc_initFunction · 0.85
mktimeFunction · 0.85
dfs_elm_statFunction · 0.85
dfs_elm_statFunction · 0.85
es32f0_rtc_controlFunction · 0.85
es32f0_rtc_controlFunction · 0.85
n32_rtc_get_timevalFunction · 0.85
pico_rtc_get_timevalFunction · 0.85
get_rtc_timestampFunction · 0.85
get_rtc_timestampFunction · 0.85

Calls 2

rt_set_errnoFunction · 0.85
__isleapFunction · 0.85

Tested by 1

test_rtc_alarmFunction · 0.68