33 #define DISABLE_DEBUGLOG
36 #include "gwentime_p.h"
37 #include <gwenhywfar/gwentime.h>
38 #include <gwenhywfar/debug.h>
82 "Overflow when adding %u seconds", secs);
97 "Underflow when subtracting %u seconds",
159 int day, month, year;
186 "Creating time from this: %04d/%02d/%02d - %02d:%02d:%02d (%d)",
187 year, month, day, hour, min, sec, inUtc);
200 int year, month, day;
224 if (!isdigit((
int)*p))
234 if (isdigit((
int)*p))
241 if (i==-1 && strchr(
"YMDhms", *t)!=
NULL) {
243 "No more digits at [%s], continueing", t);
298 "Unknown character in template, will skip in both strings");
311 "Got this date/time: %04d/%02d/%02d, %02d:%02d:%02d",
312 year, month-1, day, hour, min, sec);
315 gwt=
GWEN_Time_new(year, month-1, day, hour, min, sec, inUtc);
356 memmove(&ti, tp,
sizeof(ti));
365 ti.tm_year=year-1900;
371 assert(tt!=(time_t)-1);
388 const uint32_t hoursecs=60*60;
389 const uint32_t daysecs=24*hoursecs;
390 const uint32_t yearsecs=365*daysecs;
391 const uint32_t monthDays[12]=
398 result=(year-1970)*yearsecs;
400 for (i=1970; i<year; i++)
406 isLeap=((((year % 4)==0) &&
407 ((year % 100)!=0)) ||
410 for (i=0; i<month; i++)
414 result+=monthDays[i]*daysecs;
416 result+=(day-1)*daysecs;
417 result+=(hour*hoursecs);
432 newT->msecs=t->msecs;
452 d=1000.0*((double)(t1->secs)-(double)(t0->secs));
453 d+=(double)((
double)(t1->msecs)-(
double)(t0->msecs));
466 d=(double)(t1->secs)-(double)(t0->secs);
467 d+=((double)((
double)(t1->msecs)-(
double)(t0->msecs)))/1000.0;
476 if (t1->secs<t0->secs)
478 else if (t1->secs>t0->secs)
481 if (t1->msecs<t0->msecs)
483 else if (t1->msecs>t0->msecs)
501 return (
double)((t->secs*1000)+(t->msecs));
573 *year=tb->tm_year+1900;
595 *year=tb->tm_year+1900;
621 GWEN_TIME_TMPLCHAR *e;
642 GWEN_TIME_TMPLCHAR *e;
644 e=GWEN_TimeTmplChar_List_First(ll);
648 e=GWEN_TimeTmplChar_List_Next(e);
659 GWEN_TIME_TMPLCHAR_LIST *ll) {
664 if (strchr(
"YMDhms", *s)) {
665 GWEN_TIME_TMPLCHAR *e;
671 GWEN_TimeTmplChar_List_Add(e, ll);
687 GWEN_TIME_TMPLCHAR_LIST *ll,
689 GWEN_TIME_TMPLCHAR *e;
690 int year, month, day, hour, minute, second;
701 e=GWEN_TimeTmplChar_List_First(ll);
706 switch(e->character) {
707 case 'Y': v=year;
break;
708 case 'M': v=month+1;
break;
709 case 'D': v=day;
break;
710 case 'h': v=hour;
break;
711 case 'm': v=minute;
break;
712 case 's': v=second;
break;
713 default: v=-1;
break;
720 snprintf(buffer,
sizeof(buffer)-1,
"%0*d", GWEN_TIME_TMPL_MAX_COUNT, v);
721 buffer[
sizeof(buffer)-1]=0;
722 e->content=strdup(buffer);
723 e->nextChar=strlen(e->content)-(e->count);
724 e=GWEN_TimeTmplChar_List_Next(e);
733 GWEN_TIME_TMPLCHAR_LIST *ll;
736 ll=GWEN_TimeTmplChar_List_new();
742 if (strchr(
"YMDhms", *s)) {
743 GWEN_TIME_TMPLCHAR *e;
756 c=e->content[e->nextChar++];
765 GWEN_TimeTmplChar_List_free(ll);