xpDateTime_t DLLCALL xpDateTime_now(void) { #if defined(_WIN32) SYSTEMTIME systime; GetLocalTime(&systime); return(xpDateTime_create(systime.wYear,systime.wMonth,systime.wDay ,systime.wHour,systime.wMinute,(float)systime.wSecond+(systime.wMilliseconds*0.001F) ,xpTimeZone_local())); #else /* !Win32 (e.g. Unix) */ struct tm tm; struct timeval tv; time_t t; gettimeofday(&tv, NULL); t=tv.tv_sec; localtime_r(&t,&tm); return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec+(tv.tv_usec*0.00001) ,xpTimeZone_local()); #endif }
xpDateTime_t DLLCALL time_to_xpDateTime(time_t ti, xpTimeZone_t zone) { xpDateTime_t never; struct tm tm; ZERO_VAR(never); ZERO_VAR(tm); if(localtime_r(&ti,&tm)==NULL) return(never); return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec ,zone==xpTimeZone_LOCAL ? xpTimeZone_local() : zone); }
xpDateTime_t DLLCALL gmtime_to_xpDateTime(time_t ti) { xpDateTime_t never; struct tm tm; ZERO_VAR(never); ZERO_VAR(tm); if(gmtime_r(&ti,&tm)==NULL) return(never); return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec ,xpTimeZone_UTC); }
xpDateTime_t time_to_xpDateTime(time_t ti) { xpDateTime_t never; struct tm tm; memset(&never,0,sizeof(never)); if(ti==0) return(never); ZERO_VAR(tm); if(gmtime_r(&ti,&tm)==NULL) return(never); return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec,xpTimeZone_local()); }
xpDateTime_t DLLCALL isoDateTime_to_xpDateTime(isoDate_t date, isoTime_t ti) { return xpDateTime_create(isoDate_year(date),isoDate_month(date),isoDate_day(date) ,isoTime_hour(ti),isoTime_minute(ti),(float)isoTime_second(ti),xpTimeZone_local()); }