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