gwenhywfar  5.4.1
gwendate.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Tue Jul 07 2009
3  copyright : (C) 2019 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 
30 #include "gwendate_p.h"
31 #include "i18n_l.h"
32 
33 #include <gwenhywfar/debug.h>
34 #include <gwenhywfar/misc.h>
35 
36 
37 #include <time.h>
38 #include <ctype.h>
39 
40 
41 
42 static const uint8_t daysInMonth[12]= {
43  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
44 };
45 
46 
47 
48 
49 GWEN_DATE *GWEN_Date_fromGregorian(int y, int m, int d)
50 {
51  GWEN_DATE *gd;
52 
53  if (m<1 || m>12 || d<1 || d>31) {
54  DBG_ERROR(GWEN_LOGDOMAIN, "Bad date values (erroneous year=%d, month=%d, day=%d)", y, m, d);
55  return NULL;
56  }
57 
59  gd->year=y;
60  gd->month=m;
61  gd->day=d;
62  gd->julian=(1461*(y+4800+(m-14)/12))/4+
63  (367*(m-2-12*((m-14)/12)))/12-
64  (3*((y+4900+(m-14)/12)/100))/4+
65  d-32075;
66 
67  snprintf(gd->asString, sizeof(gd->asString)-1,
68  "%04d%02d%02d",
69  gd->year, gd->month, gd->day);
70  gd->asString[sizeof(gd->asString)-1]=0;
71 
72  return gd;
73 }
74 
75 
76 
77 void GWEN_Date_setJulian(GWEN_DATE *gd, int julian)
78 {
79  int l, n, i, j, len;
80 
81  l=julian+68569;
82  n=(4*l)/146097;
83  l=l-(146097*n+3)/4;
84  i=(4000*(l+1))/1461001;
85  l=l-(1461*i)/4+31;
86  j=(80*l)/2447;
87  gd->day=l-(2447*j)/80;
88  l=j/11;
89  gd->month=j+2-(12*l);
90  gd->year=100*(n-49)+i+l;
91  gd->julian=julian;
92 
93  len=snprintf(gd->asString, sizeof(gd->asString)-1,
94  "%04d%02d%02d",
95  gd->year, gd->month, gd->day);
96  gd->asString[sizeof(gd->asString)-1]=0;
97  if ((int)(sizeof(gd->asString)-1) < len)
98  DBG_ERROR(GWEN_LOGDOMAIN, "truncated date string [%s]", gd->asString);
99 }
100 
101 
102 
103 void GWEN_Date_AddDays(GWEN_DATE *gd, int days)
104 {
105  GWEN_Date_setJulian(gd, gd->julian+days);
106 }
107 
108 
109 
110 void GWEN_Date_SubDays(GWEN_DATE *gd, int days)
111 {
112  GWEN_Date_setJulian(gd, gd->julian-days);
113 }
114 
115 
116 
118 {
119  GWEN_DATE *gd;
120 
122  GWEN_Date_setJulian(gd, julian);
123  return gd;
124 }
125 
126 
127 
129 {
130  struct tm *ltm;
131 
132  ltm=localtime(&t);
133  if (ltm) {
134  GWEN_DATE *gd;
135 
136  gd=GWEN_Date_fromGregorian(ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday);
137  return gd;
138  }
139 
140  return NULL;
141 }
142 
143 
144 
146 {
147  struct tm ti;
148  struct tm *tp;
149  time_t tt;
150 
151  tt=time(0);
152  tp=localtime(&tt);
153  assert(tp);
154  memmove(&ti, tp, sizeof(ti));
155  ti.tm_sec=0;
156  ti.tm_min=0;
157  ti.tm_hour=0;
158  ti.tm_year=gd->year-1900;
159  ti.tm_mon=gd->month-1;
160  ti.tm_mday=gd->day;
161  ti.tm_yday=0;
162  ti.tm_wday=0;
163  tt=mktime(&ti);
164  assert(tt!=(time_t)-1);
165  return tt;
166 }
167 
168 
169 
171 {
172  struct tm *ltm;
173 
174  ltm=gmtime(&t);
175  if (ltm) {
176  GWEN_DATE *gd;
177 
178  gd=GWEN_Date_fromGregorian(ltm->tm_year+1900, ltm->tm_mon+1, ltm->tm_mday);
179  return gd;
180  }
181 
182  return NULL;
183 }
184 
185 
186 
187 
189 {
190  time_t l;
191 
192  time(&l);
193  return GWEN_Date_fromLocalTime(l);
194 }
195 
196 
197 
199 {
200  GWEN_DATE *gd;
201 
202  assert(ogd);
203 
205 #if 0
206  gd->year=ogd->year;
207  gd->month=ogd->month;
208  gd->day=ogd->day;
209  gd->julian=ogd->julian;
210  memmove(gd->asString, ogd->asString, sizeof(gd->asString));
211 #else
212  memmove(gd, ogd, sizeof(GWEN_DATE));
213 #endif
214  return gd;
215 }
216 
217 
218 
220 {
221  int y, m, d;
222 
223  if (3==sscanf(s, "%04d%02d%02d", &y, &m, &d)) {
224  GWEN_DATE *result = GWEN_Date_fromGregorian(y, m, d);
225  if (!result)
226  DBG_INFO(GWEN_LOGDOMAIN, "Bad date string [%s]", s);
227  return result;
228  }
229  else {
230  DBG_INFO(GWEN_LOGDOMAIN, "Bad date string [%s]", s);
231  return NULL;
232  }
233 }
234 
235 
236 
238 {
239  if (gd) {
240  GWEN_FREE_OBJECT(gd);
241  }
242 }
243 
244 
245 
247 {
248  return ((y%4==0) && (y%100!=0)) || (y%400==0);
249 }
250 
251 
252 
253 
255 {
256  assert(gd);
257  if (gd->month==2 &&
258  ((((gd->year%4)==0) && ((gd->year)%100!=0)) || ((gd->year)%400==0)))
259  /* February in a leap year */
260  return 29;
261  else
262  return daysInMonth[gd->month-1];
263 }
264 
265 
266 
268 {
269  GWEN_DATE *gd11;
270  int result;
271 
272  assert(gd);
273 
274  gd11=GWEN_Date_fromGregorian(gd->year, 1, 1);
275  result=(gd->julian)-(gd11->julian);
276  GWEN_Date_free(gd11);
277 
278  return result;
279 }
280 
281 
282 
284 {
285  assert(gd);
286  return gd->year;
287 }
288 
289 
290 
292 {
293  assert(gd);
294  return gd->month;
295 }
296 
297 
298 
300 {
301  assert(gd);
302  return gd->day;
303 }
304 
305 
306 
308 {
309  assert(gd);
310  return gd->julian;
311 }
312 
313 
314 
316 {
317  assert(gd);
318  return (gd->julian+1)%7; /* 0=Sunday */
319 }
320 
321 
322 
323 const char *GWEN_Date_GetString(const GWEN_DATE *gd)
324 {
325  assert(gd);
326  return gd->asString;
327 }
328 
329 
330 
331 int GWEN_Date_Compare(const GWEN_DATE *gd1, const GWEN_DATE *gd0)
332 {
333  if (gd0 && gd1) {
334  if (gd1->julian==gd0->julian)
335  return 0;
336  else if (gd1->julian>gd0->julian)
337  return 1;
338  else
339  return -1;
340  }
341  else if (gd0)
342  return 1;
343  else if (gd1)
344  return -1;
345  else
346  return 0;
347 }
348 
349 
350 
351 int GWEN_Date_Diff(const GWEN_DATE *gd1, const GWEN_DATE *gd0)
352 {
353  assert(gd1);
354  assert(gd0);
355 
356  return gd1->julian-gd0->julian;
357 }
358 
359 
360 
362 {
363  GWEN_BUFFER *tbuf;
364  GWEN_DATE *gd;
365 
366  tbuf=GWEN_Buffer_new(0, 32, 0, 1);
367  GWEN_Time_toString(ti, "YYYYMMDD", tbuf);
369  GWEN_Buffer_free(tbuf);
370 
371  return gd;
372 }
373 
374 
375 
376 
377 GWEN_DATE *GWEN_Date_fromStringWithTemplate(const char *s, const char *tmpl)
378 {
379  int year, month, day;
380  const char *p;
381  const char *t;
382  GWEN_DATE *gwt;
383 
384  assert(s);
385  assert(tmpl);
386  year=month=day=0;
387 
388  p=s;
389  t=tmpl;
390  while (*t && *p) {
391  int i;
392 
393  if (*t=='*') {
394  t++;
395  if (!*t) {
396  DBG_ERROR(GWEN_LOGDOMAIN, "Bad pattern: Must not end with \"*\"");
397  return 0;
398  }
399  i=0;
400  while (*p) {
401  if (!isdigit((int)*p))
402  break;
403  if (*p==*t)
404  break;
405  i*=10;
406  i+=(*p)-'0';
407  p++;
408  } /* while */
409  }
410  else {
411  if (isdigit((int)*p))
412  i=(*p)-'0';
413  else
414  i=-1;
415  p++;
416  }
417 
418  if (i==-1 && strchr("YMD", *t)!=NULL) {
420  "No more digits at [%s], continuing", t);
421  p--;
422  }
423  else {
424  switch (*t) {
425  case 'Y':
426  if (i==-1) {
427  DBG_INFO(GWEN_LOGDOMAIN, "here");
428  return 0;
429  }
430  year*=10;
431  year+=i;
432  break;
433  case 'M':
434  if (i==-1) {
435  DBG_INFO(GWEN_LOGDOMAIN, "here");
436  return 0;
437  }
438  month*=10;
439  month+=i;
440  break;
441  case 'D':
442  if (i==-1) {
443  DBG_INFO(GWEN_LOGDOMAIN, "here");
444  return 0;
445  }
446  day*=10;
447  day+=i;
448  break;
449  default:
451  "Unknown character in template, will skip in both strings");
452  break;
453  }
454  }
455  t++;
456  } /* while */
457 
458  if (year<100)
459  year+=2000;
460 
462  "Got this date/time: %04d/%02d/%02d",
463  year, month, day);
464 
465  /* get time in local time */
466  gwt=GWEN_Date_fromGregorian(year, month, day);
467  if (!gwt) {
468  DBG_ERROR(GWEN_LOGDOMAIN, "Bad date string [%s]", s);
469  return 0;
470  }
471  return gwt;
472 }
473 
474 
475 
476 
477 
478 GWEN_LIST_FUNCTIONS(GWEN_DATE_TMPLCHAR, GWEN_DateTmplChar)
479 
480 
481 GWEN_DATE_TMPLCHAR *GWEN_DateTmplChar_new(char c)
482 {
483  GWEN_DATE_TMPLCHAR *e;
484 
485  GWEN_NEW_OBJECT(GWEN_DATE_TMPLCHAR, e);
486  GWEN_LIST_INIT(GWEN_DATE_TMPLCHAR, e);
487  e->character=c;
488  switch (c) {
489  case 'Y':
490  e->maxCount=4;
491  break;
492  case 'M':
493  e->maxCount=2;
494  break;
495  case 'D':
496  e->maxCount=2;
497  break;
498  case 'W':
499  e->maxCount=1;
500  break;
501  case 'w':
502  default:
503  e->maxCount=GWEN_DATE_TMPL_MAX_COUNT;
504  break;
505  }
506 
507  return e;
508 }
509 
510 
511 
512 void GWEN_DateTmplChar_free(GWEN_DATE_TMPLCHAR *e)
513 {
514  if (e) {
515  free(e->content);
516  GWEN_LIST_FINI(GWEN_DATE_TMPLCHAR, e);
517  GWEN_FREE_OBJECT(e);
518  }
519 }
520 
521 
522 
523 GWEN_DATE_TMPLCHAR *GWEN_Date__findTmplChar(GWEN_DATE_TMPLCHAR_LIST *ll, char c)
524 {
525  GWEN_DATE_TMPLCHAR *e;
526 
527  e=GWEN_DateTmplChar_List_First(ll);
528  while (e) {
529  if (e->character==c)
530  break;
531  e=GWEN_DateTmplChar_List_Next(e);
532  }
533 
534  return e;
535 }
536 
537 
538 
539 
540 void GWEN_Date__sampleTmplChars(GWEN_UNUSED const GWEN_DATE *t, const char *tmpl,
542  GWEN_DATE_TMPLCHAR_LIST *ll)
543 {
544  const char *s;
545 
546  s=tmpl;
547  while (*s) {
548  if (strchr("YMDWw", *s)) {
549  GWEN_DATE_TMPLCHAR *e;
550 
551  e=GWEN_Date__findTmplChar(ll, *s);
552  if (!e) {
553  /* new entry, create it */
554  e=GWEN_DateTmplChar_new(*s);
555  GWEN_DateTmplChar_List_Add(e, ll);
556  }
557  assert(e);
558  e->count++;
559  }
560  else {
561  DBG_DEBUG(GWEN_LOGDOMAIN, "Unknown character in template (%02x)",
562  *s);
563  }
564  s++;
565  }
566 }
567 
568 
569 
570 void GWEN_Date__fillTmplChars(const GWEN_DATE *t, GWEN_DATE_TMPLCHAR_LIST *ll)
571 {
572  GWEN_DATE_TMPLCHAR *e;
573 
574 
575  e=GWEN_DateTmplChar_List_First(ll);
576  while (e) {
577  int v;
578 
579  if (e->character=='w') {
580  const char *s=NULL;
581 
582  switch (GWEN_Date_WeekDay(t)) {
583  case 0:
584  s=I18N("Sunday");
585  break;
586  case 1:
587  s=I18N("Monday");
588  break;
589  case 2:
590  s=I18N("Tuesday");
591  break;
592  case 3:
593  s=I18N("Wednesday");
594  break;
595  case 4:
596  s=I18N("Thursday");
597  break;
598  case 5:
599  s=I18N("Friday");
600  break;
601  case 6:
602  s=I18N("Saturday");
603  break;
604  default:
605  DBG_DEBUG(GWEN_LOGDOMAIN, "Invalid week day (%2d)", GWEN_Date_WeekDay(t));
606  s=NULL;
607  break;
608  }
609  assert(s);
610  e->content=strdup(s);
611  e->nextChar=0;
612  }
613  else {
614  char buffer[32];
615  int clen;
616 
617  switch (e->character) {
618  case 'Y':
619  v=t->year;
620  break;
621  case 'M':
622  v=t->month;
623  break;
624  case 'D':
625  v=t->day;
626  break;
627  case 'W':
628  v=GWEN_Date_WeekDay(t);
629  break;
630  default:
631  v=-1;
632  break;
633  }
634  if (v==-1) {
635  DBG_ERROR(GWEN_LOGDOMAIN, "Unknown character, should not happen here");
636  abort();
637  }
638  buffer[0]=0;
639  snprintf(buffer, sizeof(buffer)-1, "%0*d", e->maxCount, v);
640  buffer[sizeof(buffer)-1]=0;
641  e->content=strdup(buffer);
642  /* adjust counter if there are more than maxCount template chars */
643  clen=strlen(e->content);
644  if (e->count>clen)
645  e->count=clen;
646  e->nextChar=clen-(e->count);
647  }
648 
649  e=GWEN_DateTmplChar_List_Next(e);
650  }
651 }
652 
653 
654 
655 
656 int GWEN_Date_toStringWithTemplate(const GWEN_DATE *t, const char *tmpl, GWEN_BUFFER *buf)
657 {
658  GWEN_DATE_TMPLCHAR_LIST *ll;
659  const char *s;
660 
661  ll=GWEN_DateTmplChar_List_new();
662  GWEN_Date__sampleTmplChars(t, tmpl, buf, ll);
664 
665  s=tmpl;
666  while (*s) {
667  if (strchr("YMDWw", *s)) {
668  GWEN_DATE_TMPLCHAR *e;
669  char c;
670 
671  e=GWEN_Date__findTmplChar(ll, *s);
672  assert(e);
673  assert(e->content);
674  if (s[1]=='*') {
675  /* append full string */
676  GWEN_Buffer_AppendString(buf, e->content);
677  /* skip asterisk */
678  s++;
679  }
680  else {
681  c=e->content[e->nextChar];
682  if (c!=0) {
683  GWEN_Buffer_AppendByte(buf, c);
684  e->nextChar++;
685  }
686  }
687  }
688  else
689  GWEN_Buffer_AppendByte(buf, *s);
690  s++;
691  }
692  GWEN_DateTmplChar_List_free(ll);
693  return 0;
694 }
695 
696 
697 
699 {
700  const char *s;
701 
702  assert(dt);
703  s=GWEN_Date_GetString(dt);
705  return 0;
706 }
707 
708 
709 
711 {
712  const char *s;
713 
714  s=GWEN_DB_GetCharValue(db, "dateString", 0, NULL);
715  if (s && *s) {
716  GWEN_DATE *dt;
717 
718  dt=GWEN_Date_fromString(s);
719  if (dt==NULL) {
720  DBG_INFO(GWEN_LOGDOMAIN, "Invalid date [%s]", s);
721  return NULL;
722  }
723 
724  return dt;
725  }
726  else {
727  DBG_VERBOUS(GWEN_LOGDOMAIN, "no or empty date");
728  return NULL;
729  }
730 }
731 
732 
733 
735 {
737 }
738 
739 
740 
742 {
743  int day;
744 
745  switch (GWEN_Date_GetMonth(dt)) {
746  case 1:
747  case 3:
748  case 5:
749  case 7:
750  case 8:
751  case 10:
752  case 12:
753  day=31;
754  break;
755  case 2:
757  day=29;
758  else
759  day=28;
760  break;
761 
762  case 4:
763  case 6:
764  case 9:
765  case 11:
766  day=30;
767  break;
768 
769  default:
770  DBG_ERROR(GWEN_LOGDOMAIN, "Invalid month (%d)", GWEN_Date_GetMonth(dt));
771  abort();
772  break;
773  }
775 }
776 
777 
778 
780 {
781  int m;
782 
783  m=GWEN_Date_GetMonth(dt)>>2;
784  switch (m) {
785  case 0:
786  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 1, 1);
787  case 1:
788  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 4, 1);
789  case 2:
790  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 7, 1);
791  case 3:
792  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 10, 1);
793  default:
794  DBG_ERROR(GWEN_LOGDOMAIN, "Invalid quarter (%d)", m);
795  break;
796  }
797 
798  return NULL;
799 }
800 
801 
802 
804 {
805  int m;
806 
807  m=GWEN_Date_GetMonth(dt)>>2;
808  switch (m) {
809  case 0:
810  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 3, 31);
811  case 1:
812  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 6, 30);
813  case 2:
814  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 9, 30);
815  case 3:
816  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 12, 31);
817  default:
818  DBG_ERROR(GWEN_LOGDOMAIN, "Invalid quarter (%d)", m);
819  break;
820  }
821 
822  return NULL;
823 }
824 
825 
826 
828 {
829  if (GWEN_Date_GetMonth(dt)<7)
830  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 1, 1);
831  else
832  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 7, 1);
833 }
834 
835 
836 
838 {
839  if (GWEN_Date_GetMonth(dt)<7)
840  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 6, 30);
841  else
842  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 12, 31);
843 }
844 
845 
846 
848 {
849  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 1, 1);
850 }
851 
852 
853 
855 {
856  return GWEN_Date_fromGregorian(GWEN_Date_GetYear(dt), 12, 31);
857 }
858 
859 
860 
862 {
863  GWEN_DATE *tmpDate;
864  GWEN_DATE *result;
865  int j;
866 
868  j=GWEN_Date_GetJulian(tmpDate)-1;
869  GWEN_Date_free(tmpDate);
870  tmpDate=GWEN_Date_fromJulian(j);
871  result=GWEN_Date_fromGregorian(GWEN_Date_GetYear(tmpDate), GWEN_Date_GetMonth(tmpDate), 1);
872  GWEN_Date_free(tmpDate);
873  return result;
874 }
875 
876 
877 
879 {
880  GWEN_DATE *tmpDate;
881  int j;
882 
884  j=GWEN_Date_GetJulian(tmpDate)-1;
885  GWEN_Date_free(tmpDate);
886  return GWEN_Date_fromJulian(j);
887 }
888 
889 
890 
892 {
893  GWEN_DATE *tmpDate;
894  GWEN_DATE *result;
895 
897  result=GWEN_Date_GetThisQuarterYearStart(tmpDate);
898  GWEN_Date_free(tmpDate);
899  return result;
900 }
901 
902 
903 
905 {
906  GWEN_DATE *tmpDate;
907  int j;
908 
910  j=GWEN_Date_GetJulian(tmpDate)-1;
911  GWEN_Date_free(tmpDate);
912  return GWEN_Date_fromJulian(j);
913 }
914 
915 
916 
918 {
919  GWEN_DATE *tmpDate;
920  GWEN_DATE *result;
921 
922  tmpDate=GWEN_Date_GetLastHalfYearEnd(dt);
923  result=GWEN_Date_GetThisHalfYearStart(tmpDate);
924  GWEN_Date_free(tmpDate);
925  return result;
926 }
927 
928 
929 
931 {
932  GWEN_DATE *tmpDate;
933  int j;
934 
935  tmpDate=GWEN_Date_GetThisHalfYearStart(dt);
936  j=GWEN_Date_GetJulian(tmpDate)-1;
937  GWEN_Date_free(tmpDate);
938  return GWEN_Date_fromJulian(j);
939 }
940 
941 
942 
944 {
945  GWEN_DATE *tmpDate;
946  GWEN_DATE *result;
947 
948  tmpDate=GWEN_Date_GetLastYearEnd(dt);
949  result=GWEN_Date_GetThisYearStart(tmpDate);
950  GWEN_Date_free(tmpDate);
951  return result;
952 }
953 
954 
955 
957 {
958  GWEN_DATE *tmpDate;
959  int j;
960 
961  tmpDate=GWEN_Date_GetThisYearStart(dt);
962  j=GWEN_Date_GetJulian(tmpDate)-1;
963  GWEN_Date_free(tmpDate);
964  return GWEN_Date_fromJulian(j);
965 }
966 
967 
968 
969 
970 
971 
972 
973 
GWEN_DATE * GWEN_Date_fromDb(GWEN_DB_NODE *db)
Definition: gwendate.c:710
struct GWEN_TIME GWEN_TIME
Definition: gwentime.h:43
void GWEN_Date_SubDays(GWEN_DATE *gd, int days)
Definition: gwendate.c:110
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
#define I18N(m)
Definition: error.c:42
GWEN_DATE * GWEN_Date_fromString(const char *s)
Definition: gwendate.c:219
GWEN_DATE * GWEN_Date_dup(const GWEN_DATE *ogd)
Definition: gwendate.c:198
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
GWEN_DATE * GWEN_Date_GetLastHalfYearStart(const GWEN_DATE *dt)
Definition: gwendate.c:917
GWEN_DATE * GWEN_Date_fromStringWithTemplate(const char *s, const char *tmpl)
Definition: gwendate.c:377
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
GWEN_DATE_TMPLCHAR * GWEN_DateTmplChar_new(char c)
Definition: gwendate.c:481
GWEN_DATE * GWEN_Date_GetLastMonthStart(const GWEN_DATE *dt)
Definition: gwendate.c:861
static const uint8_t daysInMonth[12]
Definition: gwendate.c:42
int GWEN_Date_WeekDay(const GWEN_DATE *gd)
Definition: gwendate.c:315
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
time_t GWEN_Date_toLocalTime(const GWEN_DATE *gd)
Definition: gwendate.c:145
GWEN_DATE * GWEN_Date_GetThisMonthEnd(const GWEN_DATE *dt)
Definition: gwendate.c:741
#define DBG_VERBOUS(dbg_logger, format, args...)
Definition: debug.h:217
int GWEN_Date_toStringWithTemplate(const GWEN_DATE *t, const char *tmpl, GWEN_BUFFER *buf)
Definition: gwendate.c:656
void GWEN_DateTmplChar_free(GWEN_DATE_TMPLCHAR *e)
Definition: gwendate.c:512
GWEN_DATE * GWEN_Date_CurrentDate(void)
Definition: gwendate.c:188
int GWEN_Date_toDb(const GWEN_DATE *dt, GWEN_DB_NODE *db)
Definition: gwendate.c:698
GWEN_DATE * GWEN_Date_fromTime(const GWEN_TIME *ti)
Definition: gwendate.c:361
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
void GWEN_Date__fillTmplChars(const GWEN_DATE *t, GWEN_DATE_TMPLCHAR_LIST *ll)
Definition: gwendate.c:570
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
GWENHYWFAR_API int GWEN_Time_toString(const GWEN_TIME *t, const char *tmpl, GWEN_BUFFER *buf)
Definition: gwentime_all.c:830
int GWEN_Date_DaysInYear(const GWEN_DATE *gd)
Definition: gwendate.c:267
GWEN_DATE * GWEN_Date_GetThisYearEnd(const GWEN_DATE *dt)
Definition: gwendate.c:854
#define DBG_DEBUG(dbg_logger, format, args...)
Definition: debug.h:209
GWEN_DATE * GWEN_Date_GetLastHalfYearEnd(const GWEN_DATE *dt)
Definition: gwendate.c:930
void GWEN_Date_free(GWEN_DATE *gd)
Definition: gwendate.c:237
GWEN_DATE * GWEN_Date_GetThisMonthStart(const GWEN_DATE *dt)
Definition: gwendate.c:734
void GWEN_Date__sampleTmplChars(GWEN_UNUSED const GWEN_DATE *t, const char *tmpl, GWEN_UNUSED GWEN_BUFFER *buf, GWEN_DATE_TMPLCHAR_LIST *ll)
Definition: gwendate.c:540
GWEN_DATE * GWEN_Date_GetLastMonthEnd(const GWEN_DATE *dt)
Definition: gwendate.c:878
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
Definition: buffer.c:394
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:969
int GWEN_Date_DaysInMonth(const GWEN_DATE *gd)
Definition: gwendate.c:254
GWEN_DATE * GWEN_Date_fromGregorian(int y, int m, int d)
Definition: gwendate.c:49
int GWEN_Date_GetMonth(const GWEN_DATE *gd)
Definition: gwendate.c:291
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
GWEN_DATE * GWEN_Date_GetThisYearStart(const GWEN_DATE *dt)
Definition: gwendate.c:847
void GWEN_Date_AddDays(GWEN_DATE *gd, int days)
Definition: gwendate.c:103
GWEN_DATE * GWEN_Date_GetThisHalfYearEnd(const GWEN_DATE *dt)
Definition: gwendate.c:837
const char * GWEN_Date_GetString(const GWEN_DATE *gd)
Definition: gwendate.c:323
GWEN_DATE * GWEN_Date_fromLocalTime(time_t t)
Definition: gwendate.c:128
GWEN_DATE * GWEN_Date_GetThisQuarterYearStart(const GWEN_DATE *dt)
Definition: gwendate.c:779
GWEN_DATE * GWEN_Date_GetLastYearEnd(const GWEN_DATE *dt)
Definition: gwendate.c:956
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWEN_DATE * GWEN_Date_GetLastYearStart(const GWEN_DATE *dt)
Definition: gwendate.c:943
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:995
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:178
int GWEN_Date_GetJulian(const GWEN_DATE *gd)
Definition: gwendate.c:307
#define GWEN_LIST_INIT(t, element)
Definition: list1.h:465
GWEN_DATE * GWEN_Date_fromGmTime(time_t t)
Definition: gwendate.c:170
GWEN_DATE * GWEN_Date_GetLastQuarterYearEnd(const GWEN_DATE *dt)
Definition: gwendate.c:904
int GWEN_Date_IsLeapYear(int y)
Definition: gwendate.c:246
#define GWEN_LIST_FUNCTIONS(t, pr)
Definition: list1.h:366
GWEN_DATE * GWEN_Date_GetThisQuarterYearEnd(const GWEN_DATE *dt)
Definition: gwendate.c:803
GWEN_DATE * GWEN_Date_GetThisHalfYearStart(const GWEN_DATE *dt)
Definition: gwendate.c:827
int GWEN_Date_GetDay(const GWEN_DATE *gd)
Definition: gwendate.c:299
GWEN_DATE * GWEN_Date_fromJulian(int julian)
Definition: gwendate.c:117
int GWEN_Date_GetYear(const GWEN_DATE *gd)
Definition: gwendate.c:283
GWEN_DATE_TMPLCHAR * GWEN_Date__findTmplChar(GWEN_DATE_TMPLCHAR_LIST *ll, char c)
Definition: gwendate.c:523
int GWEN_Date_Diff(const GWEN_DATE *gd1, const GWEN_DATE *gd0)
Definition: gwendate.c:351
#define GWEN_LIST_FINI(t, element)
Definition: list1.h:474
void GWEN_Date_setJulian(GWEN_DATE *gd, int julian)
Definition: gwendate.c:77
int GWEN_Date_Compare(const GWEN_DATE *gd1, const GWEN_DATE *gd0)
Definition: gwendate.c:331
GWEN_DATE * GWEN_Date_GetLastQuarterYearStart(const GWEN_DATE *dt)
Definition: gwendate.c:891
#define GWEN_UNUSED
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989
struct GWEN_DATE GWEN_DATE
Definition: gwendate.h:34