GnuCash 2.4.99
gnc-date.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *            gnc-date.h (to be renamed qofdate.h)
00003  *
00004  *  Copyright (C) 1997 Robin D. Clark <rclark@cs.hmc.edu>
00005  *  Copyright (C) 1998-2000, 2003 Linas Vepstas <linas@linas.org>
00006  *  Copyright  2005  Neil Williams <linux@codehelp.co.uk>
00007  ****************************************************************************/
00008 /********************************************************************\
00009  * This program is free software; you can redistribute it and/or    *
00010  * modify it under the terms of the GNU General Public License as   *
00011  * published by the Free Software Foundation; either version 2 of   *
00012  * the License, or (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, contact:                        *
00021  *                                                                  *
00022  * Free Software Foundation           Voice:  +1-617-542-5942       *
00023  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00024  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00025 \********************************************************************/
00067 #ifndef GNC_DATE_H
00068 #define GNC_DATE_H
00069 
00070 #include <glib-object.h>
00071 #include <time.h>
00072 
00076 GType timespec_get_type( void );
00077 #define GNC_TYPE_TIMESPEC (timespec_get_type ())
00078 
00081 extern const char *gnc_default_strftime_date_format;
00082 
00084 #define MAX_DATE_LENGTH 31
00085 
00096 #define QOF_UTC_DATE_FORMAT     "%Y-%m-%dT%H:%M:%SZ"
00097 
00099 typedef enum
00100 {
00101     QOF_DATE_FORMAT_US,       
00102     QOF_DATE_FORMAT_UK,       
00103     QOF_DATE_FORMAT_CE,       
00104     QOF_DATE_FORMAT_ISO,      
00105     QOF_DATE_FORMAT_UTC,      
00106     QOF_DATE_FORMAT_LOCALE,   
00107     QOF_DATE_FORMAT_CUSTOM    
00108 } QofDateFormat;
00109 
00110 #define DATE_FORMAT_FIRST QOF_DATE_FORMAT_US
00111 #define DATE_FORMAT_LAST  QOF_DATE_FORMAT_LOCALE
00112 
00114 typedef enum
00115 {
00116     QOF_DATE_COMPLETION_THISYEAR, 
00117     QOF_DATE_COMPLETION_SLIDING,  
00118 } QofDateCompletion;
00119 
00122 #define qof_date_format_get_format qof_date_text_format_get_string
00123 
00128 typedef enum
00129 {
00130     GNCDATE_MONTH_NUMBER,
00131     GNCDATE_MONTH_ABBREV,
00132     GNCDATE_MONTH_NAME
00133 } GNCDateMonthFormat;
00134 
00135 
00138 
00140 const gchar* gnc_date_dateformat_to_string(QofDateFormat format);
00141 
00147 gboolean gnc_date_string_to_dateformat(const gchar* format_string,
00148                                        QofDateFormat *format);
00149 
00150 const gchar* gnc_date_monthformat_to_string(GNCDateMonthFormat format);
00151 
00157 gboolean gnc_date_string_to_monthformat(const gchar *format_string,
00158                                         GNCDateMonthFormat *format);
00159 // @}
00160 
00161 /* Datatypes *******************************************************/
00162 
00174 #ifndef SWIG   /* swig 1.1p5 can't hack the long long type */
00175 struct timespec64
00176 {
00177     gint64 tv_sec;
00178     glong tv_nsec;
00179 };
00180 #endif /* SWIG */
00181 
00190 typedef struct timespec64 Timespec;
00191 
00192 
00193 /* Prototypes ******************************************************/
00194 
00196 // @{
00198 gboolean timespec_equal(const Timespec *ta, const Timespec *tb);
00199 
00201 gint      timespec_cmp(const Timespec *ta, const Timespec *tb);
00202 
00206 Timespec timespec_diff(const Timespec *ta, const Timespec *tb);
00207 
00209 Timespec timespec_abs(const Timespec *t);
00210 
00215 Timespec timespecCanonicalDayTime(Timespec t);
00216 
00218 Timespec timespec_now (void);
00219 
00221 void timespecFromTime_t( Timespec *ts, time_t t );
00222 
00224 time_t timespecToTime_t (Timespec ts);
00225 
00228 GDate* gnc_g_date_new_today (void);
00229 
00231 GDate timespec_to_gdate (Timespec ts);
00232 
00234 Timespec gdate_to_timespec (GDate d);
00235 
00238 GDate gnc_dmy2gdate (gint day, gint month, gint year);
00239 
00241 Timespec gnc_dmy2timespec (gint day, gint month, gint year);
00242 
00244 Timespec gnc_dmy2timespec_end (gint day, gint month, gint year);
00245 
00262 Timespec gnc_iso8601_to_timespec_gmt(const gchar *);
00263 
00280 gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
00281 
00284 void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
00285 
00286 /* \warning hack alert XXX FIXME -- these date routines return incorrect
00287  * values for dates before 1970.  Most of them are good only up
00288  * till 2038.  This needs fixing ...
00289  *
00290  * XXX  This routine should be modified to assume that the
00291  * the user wanted the time at noon, localtime.  The returned
00292  * time_t should be seconds (at GMT) of the local noon-time.
00293 */
00294 /* time_t xaccDMYToSec (gint day, gint month, gint year); */
00295 
00308 glong gnc_timezone (const struct tm *tm);
00309 // @}
00310 
00311 /* ------------------------------------------------------------------------ */
00313 // @{
00319 QofDateFormat qof_date_format_get(void);
00320 
00326 void qof_date_format_set(QofDateFormat df);
00327 
00336 const gchar *qof_date_format_get_string(QofDateFormat df);
00337 
00346 const gchar *qof_date_text_format_get_string(QofDateFormat df);
00347 // @}
00348 
00355 void qof_date_completion_set(QofDateCompletion dc, int backmonths);
00356 
00366 gchar dateSeparator(void);
00367 
00370 // @{
00379 /* qof_format_time takes a format specification in UTF-8 and a broken-down time,
00380  *  tries to call strftime with a sufficiently large buffer and, if successful,
00381  *  return a newly allocated string in UTF-8 for the printing result.
00382  *
00383  *  @param format A format specification in UTF-8.
00384  *
00385  *  @param tm A broken-down time.
00386  *
00387  *  @return A newly allocated string on success, or NULL otherwise.
00388  */
00389 /* gchar *qof_format_time(const gchar *format, const struct tm *tm); */
00390 
00405 gsize qof_strftime(gchar *buf, gsize max, const gchar *format,
00406                    const struct tm *tm);
00407 
00423 size_t qof_print_date_dmy_buff (gchar * buff, size_t buflen, int day, int month, int year);
00424 
00426 size_t qof_print_date_buff (char * buff, size_t buflen, time_t secs);
00427 
00429 size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
00430 
00434 char * qof_print_date (time_t secs);
00435 
00442 const char * gnc_print_date(Timespec ts);
00443 
00444 /* ------------------------------------------------------------------ */
00445 /* time printing utilities */
00446 
00451 size_t qof_print_date_time_buff (char * buff, size_t len, time_t secs);
00452 
00453 /* ------------------------------------------------------------------ */
00454 /* The xaccDateUtilGetStamp() routine will take the given time in
00455  *  seconds and return a buffer containing a textual for the date.
00456  *  @param thyme The time in seconds to convert.
00457  *  @return A pointer to the generated string.
00458  *  @note The caller owns this buffer and must free it when done. */
00459 /* char * xaccDateUtilGetStamp (time_t thyme); */
00460 
00474 gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
00475 
00477 gboolean qof_scan_date_secs (const char *buff, time_t *secs);
00478 
00479 // @}
00483 // @{
00484 
00489 static inline
00490 void gnc_tm_set_day_start (struct tm *tm)
00491 {
00492     /* First second of the day */
00493     tm->tm_hour = 0;
00494     tm->tm_min = 0;
00495     tm->tm_sec = 0;
00496     tm->tm_isdst = -1;
00497 }
00498 
00503 static inline
00504 void gnc_tm_set_day_middle (struct tm *tm)
00505 {
00506     /* First second of the day */
00507     tm->tm_hour = 12;
00508     tm->tm_min = 0;
00509     tm->tm_sec = 0;
00510     tm->tm_isdst = -1;
00511 }
00512 
00517 static inline
00518 void gnc_tm_set_day_end (struct tm *tm)
00519 {
00520     /* Last second of the day */
00521     tm->tm_hour = 23;
00522     tm->tm_min = 59;
00523     tm->tm_sec = 59;
00524     tm->tm_isdst = -1;
00525 }
00526 
00529 time_t gnc_timet_get_day_start(time_t time_val);
00530 
00533 time_t gnc_timet_get_day_end(time_t time_val);
00534 
00536 int date_get_last_mday(const struct tm *tm);
00537 
00539 gboolean date_is_last_mday(const struct tm *tm);
00540 
00542 int gnc_date_my_last_mday (int month, int year);
00544 int gnc_timespec_last_mday (Timespec ts);
00545 // @}
00546 
00547 /* ======================================================== */
00548 
00550 // @{
00553 void   gnc_tm_get_today_start(struct tm *tm);
00554 
00557 void   gnc_tm_get_today_end(struct tm *tm);
00558 
00561 time_t gnc_timet_get_today_start(void);
00562 
00565 time_t gnc_timet_get_today_end(void);
00566 
00571 char * xaccDateUtilGetStampNow (void);
00572 
00573 #define MIN_BUF_LEN 10
00574 
00579 void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
00580 
00582 
00583 #endif /* GNC_DATE_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines