30 #include "gwendate_p.h" 33 #include <gwenhywfar/debug.h> 34 #include <gwenhywfar/misc.h> 43 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
66 if (m<1 || m>12 || d<1 || d>31) {
75 gd->julian=(1461*(y+4800+(m-14)/12))/4+
76 (367*(m-2-12*((m-14)/12)))/12-
77 (3*((y+4900+(m-14)/12)/100))/4+
81 memmove(gd->asString, s, 8);
99 i=(4000*(l+1))/1461001;
102 gd->day=l-(2447*j)/80;
104 gd->month=j+2-(12*l);
105 gd->year=100*(n-49)+i+l;
111 len=snprintf(gd->asString,
sizeof(gd->asString)-1,
113 gd->year, gd->month, gd->day);
114 gd->asString[
sizeof(gd->asString)-1]=0;
115 if ((
int)(
sizeof(gd->asString)-1) < len) {
204 memmove(&ti, tp,
sizeof(ti));
208 ti.tm_year=gd->year-1900;
209 ti.tm_mon=gd->month-1;
214 assert(tt!=(time_t)-1);
257 gd->month=ogd->month;
259 gd->julian=ogd->julian;
260 memmove(gd->asString, ogd->asString,
sizeof(gd->asString));
273 if (s && strlen(s)>7) {
276 const char *originalPtr;
308 if (3==sscanf(s,
"%04d%02d%02d", &y, &m, &d)) {
334 return ((y%4==0) && (y%100!=0)) || (y%400==0);
344 ((((gd->year%4)==0) && ((gd->year)%100!=0)) || ((gd->year)%400==0)))
361 result=(gd->julian)-(gd11->julian);
404 return (gd->julian+1)%7;
420 if (gd1->julian==gd0->julian)
422 else if (gd1->julian>gd0->julian)
442 return gd1->julian-gd0->julian;
465 int year, month, day;
487 if (!isdigit((
int)*p))
497 if (isdigit((
int)*p))
504 if (i==-1 && strchr(
"YMD", *t)!=
NULL) {
506 "No more digits at [%s], continuing", t);
537 "Unknown character in template, will skip in both strings");
548 "Got this date/time: %04d/%02d/%02d",
569 GWEN_DATE_TMPLCHAR *e;
589 e->maxCount=GWEN_DATE_TMPL_MAX_COUNT;
611 GWEN_DATE_TMPLCHAR *e;
613 e=GWEN_DateTmplChar_List_First(ll);
617 e=GWEN_DateTmplChar_List_Next(e);
628 GWEN_DATE_TMPLCHAR_LIST *ll)
634 if (strchr(
"YMDWw", *s)) {
635 GWEN_DATE_TMPLCHAR *e;
641 GWEN_DateTmplChar_List_Add(e, ll);
658 GWEN_DATE_TMPLCHAR *e;
661 e=GWEN_DateTmplChar_List_First(ll);
665 if (e->character==
'w') {
696 e->content=strdup(s);
703 switch (e->character) {
725 snprintf(buffer,
sizeof(buffer)-1,
"%0*d", e->maxCount, v);
726 buffer[
sizeof(buffer)-1]=0;
727 e->content=strdup(buffer);
729 clen=strlen(e->content);
732 e->nextChar=clen-(e->count);
735 e=GWEN_DateTmplChar_List_Next(e);
744 GWEN_DATE_TMPLCHAR_LIST *ll;
747 ll=GWEN_DateTmplChar_List_new();
753 if (strchr(
"YMDWw", *s)) {
754 GWEN_DATE_TMPLCHAR *e;
767 c=e->content[e->nextChar];
778 GWEN_DateTmplChar_List_free(ll);
GWEN_DATE * GWEN_Date_fromDb(GWEN_DB_NODE *db)
struct GWEN_TIME GWEN_TIME
void GWEN_Date_SubDays(GWEN_DATE *gd, int days)
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
GWEN_DATE * GWEN_Date_fromString(const char *s)
GWEN_DATE * GWEN_Date_dup(const GWEN_DATE *ogd)
#define GWEN_DB_FLAGS_OVERWRITE_VARS
GWEN_DATE * GWEN_Date_GetLastHalfYearStart(const GWEN_DATE *dt)
GWEN_DATE * GWEN_Date_fromStringWithTemplate(const char *s, const char *tmpl)
struct GWEN_DB_NODE GWEN_DB_NODE
GWEN_DATE_TMPLCHAR * GWEN_DateTmplChar_new(char c)
GWEN_DATE * GWEN_Date_GetLastMonthStart(const GWEN_DATE *dt)
static const uint8_t daysInMonth[12]
int GWEN_Date_WeekDay(const GWEN_DATE *gd)
#define GWEN_FREE_OBJECT(varname)
time_t GWEN_Date_toLocalTime(const GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_GetThisMonthEnd(const GWEN_DATE *dt)
#define DBG_VERBOUS(dbg_logger, format, args...)
int GWEN_Date_toStringWithTemplate(const GWEN_DATE *t, const char *tmpl, GWEN_BUFFER *buf)
void GWEN_DateTmplChar_free(GWEN_DATE_TMPLCHAR *e)
GWEN_DATE * GWEN_Date_CurrentDate(void)
int GWEN_Date_toDb(const GWEN_DATE *dt, GWEN_DB_NODE *db)
GWEN_DATE * GWEN_Date_fromTime(const GWEN_TIME *ti)
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
void GWEN_Date__fillTmplChars(const GWEN_DATE *t, GWEN_DATE_TMPLCHAR_LIST *ll)
#define GWEN_NEW_OBJECT(typ, varname)
GWENHYWFAR_API int GWEN_Time_toString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf)
int GWEN_Date_DaysInYear(const GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_GetThisYearEnd(const GWEN_DATE *dt)
#define DBG_DEBUG(dbg_logger, format, args...)
GWEN_DATE * GWEN_Date_GetLastHalfYearEnd(const GWEN_DATE *dt)
void GWEN_Date_free(GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_GetThisMonthStart(const GWEN_DATE *dt)
void GWEN_Date__sampleTmplChars(GWEN_UNUSED const GWEN_DATE *t, const char *tmpl, GWEN_UNUSED GWEN_BUFFER *buf, GWEN_DATE_TMPLCHAR_LIST *ll)
GWEN_DATE * GWEN_Date_GetLastMonthEnd(const GWEN_DATE *dt)
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
int GWEN_Date_DaysInMonth(const GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_fromGregorian(int y, int m, int d)
int GWEN_Date_GetMonth(const GWEN_DATE *gd)
void GWEN_Buffer_free(GWEN_BUFFER *bf)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
GWEN_DATE * GWEN_Date_GetThisYearStart(const GWEN_DATE *dt)
void GWEN_Date_AddDays(GWEN_DATE *gd, int days)
GWEN_DATE * GWEN_Date_GetThisHalfYearEnd(const GWEN_DATE *dt)
const char * GWEN_Date_GetString(const GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_fromLocalTime(time_t t)
GWEN_DATE * GWEN_Date_GetThisQuarterYearStart(const GWEN_DATE *dt)
GWEN_DATE * GWEN_Date_GetLastYearEnd(const GWEN_DATE *dt)
#define DBG_ERROR(dbg_logger, format, args...)
static void _writeAsString(GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_GetLastYearStart(const GWEN_DATE *dt)
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
static GWEN_DATE * _createFromGregorianAndUseGivenString(int y, int m, int d, const char *s)
#define DBG_INFO(dbg_logger, format, args...)
int GWEN_Date_GetJulian(const GWEN_DATE *gd)
#define GWEN_LIST_INIT(t, element)
GWEN_DATE * GWEN_Date_fromGmTime(time_t t)
GWEN_DATE * GWEN_Date_GetLastQuarterYearEnd(const GWEN_DATE *dt)
int GWEN_Date_IsLeapYear(int y)
#define GWEN_LIST_FUNCTIONS(t, pr)
GWEN_DATE * GWEN_Date_GetThisQuarterYearEnd(const GWEN_DATE *dt)
GWEN_DATE * GWEN_Date_GetThisHalfYearStart(const GWEN_DATE *dt)
int GWEN_Date_GetDay(const GWEN_DATE *gd)
GWEN_DATE * GWEN_Date_fromJulian(int julian)
int GWEN_Date_GetYear(const GWEN_DATE *gd)
GWEN_DATE_TMPLCHAR * GWEN_Date__findTmplChar(GWEN_DATE_TMPLCHAR_LIST *ll, char c)
int GWEN_Date_Diff(const GWEN_DATE *gd1, const GWEN_DATE *gd0)
#define GWEN_LIST_FINI(t, element)
void GWEN_Date_setJulian(GWEN_DATE *gd, int julian)
int GWEN_Date_Compare(const GWEN_DATE *gd1, const GWEN_DATE *gd0)
GWEN_DATE * GWEN_Date_GetLastQuarterYearStart(const GWEN_DATE *dt)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
struct GWEN_DATE GWEN_DATE