QOF  0.7.5
qofdate.h
Go to the documentation of this file.
1 /********************************************************************
2  * qofdate.h - QofDate, 64bit UTC date handling.
3  * Rewritten from scratch for QOF 0.7.0
4  *
5  * Fri May 5 15:05:24 2006
6  * Copyright (C) 2006 Free Software Foundation, Inc.
7  ********************************************************************/
8 /*
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
22  */
75 #ifndef QOFDATE_H
76 #define QOFDATE_H
77 
78 #include "qoftime.h"
79 
87 #define MAX_DATE_LENGTH 41
88 
92 #define MAX_DATE_BUFFER 256
93 
94 #define SECS_PER_DAY 86400
95 
96 #define SECS_PER_HOUR 3600
97 
98 #define QOF_MOD_DATE "qof-dates"
99 
138 typedef struct QofDate_s
139 {
141  glong qd_nanosecs;
143  gint64 qd_sec;
150  glong qd_min;
157  glong qd_hour;
164  glong qd_mday;
171  glong qd_mon;
181  gint64 qd_year;
185  gshort qd_wday;
189  gshort qd_yday;
193  gshort qd_is_dst;
201  glong qd_gmt_off;
208  const gchar *qd_zone;
217  gboolean qd_valid;
218 } QofDate;
219 
222 # define qof_date_isleap(year) \
223  ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
224 
226 void qof_date_init (void);
227 
229 void qof_date_close (void);
230 
244 #define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
245 
253 #define QOF_DATE_FORMAT_US 1
254 
258 #define QOF_DATE_FORMAT_UK 2
259 
263 #define QOF_DATE_FORMAT_CE 3
264 
268 #define QOF_DATE_FORMAT_ISO 4
269 
277 #define QOF_DATE_FORMAT_UTC 5
278 
287 #define QOF_DATE_FORMAT_ISO8601 6
288 
303 #define QOF_DATE_FORMAT_LOCALE 7
304 
319 #define QOF_DATE_FORMAT_CUSTOM 8
320 
322 #define DATE_FORMAT_LAST QOF_DATE_FORMAT_CUSTOM
323 
327 #define QOF_HOUR_TO_SEC(x) (x * SECS_PER_HOUR)
328 
329 #define QOF_MIN_TO_SEC(x) (x * 60)
330 
331 #define QOF_DAYS_TO_SEC(x) (x * SECS_PER_DAY)
332 
335 typedef gint QofDateFormat;
336 
358 gboolean
359 qof_date_format_add (const gchar * str, QofDateFormat *identifier);
360 
371 const gchar *
373 
385 qof_date_format_from_name (const gchar * name);
386 
400 gboolean
401 qof_date_format_set_name (const gchar * name, QofDateFormat format);
402 
406 
413 gboolean
415 
423 const gchar *
425 
436 gchar
438 
447 gboolean
455 QofDate *
456 qof_date_new (void);
457 
459 QofDate *
460 qof_date_get_current (void);
461 
463 QofDate *
464 qof_date_new_dmy (gint day, gint month, gint64 year);
465 
467 void
468 qof_date_free (QofDate * date);
469 
471 QofTime*
472 qof_date_time_difference (const QofDate * date1, const QofDate * date2);
473 
481 gboolean
482 qof_date_is_last_mday (const QofDate *qd);
483 
499 gboolean
500 qof_date_addmonths (QofDate * qd, gint months,
501  gboolean track_last_day);
502 
504 gboolean
505 qof_date_equal (const QofDate *d1, const QofDate *d2);
506 
508 gint
509 qof_date_compare (const QofDate * d1, const QofDate * d2);
510 
532 gboolean
533 qof_date_valid (QofDate *date);
534 
544 guint16
545 qof_date_get_yday (gint mday, gint month, gint64 year);
546 
555 guint8
556 qof_date_get_mday (gint month, gint64 year);
557 
564 QofDate *
565 qof_date_from_qtime (const QofTime *qt);
566 
568 QofTime *
569 qof_date_to_qtime (const QofDate *qd);
570 
576 QofDate *
577 qof_date_from_struct_tm (const struct tm *stm);
578 
593 gboolean
594 qof_date_to_struct_tm (const QofDate * qt, struct tm *stm, glong * nanosecs);
595 
605 gboolean
606 qof_date_to_gdate (const QofDate *qd, GDate *gd);
607 
617 QofDate *
618 qof_date_from_gdate (const GDate *gd);
619 
635 gboolean
636 qof_date_adddays (QofDate * qd, gint days);
637 
638 gboolean
639 qof_date_set_day_end (QofDate * qd);
640 
641 gboolean
642 qof_date_set_day_start (QofDate * qd);
643 
644 gboolean
645 qof_date_set_day_middle (QofDate * qd);
646 
712 gchar *
713 qof_date_print (const QofDate * date, QofDateFormat df);
714 
725 QofDate *
726 qof_date_parse (const gchar * str, QofDateFormat df);
727 
732 #endif /* QOFDATE_H */