33 #define DISABLE_DEBUGLOG 36 #include "gwentime_p.h" 37 #include <gwenhywfar/gwentime.h> 38 #include <gwenhywfar/debug.h> 85 "Overflow when adding %u seconds", secs);
101 "Underflow when subtracting %u seconds",
166 int day, month, year;
193 "Creating time from this: %04d/%02d/%02d - %02d:%02d:%02d (%d)",
194 year, month, day, hour, min, sec, inUtc);
208 int year, month, day;
232 if (!isdigit((
int)*p))
242 if (isdigit((
int)*p))
249 if (i==-1 && strchr(
"YMDhms", *t)!=
NULL) {
251 "No more digits at [%s], continuing", t);
306 "Unknown character in template, will skip in both strings");
319 "Got this date/time: %04d/%02d/%02d, %02d:%02d:%02d",
320 year, month-1, day, hour, min, sec);
323 gwt=
GWEN_Time_new(year, month-1, day, hour, min, sec, inUtc);
367 memmove(&ti, tp,
sizeof(ti));
376 ti.tm_year=year-1900;
382 assert(tt!=(time_t)-1);
400 const uint32_t hoursecs=60*60;
401 const uint32_t daysecs=24*hoursecs;
402 const uint32_t yearsecs=365*daysecs;
403 const uint32_t monthDays[12]= {
409 result=(year-1970)*yearsecs;
411 for (i=1970; i<year; i++)
417 isLeap=((((year % 4)==0) &&
418 ((year % 100)!=0)) ||
421 for (i=0; i<month; i++)
425 result+=monthDays[i]*daysecs;
427 result+=(day-1)*daysecs;
428 result+=(hour*hoursecs);
444 newT->msecs=t->msecs;
466 d=1000.0*((double)(t1->secs)-(double)(t0->secs));
467 d+=(double)((
double)(t1->msecs)-(
double)(t0->msecs));
481 d=(double)(t1->secs)-(double)(t0->secs);
482 d+=((double)((
double)(t1->msecs)-(
double)(t0->msecs)))/1000.0;
492 if (t1->secs<t0->secs)
494 else if (t1->secs>t0->secs)
497 if (t1->msecs<t0->msecs)
499 else if (t1->msecs>t0->msecs)
518 return (
double)((t->secs*1000)+(t->msecs));
594 *year=tb->tm_year+1900;
617 *year=tb->tm_year+1900;
646 GWEN_TIME_TMPLCHAR *e;
669 GWEN_TIME_TMPLCHAR *e;
671 e=GWEN_TimeTmplChar_List_First(ll);
675 e=GWEN_TimeTmplChar_List_Next(e);
686 GWEN_TIME_TMPLCHAR_LIST *ll)
692 if (strchr(
"YMDhms", *s)) {
693 GWEN_TIME_TMPLCHAR *e;
699 GWEN_TimeTmplChar_List_Add(e, ll);
715 GWEN_TIME_TMPLCHAR_LIST *ll,
718 GWEN_TIME_TMPLCHAR *e;
719 int year, month, day, hour, minute, second;
730 e=GWEN_TimeTmplChar_List_First(ll);
735 switch (e->character) {
763 snprintf(buffer,
sizeof(buffer)-1,
"%0*d", GWEN_TIME_TMPL_MAX_COUNT, v);
764 buffer[
sizeof(buffer)-1]=0;
765 e->content=strdup(buffer);
766 e->nextChar=strlen(e->content)-(e->count);
767 e=GWEN_TimeTmplChar_List_Next(e);
777 GWEN_TIME_TMPLCHAR_LIST *ll;
780 ll=GWEN_TimeTmplChar_List_new();
786 if (strchr(
"YMDhms", *s)) {
787 GWEN_TIME_TMPLCHAR *e;
800 c=e->content[e->nextChar++];
809 GWEN_TimeTmplChar_List_free(ll);
struct GWEN_TIME GWEN_TIME
double GWEN_Time_Diff(const GWEN_TIME *t1, const GWEN_TIME *t0)
int GWEN_Time_GetBrokenDownUtcDate(const GWEN_TIME *t, int *days, int *month, int *year)
void GWEN_Time__fillTmplChars(const GWEN_TIME *t, GWEN_TIME_TMPLCHAR_LIST *ll, int useUtc)
#define GWEN_DB_FLAGS_OVERWRITE_VARS
struct tm GWEN_Time_toTm(const GWEN_TIME *t)
int GWEN_Time_AddSeconds(GWEN_TIME *ti, uint32_t secs)
struct GWEN_DB_NODE GWEN_DB_NODE
int GWEN_Time_GetBrokenDownDate(const GWEN_TIME *t, int *days, int *month, int *year)
int GWEN_Time_toDb(const GWEN_TIME *t, GWEN_DB_NODE *db)
#define GWEN_ERROR_INVALID
double GWEN_Time_DiffSeconds(const GWEN_TIME *t1, const GWEN_TIME *t0)
int GWEN_Time_SubSeconds(GWEN_TIME *ti, uint32_t secs)
int GWEN_Time_Compare(const GWEN_TIME *t1, const GWEN_TIME *t0)
void GWEN_Time__sampleTmplChars(GWEN_UNUSED const GWEN_TIME *t, const char *tmpl, GWEN_UNUSED GWEN_BUFFER *buf, GWEN_TIME_TMPLCHAR_LIST *ll)
uint32_t GWEN_Time_Seconds(const GWEN_TIME *t)
#define GWEN_FREE_OBJECT(varname)
#define DBG_VERBOUS(dbg_logger, format, args...)
double GWEN_Time_Milliseconds(const GWEN_TIME *t)
GWEN_TIME * GWEN_Time_new(int year, int month, int day, int hour, int min, int sec, int inUtc)
void GWEN_Time_free(GWEN_TIME *t)
GWEN_TIME * GWEN_Time_fromString(const char *s, const char *tmpl)
int GWEN_Time_GetBrokenDownTime(const GWEN_TIME *t, int *hours, int *mins, int *secs)
#define GWEN_NEW_OBJECT(typ, varname)
int GWEN_Time_toUtcString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf)
GWEN_TIME * GWEN_Time_fromDb(GWEN_DB_NODE *db)
#define DBG_DEBUG(dbg_logger, format, args...)
GWEN_TIME * GWEN_Time_fromUtcString(const char *s, const char *tmpl)
time_t GWEN_Time_toTime_t(const GWEN_TIME *t)
uint32_t GWEN_Time__mktimeUtc(int year, int month, int day, int hour, int min, int sec)
GWEN_TIME * GWEN_Time_fromSeconds(uint32_t secs)
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
int GWEN_Time__GetCurrentTime(GWEN_TIME *ti)
GWEN_TIME * GWEN_Time_dup(const GWEN_TIME *t)
GWEN_TIME * GWEN_Time__fromString(const char *s, const char *tmpl, int inUtc)
#define DBG_ERROR(dbg_logger, format, args...)
GWEN_TIME_TMPLCHAR * GWEN_Time__findTmplChar(GWEN_TIME_TMPLCHAR_LIST *ll, char c)
void GWEN_Time__SetSecsAndMSecs(GWEN_TIME *ti, uint32_t secs, uint32_t msecs)
#define DBG_INFO(dbg_logger, format, args...)
GWEN_TIME * GWEN_CurrentTime(void)
GWEN_TIME_TMPLCHAR * GWEN_TimeTmplChar_new(char c)
#define GWEN_LIST_INIT(t, element)
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
void GWEN_TimeTmplChar_free(GWEN_TIME_TMPLCHAR *e)
int GWEN_Time_toString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf)
int GWEN_Time_GetBrokenDownUtcTime(const GWEN_TIME *t, int *hours, int *mins, int *secs)
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
#define GWEN_LIST_FUNCTIONS(t, pr)
#define GWEN_PATH_FLAGS_NAMEMUSTEXIST
int GWEN_Time__toString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf, int useUtc)
#define GWEN_LIST_FINI(t, element)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
#define GWEN_DB_FLAGS_DEFAULT