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