gnc-date.h

Go to the documentation of this file.
00001 /********************************************************************\
00002  * This program is free software; you can redistribute it and/or    *
00003  * modify it under the terms of the GNU General Public License as   *
00004  * published by the Free Software Foundation; either version 2 of   *
00005  * the License, or (at your option) any later version.              *
00006  *                                                                  *
00007  * This program is distributed in the hope that it will be useful,  *
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00010  * GNU General Public License for more details.                     *
00011  *                                                                  *
00012  * You should have received a copy of the GNU General Public License*
00013  * along with this program; if not, contact:                        *
00014  *                                                                  *
00015  * Free Software Foundation           Voice:  +1-617-542-5942       *
00016  * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
00017  * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
00018 \********************************************************************/
00060 #ifndef GNC_DATE_H
00061 #define GNC_DATE_H
00062 
00063 #include <glib.h>
00064 #include <time.h>
00065 
00067 #define MAX_DATE_LENGTH 31
00068 
00079 #define QOF_UTC_DATE_FORMAT     "%Y-%m-%dT%H:%M:%SZ"
00080 
00082 typedef enum
00083 {
00084   QOF_DATE_FORMAT_US,       
00085   QOF_DATE_FORMAT_UK,       
00086   QOF_DATE_FORMAT_CE,       
00087   QOF_DATE_FORMAT_ISO,      
00088   QOF_DATE_FORMAT_UTC,      
00089   QOF_DATE_FORMAT_LOCALE,   
00090   QOF_DATE_FORMAT_CUSTOM    
00091 } QofDateFormat;
00092 
00093 #define DATE_FORMAT_FIRST QOF_DATE_FORMAT_US
00094 #define DATE_FORMAT_LAST  QOF_DATE_FORMAT_LOCALE
00095 
00098 #define qof_date_format_get_format qof_date_text_format_get_string
00099 
00104 typedef enum {
00105   GNCDATE_MONTH_NUMBER,
00106   GNCDATE_MONTH_ABBREV,
00107   GNCDATE_MONTH_NAME
00108 } GNCDateMonthFormat;
00109 
00110 
00113 
00115 const char* gnc_date_dateformat_to_string(QofDateFormat format);
00116 
00122 gboolean gnc_date_string_to_dateformat(const char* format_string,
00123                                        QofDateFormat *format);
00124 
00125 const char* gnc_date_monthformat_to_string(GNCDateMonthFormat format);
00126 
00132 gboolean gnc_date_string_to_monthformat(const char *format_string,
00133                                         GNCDateMonthFormat *format);
00134 // @}
00135 
00136 /* Datatypes *******************************************************/
00137 
00151 #ifndef SWIG   /* swig 1.1p5 can't hack the long long type */
00152 struct timespec64
00153 {
00154    long long int tv_sec;     
00155    long int tv_nsec;
00156 };
00157 #endif /* SWIG */
00158 
00168 typedef struct timespec64 Timespec;
00169 
00170 
00171 /* Prototypes ******************************************************/
00172 
00174 // @{ 
00176 gboolean timespec_equal(const Timespec *ta, const Timespec *tb);
00177 
00179 int      timespec_cmp(const Timespec *ta, const Timespec *tb);
00180 
00184 Timespec timespec_diff(const Timespec *ta, const Timespec *tb);
00185 
00187 Timespec timespec_abs(const Timespec *t);
00188 
00191 Timespec timespecCanonicalDayTime(Timespec t);
00192 
00194 void timespecFromTime_t( Timespec *ts, time_t t );
00195 
00197 time_t timespecToTime_t (Timespec ts);
00198 
00200 Timespec gnc_dmy2timespec (int day, int month, int year);
00201 
00203 Timespec gnc_dmy2timespec_end (int day, int month, int year);
00204 
00221 Timespec gnc_iso8601_to_timespec_gmt(const char *);
00222 
00239 char * gnc_timespec_to_iso8601_buff (Timespec ts, char * buff);
00240 
00243 void gnc_timespec2dmy (Timespec ts, int *day, int *month, int *year);
00244 
00247 void date_add_months (struct tm *tm, int months, gboolean track_last_day);
00248 
00257 time_t xaccDMYToSec (int day, int month, int year);
00258 
00271 long int gnc_timezone (struct tm *tm);
00272 // @}
00273 
00274 /* ------------------------------------------------------------------------ */
00276 // @{
00282 QofDateFormat qof_date_format_get(void);
00283 
00289 void qof_date_format_set(QofDateFormat df);
00290 
00299 const gchar *qof_date_format_get_string(QofDateFormat df);
00300 
00309 const gchar *qof_date_text_format_get_string(QofDateFormat df);
00310 // @}
00311 
00321 char dateSeparator(void);
00322 
00325 // @{
00349 size_t qof_print_date_dmy_buff (char * buff, size_t buflen, int day, int month, int year);
00350 
00352 size_t qof_print_date_buff (char * buff, size_t buflen, time_t secs);
00353 
00355 size_t qof_print_gdate( char *buf, size_t bufflen, GDate *gd );
00356 
00360 char * qof_print_date (time_t secs);
00361 
00368 const char * gnc_print_date(Timespec ts);
00369 
00370 /* ------------------------------------------------------------------ */
00371 /* time printing utilities */
00372 
00378 size_t qof_print_hours_elapsed_buff (char * buff, size_t len, int secs, gboolean show_secs);
00379 size_t qof_print_minutes_elapsed_buff (char * buff, size_t len, int secs, gboolean show_secs);
00380 
00386 size_t qof_print_time_buff (char * buff, size_t len, time_t secs);
00387 size_t qof_print_date_time_buff (char * buff, size_t len, time_t secs);
00388 
00393 gboolean qof_is_same_day (time_t, time_t);
00394 
00395 /* ------------------------------------------------------------------ */
00401 char * xaccDateUtilGetStamp (time_t thyme);
00402  
00416 gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
00417 
00419 gboolean qof_scan_date_secs (const char *buff, time_t *secs);
00420 
00421 // @}
00425 // @{
00426 
00431 static inline
00432 void gnc_tm_set_day_start (struct tm *tm)
00433 {
00434   /* First second of the day */
00435   tm->tm_hour = 0;
00436   tm->tm_min = 0;
00437   tm->tm_sec = 0;
00438   tm->tm_isdst = -1;
00439 }
00440 
00445 static inline
00446 void gnc_tm_set_day_middle (struct tm *tm)
00447 {
00448   /* First second of the day */
00449   tm->tm_hour = 12;
00450   tm->tm_min = 0;
00451   tm->tm_sec = 0;
00452   tm->tm_isdst = -1;
00453 }
00454 
00459 static inline
00460 void gnc_tm_set_day_end (struct tm *tm)
00461 {
00462   /* Last second of the day */
00463   tm->tm_hour = 23;
00464   tm->tm_min = 59;
00465   tm->tm_sec = 59;
00466   tm->tm_isdst = -1;
00467 }
00468 
00472 void   gnc_tm_get_day_start(struct tm *tm, time_t time_val);
00473 
00477 void   gnc_tm_get_day_end(struct tm *tm, time_t time_val);
00478 
00481 time_t gnc_timet_get_day_start(time_t time_val);
00482 
00485 time_t gnc_timet_get_day_end(time_t time_val);
00486 
00487 #ifndef GNUCASH_MAJOR_VERSION
00488 
00493 time_t gnc_timet_get_day_start_gdate (GDate *date);
00494 
00500 time_t gnc_timet_get_day_end_gdate (GDate *date);
00501 #endif /* GNUCASH_MAJOR_VERSION */
00502 
00504 int date_get_last_mday(struct tm *tm);
00505 
00507 gboolean date_is_last_mday(struct tm *tm);
00508 
00510 int gnc_date_my_last_mday (int month, int year);
00512 int gnc_timespec_last_mday (Timespec ts);
00513 // @}
00514 
00515 /* ======================================================== */
00516 
00518 // @{
00521 void   gnc_tm_get_today_start(struct tm *tm);
00522 
00525 void   gnc_tm_get_today_end(struct tm *tm);
00526 
00529 time_t gnc_timet_get_today_start(void);
00530 
00533 time_t gnc_timet_get_today_end(void);
00534 
00539 char * xaccDateUtilGetStampNow (void);
00540 
00542 
00543 #endif /* GNC_DATE_H */

Generated on Fri Oct 21 15:49:54 2005 for QOF by  doxygen 1.4.5