/*---------------------------------------------------------------------*/ BGL_RUNTIME_DEF obj_t bgl_seconds_to_date( long sec ) { obj_t res; bgl_mutex_lock( date_mutex ); res = tm_to_date( localtime( (time_t *)&sec ) ); bgl_mutex_unlock( date_mutex ); return res; }
static Sophon_Result time_to_local_date (Sophon_VM *vm, Sophon_Time *time, Sophon_Date *date) { struct tm *d; time_t t; t = sophon_floor(*time / 1000); if (!(d = localtime(&t))) return SOPHON_ERR_ARG; return tm_to_date(date, time, d); }
void os_gmtime(date_t* date, int64_t sec, int64_t nsec) { int64_t overflow_sec = nsec / 1000000000; nsec -= (overflow_sec * 1000000000); if(nsec < 0) { nsec += 1000000000; overflow_sec--; } time_t t = sec + overflow_sec; struct tm tm; #ifdef PLATFORM_IS_WINDOWS gmtime_s(&tm, &t); #else gmtime_r(&t, &tm); #endif tm_to_date(&tm, nsec, date); }
PONY_API void ponyint_gmtime(date_t* date, int64_t sec, int64_t nsec) { time_t overflow_sec = (time_t)(nsec / 1000000000); nsec -= (overflow_sec * 1000000000); if(nsec < 0) { nsec += 1000000000; overflow_sec--; } time_t t = (time_t)sec + overflow_sec; struct tm tm; #ifdef PLATFORM_IS_WINDOWS gmtime_s(&tm, &t); #else gmtime_r(&t, &tm); #endif tm_to_date(&tm, (int)nsec, date); }