QOF  0.8.7
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 */
gshort qd_yday
Definition: qofdate.h:189
gint64 qd_year
Extended version to cope with full range of dates.
Definition: qofdate.h:181
gboolean qof_date_format_set_current(QofDateFormat df)
Selects one registered date format as the current default.
Definition: qofdate.c:294
gboolean qd_valid
If the QofDate is valid or merely initialised.
Definition: qofdate.h:217
gboolean qof_date_adddays(QofDate *qd, gint days)
Add a number of days to a QofDate and normalise.
Definition: qofdate.c:1000
void qof_date_free(QofDate *date)
Definition: qofdate.c:642
QofDate * qof_date_from_qtime(const QofTime *qt)
Definition: qofdate.c:884
gboolean qof_date_format_set_name(const gchar *name, QofDateFormat format)
Set a shorthand name for a custom date format.
Definition: qofdate.c:269
QofDateFormat qof_date_format_from_name(const gchar *name)
Returns the default date format for a known shorthand name.
Definition: qofdate.c:385
const gchar * qd_zone
Calculated value based on struct tm.tm_zone.
Definition: qofdate.h:208
QofDate * qof_date_get_current(void)
Definition: qofdate.c:616
guint8 qof_date_get_mday(gint month, gint64 year)
Definition: qofdate.c:183
void qof_date_close(void)
close down the QofDate tables
Definition: qofdate.c:156
gchar * qof_date_print(const QofDate *date, QofDateFormat df)
Convert a QofDate to a timestamp according to the specified date format.
Definition: qofdate.c:581
gboolean qof_date_format_set_date_separator(const gchar sep, QofDateFormat df)
Set a locale-specific separator.
Definition: qofdate.c:340
QofDateFormat qof_date_format_get_current(void)
returns the current date format.
Definition: qofdate.c:288
gshort qd_is_dst
Definition: qofdate.h:193
struct QofDate_s QofDate
Full range replacement for struct tm.
const gchar * qof_date_format_get_format(QofDateFormat df)
Retrieve the strftime format string for a registered date format.
Definition: qofdate.c:310
QofTime * qof_date_to_qtime(const QofDate *qd)
Definition: qofdate.c:926
Full range replacement for struct tm.
Definition: qofdate.h:138
gchar qof_date_format_get_date_separator(QofDateFormat df)
Return the field separator for the current date format.
Definition: qofdate.c:325
void qof_date_init(void)
initialise the QofDate tables
Definition: qofdate.c:67
QofDate * qof_date_parse(const gchar *str, QofDateFormat df)
Convert a timestamp to a QofTime.
Definition: qofdate.c:557
glong qd_hour
Signed replacement of struct tm.tm_hour.
Definition: qofdate.h:157
glong qd_min
Signed replacement of struct tm.tm_min.
Definition: qofdate.h:150
glong qd_mon
Signed replacement of struct tm.tm_mon.
Definition: qofdate.h:171
guint16 qof_date_get_yday(gint mday, gint month, gint64 year)
Definition: qofdate.c:167
gboolean qof_date_to_struct_tm(const QofDate *qt, struct tm *stm, glong *nanosecs)
Convert a QofDate to a struct tm.
Definition: qofdate.c:736
QofDate * qof_date_new_dmy(gint day, gint month, gint64 year)
Definition: qofdate.c:628
gint64 qd_sec
Definition: qofdate.h:143
gint QofDateFormat
Definition: qofdate.h:335
glong qd_gmt_off
Calculated value based on struct tm.tm_gmtoff.
Definition: qofdate.h:201
gboolean qof_date_equal(const QofDate *d1, const QofDate *d2)
Definition: qofdate.c:663
64bit UTC Time handling routines
gboolean qof_date_addmonths(QofDate *qd, gint months, gboolean track_last_day)
Definition: qofdate.c:1009
gboolean qof_date_to_gdate(const QofDate *qd, GDate *gd)
Convert a QofDate to a GDate.
Definition: qofdate.c:764
const gchar * qof_date_format_to_name(QofDateFormat format)
Retrieve the shorthand name for the selected date format.
Definition: qofdate.c:254
glong qd_nanosecs
Definition: qofdate.h:141
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
Definition: qoftime.h:112
QofDate * qof_date_new(void)
Definition: qofdate.c:607
QofTime * qof_date_time_difference(const QofDate *date1, const QofDate *date2)
Definition: qofdate.c:959
gint qof_date_compare(const QofDate *d1, const QofDate *d2)
Definition: qofdate.c:671
gshort qd_wday
Definition: qofdate.h:185
gboolean qof_date_is_last_mday(const QofDate *qd)
Definition: qofdate.c:193
glong qd_mday
Signed replacement of struct tm.tm_mday.
Definition: qofdate.h:164
QofDate * qof_date_from_gdate(const GDate *gd)
Create a QofDate from a GDate.
Definition: qofdate.c:784
gboolean qof_date_format_add(const gchar *str, QofDateFormat *identifier)
Add a specific strftime compatible string as a new QofDateFormat.
Definition: qofdate.c:202
gboolean qof_date_valid(QofDate *date)
Validate a QofDate.
Definition: qofdate.c:650
QofDate * qof_date_from_struct_tm(const struct tm *stm)
Convert a struct tm to a QofDate.
Definition: qofdate.c:713