00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00162
00174 #ifndef SWIG
00175 struct timespec64
00176 {
00177 gint64 tv_sec;
00178 glong tv_nsec;
00179 };
00180 #endif
00181
00190 typedef struct timespec64 Timespec;
00191
00192
00193
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
00213 Timespec timespecCanonicalDayTime(Timespec t);
00214
00216 Timespec timespec_now (void);
00217
00219 void timespecFromTime_t( Timespec *ts, time_t t );
00220
00222 time_t timespecToTime_t (Timespec ts);
00223
00225 GDate timespec_to_gdate (Timespec ts);
00226
00228 Timespec gdate_to_timespec (GDate d);
00229
00231 Timespec gnc_dmy2timespec (gint day, gint month, gint year);
00232
00234 Timespec gnc_dmy2timespec_end (gint day, gint month, gint year);
00235
00252 Timespec gnc_iso8601_to_timespec_gmt(const gchar *);
00253
00270 gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
00271
00274 void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00298 glong gnc_timezone (const struct tm *tm);
00299
00300
00301
00303
00309 QofDateFormat qof_date_format_get(void);
00310
00316 void qof_date_format_set(QofDateFormat df);
00317
00326 const gchar *qof_date_format_get_string(QofDateFormat df);
00327
00336 const gchar *qof_date_text_format_get_string(QofDateFormat df);
00337
00338
00345 void qof_date_completion_set(QofDateCompletion dc, int backmonths);
00346
00356 gchar dateSeparator(void);
00357
00360
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00395 gsize qof_strftime(gchar *buf, gsize max, const gchar *format,
00396 const struct tm *tm);
00397
00413 size_t qof_print_date_dmy_buff (gchar * buff, size_t buflen, int day, int month, int year);
00414
00416 size_t qof_print_date_buff (char * buff, size_t buflen, time_t secs);
00417
00419 size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
00420
00424 char * qof_print_date (time_t secs);
00425
00432 const char * gnc_print_date(Timespec ts);
00433
00434
00435
00436
00441 size_t qof_print_date_time_buff (char * buff, size_t len, time_t secs);
00442
00443
00444
00445
00446
00447
00448
00449
00450
00464 gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
00465
00467 gboolean qof_scan_date_secs (const char *buff, time_t *secs);
00468
00469
00473
00474
00479 static inline
00480 void gnc_tm_set_day_start (struct tm *tm)
00481 {
00482
00483 tm->tm_hour = 0;
00484 tm->tm_min = 0;
00485 tm->tm_sec = 0;
00486 tm->tm_isdst = -1;
00487 }
00488
00493 static inline
00494 void gnc_tm_set_day_middle (struct tm *tm)
00495 {
00496
00497 tm->tm_hour = 12;
00498 tm->tm_min = 0;
00499 tm->tm_sec = 0;
00500 tm->tm_isdst = -1;
00501 }
00502
00507 static inline
00508 void gnc_tm_set_day_end (struct tm *tm)
00509 {
00510
00511 tm->tm_hour = 23;
00512 tm->tm_min = 59;
00513 tm->tm_sec = 59;
00514 tm->tm_isdst = -1;
00515 }
00516
00519 time_t gnc_timet_get_day_start(time_t time_val);
00520
00523 time_t gnc_timet_get_day_end(time_t time_val);
00524
00526 int date_get_last_mday(const struct tm *tm);
00527
00529 gboolean date_is_last_mday(const struct tm *tm);
00530
00532 int gnc_date_my_last_mday (int month, int year);
00534 int gnc_timespec_last_mday (Timespec ts);
00535
00536
00537
00538
00540
00543 void gnc_tm_get_today_start(struct tm *tm);
00544
00547 void gnc_tm_get_today_end(struct tm *tm);
00548
00551 time_t gnc_timet_get_today_start(void);
00552
00555 time_t gnc_timet_get_today_end(void);
00556
00561 char * xaccDateUtilGetStampNow (void);
00562
00563 #define MIN_BUF_LEN 10
00564
00569 void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
00570
00572
00573 #endif