QOF
0.7.5
|
00001 /******************************************************************** 00002 * qofdate.h - QofDate, 64bit UTC date handling. 00003 * Rewritten from scratch for QOF 0.7.0 00004 * 00005 * Fri May 5 15:05:24 2006 00006 * Copyright (C) 2006 Free Software Foundation, Inc. 00007 ********************************************************************/ 00008 /* 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA 00022 */ 00075 #ifndef QOFDATE_H 00076 #define QOFDATE_H 00077 00078 #include "qoftime.h" 00079 00087 #define MAX_DATE_LENGTH 41 00088 00092 #define MAX_DATE_BUFFER 256 00093 00094 #define SECS_PER_DAY 86400 00095 00096 #define SECS_PER_HOUR 3600 00097 00098 #define QOF_MOD_DATE "qof-dates" 00099 00138 typedef struct QofDate_s 00139 { 00141 glong qd_nanosecs; 00143 gint64 qd_sec; 00150 glong qd_min; 00157 glong qd_hour; 00164 glong qd_mday; 00171 glong qd_mon; 00181 gint64 qd_year; 00185 gshort qd_wday; 00189 gshort qd_yday; 00193 gshort qd_is_dst; 00201 glong qd_gmt_off; 00208 const gchar *qd_zone; 00217 gboolean qd_valid; 00218 } QofDate; 00219 00222 # define qof_date_isleap(year) \ 00223 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) 00224 00226 void qof_date_init (void); 00227 00229 void qof_date_close (void); 00230 00244 #define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ" 00245 00253 #define QOF_DATE_FORMAT_US 1 00254 00258 #define QOF_DATE_FORMAT_UK 2 00259 00263 #define QOF_DATE_FORMAT_CE 3 00264 00268 #define QOF_DATE_FORMAT_ISO 4 00269 00277 #define QOF_DATE_FORMAT_UTC 5 00278 00287 #define QOF_DATE_FORMAT_ISO8601 6 00288 00303 #define QOF_DATE_FORMAT_LOCALE 7 00304 00319 #define QOF_DATE_FORMAT_CUSTOM 8 00320 00322 #define DATE_FORMAT_LAST QOF_DATE_FORMAT_CUSTOM 00323 00327 #define QOF_HOUR_TO_SEC(x) (x * SECS_PER_HOUR) 00328 00329 #define QOF_MIN_TO_SEC(x) (x * 60) 00330 00331 #define QOF_DAYS_TO_SEC(x) (x * SECS_PER_DAY) 00332 00335 typedef gint QofDateFormat; 00336 00358 gboolean 00359 qof_date_format_add (const gchar * str, QofDateFormat *identifier); 00360 00371 const gchar * 00372 qof_date_format_to_name (QofDateFormat format); 00373 00384 QofDateFormat 00385 qof_date_format_from_name (const gchar * name); 00386 00400 gboolean 00401 qof_date_format_set_name (const gchar * name, QofDateFormat format); 00402 00404 QofDateFormat 00405 qof_date_format_get_current (void); 00406 00413 gboolean 00414 qof_date_format_set_current (QofDateFormat df); 00415 00423 const gchar * 00424 qof_date_format_get_format (QofDateFormat df); 00425 00436 gchar 00437 qof_date_format_get_date_separator (QofDateFormat df); 00438 00447 gboolean 00448 qof_date_format_set_date_separator (const gchar sep, QofDateFormat df); 00455 QofDate * 00456 qof_date_new (void); 00457 00459 QofDate * 00460 qof_date_get_current (void); 00461 00463 QofDate * 00464 qof_date_new_dmy (gint day, gint month, gint64 year); 00465 00467 void 00468 qof_date_free (QofDate * date); 00469 00471 QofTime* 00472 qof_date_time_difference (const QofDate * date1, const QofDate * date2); 00473 00481 gboolean 00482 qof_date_is_last_mday (const QofDate *qd); 00483 00499 gboolean 00500 qof_date_addmonths (QofDate * qd, gint months, 00501 gboolean track_last_day); 00502 00504 gboolean 00505 qof_date_equal (const QofDate *d1, const QofDate *d2); 00506 00508 gint 00509 qof_date_compare (const QofDate * d1, const QofDate * d2); 00510 00532 gboolean 00533 qof_date_valid (QofDate *date); 00534 00544 guint16 00545 qof_date_get_yday (gint mday, gint month, gint64 year); 00546 00555 guint8 00556 qof_date_get_mday (gint month, gint64 year); 00557 00564 QofDate * 00565 qof_date_from_qtime (const QofTime *qt); 00566 00568 QofTime * 00569 qof_date_to_qtime (const QofDate *qd); 00570 00576 QofDate * 00577 qof_date_from_struct_tm (const struct tm *stm); 00578 00593 gboolean 00594 qof_date_to_struct_tm (const QofDate * qt, struct tm *stm, glong * nanosecs); 00595 00605 gboolean 00606 qof_date_to_gdate (const QofDate *qd, GDate *gd); 00607 00617 QofDate * 00618 qof_date_from_gdate (const GDate *gd); 00619 00635 gboolean 00636 qof_date_adddays (QofDate * qd, gint days); 00637 00638 gboolean 00639 qof_date_set_day_end (QofDate * qd); 00640 00641 gboolean 00642 qof_date_set_day_start (QofDate * qd); 00643 00644 gboolean 00645 qof_date_set_day_middle (QofDate * qd); 00646 00712 gchar * 00713 qof_date_print (const QofDate * date, QofDateFormat df); 00714 00725 QofDate * 00726 qof_date_parse (const gchar * str, QofDateFormat df); 00727 00732 #endif /* QOFDATE_H */