QOF: qofdate.h Source File

QOF 0.7.5

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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 *
372 qof_date_format_to_name (QofDateFormat format);
373
384 QofDateFormat
385 qof_date_format_from_name (const gchar * name);
386
400 gboolean
401 qof_date_format_set_name (const gchar * name, QofDateFormat format);
402
404 QofDateFormat
405 qof_date_format_get_current (void);
406
413 gboolean
414 qof_date_format_set_current (QofDateFormat df);
415
423 const gchar *
424 qof_date_format_get_format (QofDateFormat df);
425
436 gchar
437 qof_date_format_get_date_separator (QofDateFormat df);
438
447 gboolean
448 qof_date_format_set_date_separator (const gchar sep, QofDateFormat df);
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 */
QofDate_s::qd_yday
gshort qd_yday
Definition: qofdate.h:189
QofDate_s::qd_year
gint64 qd_year
Extended version to cope with full range of dates.
Definition: qofdate.h:181
qof_date_format_set_current
gboolean qof_date_format_set_current(QofDateFormat df)
Selects one registered date format as the current default.
Definition: qofdate.c:294
QofDate_s::qd_valid
gboolean qd_valid
If the QofDate is valid or merely initialised.
Definition: qofdate.h:217
qof_date_adddays
gboolean qof_date_adddays(QofDate *qd, gint days)
Add a number of days to a QofDate and normalise.
Definition: qofdate.c:966
qof_date_free
void qof_date_free(QofDate *date)
Definition: qofdate.c:608
qof_date_from_qtime
QofDate * qof_date_from_qtime(const QofTime *qt)
Definition: qofdate.c:850
qof_date_format_set_name
gboolean qof_date_format_set_name(const gchar *name, QofDateFormat format)
Set a shorthand name for a custom date format.
Definition: qofdate.c:269
qof_date_format_from_name
QofDateFormat qof_date_format_from_name(const gchar *name)
Returns the default date format for a known shorthand name.
Definition: qofdate.c:385
QofDate_s::qd_zone
const gchar * qd_zone
Calculated value based on struct tm.tm_zone.
Definition: qofdate.h:208
qof_date_get_current
QofDate * qof_date_get_current(void)
Definition: qofdate.c:582
qof_date_get_mday
guint8 qof_date_get_mday(gint month, gint64 year)
Definition: qofdate.c:183
qof_date_close
void qof_date_close(void)
close down the QofDate tables
Definition: qofdate.c:156
qof_date_print
gchar * qof_date_print(const QofDate *date, QofDateFormat df)
Convert a QofDate to a timestamp according to the specified date format.
Definition: qofdate.c:547
qof_date_format_set_date_separator
gboolean qof_date_format_set_date_separator(const gchar sep, QofDateFormat df)
Set a locale-specific separator.
Definition: qofdate.c:340
qof_date_format_get_current
QofDateFormat qof_date_format_get_current(void)
returns the current date format.
Definition: qofdate.c:288
QofDate_s::qd_is_dst
gshort qd_is_dst
Definition: qofdate.h:193
QofDate
struct QofDate_s QofDate
Full range replacement for struct tm.
qof_date_format_get_format
const gchar * qof_date_format_get_format(QofDateFormat df)
Retrieve the strftime format string for a registered date format.
Definition: qofdate.c:310
qof_date_to_qtime
QofTime * qof_date_to_qtime(const QofDate *qd)
Definition: qofdate.c:892
QofDate_s
Full range replacement for struct tm.
Definition: qofdate.h:138
qof_date_format_get_date_separator
gchar qof_date_format_get_date_separator(QofDateFormat df)
Return the field separator for the current date format.
Definition: qofdate.c:325
qof_date_init
void qof_date_init(void)
initialise the QofDate tables
Definition: qofdate.c:67
qof_date_parse
QofDate * qof_date_parse(const gchar *str, QofDateFormat df)
Convert a timestamp to a QofTime.
Definition: qofdate.c:525
QofDate_s::qd_hour
glong qd_hour
Signed replacement of struct tm.tm_hour.
Definition: qofdate.h:157
QofDate_s::qd_min
glong qd_min
Signed replacement of struct tm.tm_min.
Definition: qofdate.h:150
QofDate_s::qd_mon
glong qd_mon
Signed replacement of struct tm.tm_mon.
Definition: qofdate.h:171
qof_date_get_yday
guint16 qof_date_get_yday(gint mday, gint month, gint64 year)
Definition: qofdate.c:167
qof_date_to_struct_tm
gboolean qof_date_to_struct_tm(const QofDate *qt, struct tm *stm, glong *nanosecs)
Convert a QofDate to a struct tm.
Definition: qofdate.c:702
qof_date_new_dmy
QofDate * qof_date_new_dmy(gint day, gint month, gint64 year)
Definition: qofdate.c:594
QofDate_s::qd_sec
gint64 qd_sec
Definition: qofdate.h:143
QofDateFormat
gint QofDateFormat
Definition: qofdate.h:335
QofDate_s::qd_gmt_off
glong qd_gmt_off
Calculated value based on struct tm.tm_gmtoff.
Definition: qofdate.h:201
qof_date_equal
gboolean qof_date_equal(const QofDate *d1, const QofDate *d2)
Definition: qofdate.c:629
qoftime.h
64bit UTC Time handling routines
qof_date_addmonths
gboolean qof_date_addmonths(QofDate *qd, gint months, gboolean track_last_day)
Definition: qofdate.c:975
qof_date_to_gdate
gboolean qof_date_to_gdate(const QofDate *qd, GDate *gd)
Convert a QofDate to a GDate.
Definition: qofdate.c:730
qof_date_format_to_name
const gchar * qof_date_format_to_name(QofDateFormat format)
Retrieve the shorthand name for the selected date format.
Definition: qofdate.c:254
QofDate_s::qd_nanosecs
glong qd_nanosecs
Definition: qofdate.h:141
QofTime
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
Definition: qoftime.h:120
qof_date_new
QofDate * qof_date_new(void)
Definition: qofdate.c:573
qof_date_time_difference
QofTime * qof_date_time_difference(const QofDate *date1, const QofDate *date2)
Definition: qofdate.c:925
qof_date_compare
gint qof_date_compare(const QofDate *d1, const QofDate *d2)
Definition: qofdate.c:637
QofDate_s::qd_wday
gshort qd_wday
Definition: qofdate.h:185
qof_date_is_last_mday
gboolean qof_date_is_last_mday(const QofDate *qd)
Definition: qofdate.c:193
QofDate_s::qd_mday
glong qd_mday
Signed replacement of struct tm.tm_mday.
Definition: qofdate.h:164
qof_date_from_gdate
QofDate * qof_date_from_gdate(const GDate *gd)
Create a QofDate from a GDate.
Definition: qofdate.c:750
qof_date_format_add
gboolean qof_date_format_add(const gchar *str, QofDateFormat *identifier)
Add a specific strftime compatible string as a new QofDateFormat.
Definition: qofdate.c:202
qof_date_valid
gboolean qof_date_valid(QofDate *date)
Validate a QofDate.
Definition: qofdate.c:616
qof_date_from_struct_tm
QofDate * qof_date_from_struct_tm(const struct tm *stm)
Convert a struct tm to a QofDate.
Definition: qofdate.c:679