28 #define __EXTENSIONS__ 39 #ifdef HAVE_LANGINFO_D_FMT 40 # include <langinfo.h> 51 #include <unicode/calendar.h> 54 #include "gnc-date-p.h" 55 #include "gnc-datetime.hpp" 56 #include "gnc-timezone.hpp" 57 #define BOOST_ERROR_CODE_HEADER_ONLY 58 #include <boost/date_time/local_time/local_time.hpp> 60 #define N_(string) string //So that xgettext will find it 62 #ifdef HAVE_LANGINFO_D_FMT 63 # define GNC_D_FMT (nl_langinfo (D_FMT)) 64 # define GNC_D_T_FMT (nl_langinfo (D_T_FMT)) 65 # define GNC_T_FMT (nl_langinfo (T_FMT)) 66 #elif defined(G_OS_WIN32) 67 # define GNC_D_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATE)) 68 # define GNC_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_TIME)) 69 # define GNC_D_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATETIME)) 71 # define GNC_D_FMT "%Y-%m-%d" 72 # define GNC_D_T_FMT "%Y-%m-%d %r" 73 # define GNC_T_FMT "%r" 92 static int dateCompletionBackMonths = 6;
95 static QofLogModule log_module = QOF_MOD_ENGINE;
107 auto time =
static_cast<struct tm*
>(calloc(1,
sizeof(
struct tm)));
121 *time =
static_cast<struct tm
>(
GncDateTime(*secs));
124 catch(std::invalid_argument&)
131 normalize_time_component (
int *inner,
int *outer,
unsigned int divisor,
134 while (*inner < base)
139 while (*inner > static_cast<gint>(divisor))
147 normalize_month(
int *month,
int *year)
150 normalize_time_component(month, year, 12, 1);
155 normalize_struct_tm (
struct tm* time)
157 gint year = time->tm_year + 1900;
163 if (year < 1400) year += 1400;
164 if (year > 9999) year %= 10000;
166 normalize_time_component (&(time->tm_sec), &(time->tm_min), 60, 0);
167 normalize_time_component (&(time->tm_min), &(time->tm_hour), 60, 0);
168 normalize_time_component (&(time->tm_hour), &(time->tm_mday), 24, 0);
169 normalize_month (&(time->tm_mon), &year);
172 while (time->tm_mday < 1)
174 normalize_month (&(--time->tm_mon), &year);
176 time->tm_mday += last_day;
179 while (time->tm_mday > last_day)
181 time->tm_mday -= last_day;
182 normalize_month(&(++time->tm_mon), &year);
185 time->tm_year = year - 1900;
193 auto time =
static_cast<struct tm*
>(calloc(1,
sizeof(
struct tm)));
198 catch(std::invalid_argument&)
209 static int cached_result = 0;
213 UErrorCode err = U_ZERO_ERROR;
214 auto cal = icu::Calendar::createInstance (err);
217 PERR(
"ICU error: %s\n", u_errorName (err));
222 cached_result = cal->getFirstDayOfWeek (err);
226 return cached_result;
234 normalize_struct_tm (time);
236 *time =
static_cast<struct tm
>(gncdt);
237 return static_cast<time64>(gncdt);
239 catch(std::invalid_argument&)
250 normalize_struct_tm(time);
252 *time =
static_cast<struct tm
>(gncdt);
253 time->tm_sec -= gncdt.
offset();
254 normalize_struct_tm(time);
255 #ifdef HAVE_STRUcT_TM_GMTOFF 260 catch(std::invalid_argument&)
276 auto time =
static_cast<time64>(gncdt);
285 return (
double)secs1 - (double)secs2;
322 if (!strcmp(fmt_str,
"us"))
324 else if (!strcmp(fmt_str,
"uk"))
326 else if (!strcmp(fmt_str,
"ce"))
328 else if (!strcmp(fmt_str,
"utc"))
330 else if (!strcmp(fmt_str,
"iso"))
332 else if (!strcmp(fmt_str,
"locale"))
334 else if (!strcmp(fmt_str,
"custom"))
336 else if (!strcmp(fmt_str,
"unset"))
349 case GNCDATE_MONTH_NUMBER:
351 case GNCDATE_MONTH_ABBREV:
353 case GNCDATE_MONTH_NAME:
366 if (!strcmp(fmt_str,
"number"))
367 *format = GNCDATE_MONTH_NUMBER;
368 else if (!strcmp(fmt_str,
"abbrev"))
369 *format = GNCDATE_MONTH_ABBREV;
370 else if (!strcmp(fmt_str,
"name"))
371 *format = GNCDATE_MONTH_NAME;
384 auto sstr = gncdt.
format(format);
386 char* cstr =
static_cast<char*
>(malloc(sstr.length() + 1));
387 memset(cstr, 0, sstr.length() + 1);
388 strncpy(cstr, sstr.c_str(), sstr.length());
391 catch(std::runtime_error& err)
393 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
396 catch(std::logic_error& err)
398 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
417 gnc_tm_set_day_middle(&tm);
424 static int last_day_of_month[2][12] =
426 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
427 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
431 if (year % 2000 == 0)
return last_day_of_month[1][month];
432 if (year % 400 == 0 )
return last_day_of_month[0][month];
433 if (year % 4 == 0 )
return last_day_of_month[1][month];
434 return last_day_of_month[0][month];
444 if (df >= DATE_FORMAT_FIRST && df <= DATE_FORMAT_LAST)
446 prevQofDateFormat = dateFormat;
452 PERR(
"non-existent date format set attempted. Setting ISO default");
453 prevQofDateFormat = dateFormat;
485 PERR(
"non-existent date completion set attempted. Setting current year completion as default");
493 else if (backmonths > 11)
497 dateCompletionBackMonths = backmonths;
520 return "%Y-%m-%dT%H:%M:%SZ";
542 return "%Y-%m-%dT%H:%M:%SZ";
561 GncDate date(year, month, day);
563 strncpy(buff, str.c_str(), len);
564 if (str.length() >= len)
565 buff[len - 1] =
'\0';
567 catch(std::logic_error& err)
569 PWARN(
"Error processing year-month-day %d-%d-%d: %s",
570 year, month, day, err.what());
572 catch(std::runtime_error& err)
574 PWARN(
"Error processing year-month-day %d-%d-%d: %s",
575 year, month, day, err.what());
589 strncpy(buff, str.c_str(), len);
590 if (str.length() >= len)
591 buff[len - 1] =
'\0';
593 catch(std::logic_error& err)
595 PWARN(
"Error processing time64 %" PRId64
": %s", t, err.what());
597 catch(std::runtime_error& err)
599 PWARN(
"Error processing time64 %" PRId64
": %s", t, err.what());
608 g_date_clear (&date, 1);
611 g_date_get_day(&date),
612 g_date_get_month(&date),
613 g_date_get_year(&date) );
620 memset (buff, 0,
sizeof (buff));
622 return g_strdup (buff);
630 floordiv(
int a,
int b)
638 return - ((-a - 1) / b) - 1;
647 static inline std::string
648 normalize_format (
const std::string& format)
651 std::string normalized;
653 format.begin(), format.end(), back_inserter(normalized),
655 bool r = (is_pct && (e ==
'E' || e ==
'O' || e ==
'-'));
685 qof_scan_date_internal (
const char *buff,
int *day,
int *month,
int *year,
688 char *dupe, *tmp, *first_field, *second_field, *third_field;
689 int iday, imonth, iyear;
690 int now_day, now_month, now_year;
694 if (!buff)
return(FALSE);
699 || strptime (buff,
"%Y-%m-%d", &utc))
702 *month = utc.tm_mon + 1;
703 *year = utc.tm_year + 1900;
711 dupe = g_strdup (buff);
721 static const char *delims =
".,-+/\\()년월年月 ";
723 first_field = strtok (tmp, delims);
726 second_field = strtok (NULL, delims);
729 third_field = strtok (NULL, delims);
737 now_day = now->tm_mday;
738 now_month = now->tm_mon + 1;
739 now_year = now->tm_year + 1900;
748 switch (which_format)
755 memset(&thetime, -1,
sizeof(
struct tm));
756 strptime (buff, normalize_format(GNC_D_FMT).c_str(), &thetime);
761 iyear = thetime.tm_year + 1900;
762 iday = thetime.tm_mday;
763 imonth = thetime.tm_mon + 1;
765 else if (second_field)
768 if (thetime.tm_year == -1)
771 iday = thetime.tm_mday;
772 imonth = thetime.tm_mon + 1;
774 else if (thetime.tm_mon != -1)
777 imonth = atoi(first_field);
778 iday = atoi(second_field);
783 iday = atoi(first_field);
784 imonth = atoi(second_field);
787 else if (first_field)
789 iday = atoi(first_field);
797 iday = atoi(first_field);
798 imonth = atoi(second_field);
799 iyear = atoi(third_field);
801 else if (second_field)
803 iday = atoi(first_field);
804 imonth = atoi(second_field);
806 else if (first_field)
808 iday = atoi(first_field);
814 iyear = atoi(first_field);
815 imonth = atoi(second_field);
816 iday = atoi(third_field);
818 else if (second_field)
820 imonth = atoi(first_field);
821 iday = atoi(second_field);
823 else if (first_field)
825 iday = atoi(first_field);
832 imonth = atoi(first_field);
833 iday = atoi(second_field);
834 iyear = atoi(third_field);
836 else if (second_field)
838 imonth = atoi(first_field);
839 iday = atoi(second_field);
841 else if (first_field)
843 iday = atoi(first_field);
850 if ((imonth == 0) || (iday == 0))
853 if ((12 < imonth) || (31 < iday))
868 if ((which_format != prevQofDateFormat) &&
869 qof_scan_date_internal(buff, day, month, year, prevQofDateFormat))
873 if ((12 < imonth) && (12 >= iday))
903 iyear = now_year - floordiv(imonth - now_month +
904 dateCompletionBackMonths, 12);
911 iyear += ((int) ((now_year + 50 - iyear) / 100)) * 100;
913 if (year) *year = iyear;
914 if (month) *month = imonth;
915 if (day) *day = iday;
922 return qof_scan_date_internal(buff, day, month, year, dateFormat);
930 static char locale_separator =
'\0';
944 if (locale_separator !=
'\0')
945 return locale_separator;
956 auto normalized_fmt =
958 qof_strftime(
string,
sizeof(
string), normalized_fmt.c_str(), &tm);
960 for (s =
string; *s !=
'\0'; s++)
962 return (locale_separator = *s);
972 qof_time_format_from_utf8(
const gchar *utf8_format)
975 GError *error = NULL;
977 retval = g_locale_from_utf8(utf8_format, -1, NULL, NULL, &error);
981 g_warning(
"Could not convert format '%s' from UTF-8: %s", utf8_format,
989 qof_formatted_time_to_utf8(
const gchar *locale_string)
992 GError *error = NULL;
994 retval = g_locale_to_utf8(locale_string, -1, NULL, NULL, &error);
998 g_warning(
"Could not convert '%s' to UTF-8: %s", locale_string,
1000 g_error_free(error);
1007 qof_format_time(
const gchar *format,
const struct tm *tm)
1009 gchar *locale_format, *tmpbuf, *retval;
1010 gsize tmplen, tmpbufsize;
1012 g_return_val_if_fail(format, 0);
1013 g_return_val_if_fail(tm, 0);
1015 locale_format = qof_time_format_from_utf8(format);
1019 tmpbufsize = MAX(128, strlen(locale_format) * 2);
1022 tmpbuf =
static_cast<gchar*
>(g_malloc(tmpbufsize));
1028 tmplen = strftime(tmpbuf, tmpbufsize, locale_format, tm);
1030 if (tmplen == 0 && tmpbuf[0] !=
'\0')
1035 if (tmpbufsize > 65536)
1037 g_warning(
"Maximum buffer size for qof_format_time " 1038 "exceeded: giving up");
1039 g_free(locale_format);
1049 g_free(locale_format);
1051 retval = qof_formatted_time_to_utf8(tmpbuf);
1058 qof_strftime(gchar *buf, gsize max,
const gchar *format,
const struct tm *tm)
1060 gsize convlen, retval;
1063 g_return_val_if_fail(buf, 0);
1064 g_return_val_if_fail(max > 0, 0);
1065 g_return_val_if_fail(format, 0);
1066 g_return_val_if_fail(tm, 0);
1068 convbuf = qof_format_time(format, tm);
1075 convlen = strlen(convbuf);
1080 gchar *end = g_utf8_find_prev_char(convbuf, convbuf + max);
1081 g_assert(end != NULL);
1082 convlen = end - convbuf;
1092 memcpy(buf, convbuf, convlen);
1093 buf[convlen] =
'\0';
1115 #define ISO_DATE_FORMAT "%d-%d-%d %d:%d:%lf%s" 1120 if (!cstr)
return INT64_MAX;
1124 return static_cast<time64>(gncdt);
1126 catch(std::logic_error& err)
1128 PWARN(
"Error processing %s: %s", cstr, err.what());
1131 catch(std::runtime_error& err)
1133 PWARN(
"Error processing time64 %s: %s", cstr, err.what());
1144 constexpr
size_t max_iso_date_length = 32;
1146 if (! buff)
return NULL;
1152 memset(buff, 0, sstr.length() + 1);
1153 strncpy(buff, sstr.c_str(), sstr.length());
1154 return buff + sstr.length();
1156 catch(std::logic_error& err)
1158 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
1161 catch(std::runtime_error& err)
1163 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
1168 #define THIRTY_TWO_YEARS 0x3c30fc00LL 1171 gnc_dmy2time64_internal (
int day,
int month,
int year, DayPart day_part)
1175 auto date =
GncDate(year, month, day);
1178 catch(
const std::logic_error& err)
1180 PWARN(
"Date computation error from Y-M-D %d-%d-%d: %s",
1181 year, month, day, err.what());
1184 catch(
const std::runtime_error& err)
1186 PWARN(
"Date computation error from Y-M-D %d-%d-%d: %s",
1187 year, month, day, err.what());
1195 return gnc_dmy2time64_internal (day, month, year, DayPart::start);
1201 return gnc_dmy2time64_internal (day, month, year, DayPart::end);
1207 return gnc_dmy2time64_internal (day, month, year, DayPart::neutral);
1219 g_date_clear (&result, 1);
1221 auto date = time.date().year_month_day();
1222 g_date_set_dmy (&result, date.day, static_cast<GDateMonth>(date.month),
1224 g_assert(g_date_valid (&result));
1233 auto month =
static_cast<GDateMonth
>(
ymd.month);
1234 auto result = g_date_new_dmy (
ymd.day, month,
ymd.year);
1235 g_assert(g_date_valid (result));
1243 g_date_set_julian (gd, g_date_get_julian (today));
1244 g_date_free (today);
1252 g_date_set_dmy (gd, tm.tm_mday,
1253 static_cast<GDateMonth>(tm.tm_mon + 1),
1260 g_date_get_month(&d),
1261 g_date_get_year(&d));
1265 gnc_tm_get_day_start (
struct tm *tm,
time64 time_val)
1270 gnc_tm_set_day_start(tm);
1276 auto time_val{gnc_dmy2time64_internal(tm->tm_mday, tm->tm_mon + 1,
1277 tm->tm_year + 1900, DayPart::neutral)};
1282 gnc_tm_get_day_neutral (
struct tm *tm,
time64 time_val)
1291 gnc_tm_get_day_end (
struct tm *tm,
time64 time_val)
1296 gnc_tm_set_day_end(tm);
1305 gnc_tm_get_day_start(&tm, time_val);
1315 return gnc_dmy2time64_internal(tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900,
1325 gnc_tm_get_day_end(&tm, time_val);
1335 gnc_tm_get_day_start(tm, time(NULL));
1341 gnc_tm_get_day_neutral(tm, time(NULL));
1347 gnc_tm_get_day_end(tm, time(NULL));
1355 gnc_tm_get_day_start(&tm, time(NULL));
1364 gnc_tm_get_day_end(&tm, time(NULL));
1374 memset(buf, 0, buf_len);
1375 memset(&my_tm, 0,
sizeof(
struct tm));
1376 my_tm.tm_wday = dow;
1386 time64_boxed_copy_func (gpointer in_time64)
1390 newvalue =
static_cast<Time64*
>(g_malloc (
sizeof (
Time64)));
1391 memcpy (newvalue, in_time64,
sizeof(
Time64));
1397 time64_boxed_free_func (gpointer in_time64)
1403 time64_get_type(
void )
1405 static GType type = 0;
1409 type = g_boxed_type_register_static(
"time64",
1410 time64_boxed_copy_func,
1411 time64_boxed_free_func );
1421 return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
1427 gint val = (g_date_get_year( (GDate*)gd ) * 10000)
1428 + (g_date_get_month( (GDate*)gd ) * 100)
1429 + g_date_get_day( (GDate*)gd );
1430 return g_int_hash( &val );
1442 g_date_to_struct_tm (date, &stm);
1456 g_date_to_struct_tm(date, &stm);
1474 g_date_set_day(date, 1);
1488 g_date_set_day(date, 1);
1489 g_date_add_months(date, 1);
1492 g_date_subtract_days(date, 1);
1505 g_date_set_day(date, 1);
1506 g_date_subtract_months(date, 1);
1520 g_date_set_day(date, 1);
1521 g_date_subtract_days(date, 1);
1532 g_date_set_day(date, 1);
1535 months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
1536 g_date_subtract_months(date, months);
1542 const GDateMonth months[] = {G_DATE_MARCH, G_DATE_JUNE,
1543 G_DATE_SEPTEMBER, G_DATE_DECEMBER};
1544 const GDateDay days[] = {31, 30, 30, 31};
1545 int quarter = (g_date_get_month (date) - 1) / 3;
1547 g_date_set_month (date, months[quarter]);
1548 g_date_set_day (date, days[quarter]);
1555 g_date_subtract_months(date, 3);
1561 g_date_subtract_months(date, 3);
1570 g_date_set_month(date, G_DATE_JANUARY);
1571 g_date_set_day(date, 1);
1577 g_date_set_month(date, G_DATE_DECEMBER);
1578 g_date_set_day(date, 31);
1585 g_date_subtract_years(date, 1);
1592 g_date_subtract_years(date, 1);
1599 const GDate *fy_end)
1604 g_return_if_fail(date);
1605 g_return_if_fail(fy_end);
1609 g_date_set_year(&temp, g_date_get_year(date));
1612 new_fy = (g_date_compare(date, &temp) > 0);
1616 g_date_add_days(date, 1);
1618 g_date_subtract_years(date, 1);
1623 const GDate *fy_end)
1628 g_return_if_fail(date);
1629 g_return_if_fail(fy_end);
1633 g_date_set_year(&temp, g_date_get_year(date));
1636 new_fy = (g_date_compare(date, &temp) > 0);
1641 g_date_add_years(date, 1);
1646 const GDate *fy_end)
1648 g_return_if_fail(date);
1649 g_return_if_fail(fy_end);
1652 g_date_subtract_years(date, 1);
1657 const GDate *fy_end)
1659 g_return_if_fail(date);
1660 g_return_if_fail(fy_end);
1663 g_date_subtract_years(date, 1);
1667 gnc_date_load_funcs (
void)
time64 gnc_iso8601_to_time64_gmt(const gchar *)
The gnc_iso8601_to_time64_gmt() routine converts an ISO-8601 style date/time string to time64...
size_t qof_print_date_dmy_buff(gchar *buff, size_t buflen, int day, int month, int year)
qof_print_date_dmy_buff Convert a date as day / month / year integers into a localized string represe...
gsize qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
qof_strftime calls qof_format_time to print a given time and afterwards tries to put the result into ...
std::string format_iso8601() const
Format the GncDateTime into a gnucash-style iso8601 string in UTC.
Used by the check printing code.
gchar dateSeparator(void)
dateSeparator Return the field separator for the current date format
Date and Time handling routines.
gboolean gnc_date_string_to_monthformat(const gchar *format_string, GNCDateMonthFormat *format)
Converts the month format to a printable string.
time64 gnc_dmy2time64_neutral(gint day, gint month, gint year)
Converts a day, month, and year to a time64 representing 11:00:00 UTC 11:00:00 UTC falls on the same ...
void gnc_gdate_set_fiscal_year_end(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the last day of the fiscal year in which it falls...
const char * gnc_date_dateformat_to_string(QofDateFormat format)
The string->value versions return FALSE on success and TRUE on failure.
char * gnc_date_timestamp(void)
Make a timestamp in YYYYMMDDHHMMSS format.
QofDateCompletion
Enum for date completion modes (for dates entered without year)
gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb)
Compares two GDate*'s for equality; useful for using GDate*'s as GHashTable keys. ...
#define QOF_UTC_DATE_FORMAT
Constants.
Continental Europe: dd.mm.yyyy.
guint gnc_gdate_hash(gconstpointer gd)
Provides a "hash" of a GDate* value; useful for using GDate*'s as GHashTable keys.
void gnc_gdate_set_quarter_start(GDate *date)
This function modifies a GDate to set it to the first day of the quarter in which it falls...
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd)
Convenience; calls through to qof_print_date_dmy_buff().
No Fancy Date Format, use Global.
time64 gnc_dmy2time64(gint day, gint month, gint year)
Convert a day, month, and year to a time64, returning the first second of the day.
void gnc_gdate_set_today(GDate *gd)
Set a GDate to the current day.
GDate time64_to_gdate(time64 t)
Returns the GDate in which the time64 occurs.
long offset() const
Obtain the UTC offset in seconds.
void gnc_gdate_set_prev_month_end(GDate *date)
This function modifies a GDate to set it to the last day of the month prior to the one in which it fa...
void gnc_tm_get_today_start(struct tm *tm)
The gnc_tm_get_today_start() routine takes a pointer to a struct tm and fills it in with the first se...
int gnc_date_get_last_mday(int month, int year)
Get the numerical last date of the month.
const char * gnc_default_strftime_date_format
The default date format for use with strftime.
#define PERR(format, args...)
Log a serious error.
void qof_date_completion_set(QofDateCompletion dc, int backmonths)
The qof_date_completion_set() routing sets the date completion method to one of QOF_DATE_COMPLETION_T...
struct tm * gnc_localtime_r(const time64 *secs, struct tm *time)
fill out a time struct from a 64-bit time value adjusted for the current time zone.
void gnc_tm_get_today_neutral(struct tm *tm)
The gnc_tm_get_today_start() routine takes a pointer to a struct tm and fills it in with the timezone...
void gnc_tm_free(struct tm *time)
free a struct tm* created with gnc_localtime() or gnc_gmtime()
#define PWARN(format, args...)
Log a warning.
QofDateFormat qof_date_format_get(void)
The qof_date_format_get routine returns the date format that the date printing will use when printing...
use sliding 12-month window
char * qof_print_date(time64 secs)
Convenience; calls through to qof_print_date_dmy_buff().
static std::string timestamp()
Get an undelimited string representing the current date and time.
void gnc_gdate_set_prev_year_end(GDate *date)
This function modifies a GDate to set it to the last day of the year prior to the one in which it fal...
void gnc_gdate_set_prev_year_start(GDate *date)
This function modifies a GDate to set it to the first day of the year prior to the one in which it fa...
char * gnc_print_time64(time64 time, const char *format)
print a time64 as a date string per format
time64 gnc_time64_get_day_start(time64 time_val)
The gnc_time64_get_day_start() routine will take the given time in seconds and adjust it to the first...
void gnc_dow_abbrev(gchar *buf, int buf_len, int dow)
Localized DOW abbreviation.
UTC: 2004-12-12T23:39:11Z.
time64 gnc_time64_get_today_start(void)
The gnc_time64_get_today_start() routine returns a time64 value corresponding to the first second of ...
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
GNCDateMonthFormat
This is how to format the month, as a number, an abbreviated string, or the full name.
time64 gnc_timegm(struct tm *time)
calculate seconds from the epoch given a time struct
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
void gnc_gdate_set_month_start(GDate *date)
This function modifies a GDate to set it to the first day of the month in which it falls...
struct tm * gnc_localtime(const time64 *secs)
fill out a time struct from a 64-bit time value.
void gnc_gdate_set_prev_fiscal_year_end(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the last day of the fiscal year prior to the one in which...
gdouble gnc_difftime(const time64 secs1, const time64 secs2)
Find the difference in seconds between two time values.
std::string format(const char *format) const
Format the GncDateTime into a std::string.
ymd year_month_day() const
Get the year, month, and day from the date as a ymd.
void gnc_gdate_set_fiscal_year_start(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the first day of the fiscal year in which it falls...
void gnc_gdate_set_year_end(GDate *date)
This function modifies a GDate to set it to the last day of the year in which it falls.
const gchar * qof_date_text_format_get_string(QofDateFormat df)
This function returns a strftime formatting string for printing a date using words and numbers (e...
gboolean qof_scan_date(const char *buff, int *day, int *month, int *year)
qof_scan_date Convert a string into day / month / year integers according to the current dateFormat v...
void gnc_gdate_set_time64(GDate *gd, time64 time)
Set a GDate to a time64.
void gnc_gdate_set_month_end(GDate *date)
This function modifies a GDate to set it to the last day of the month in which it falls...
time64 gnc_time64_get_day_end_gdate(const GDate *date)
The gnc_time64_get_day_end() routine will take the given time in GLib GDate format and adjust it to t...
time64 gnc_dmy2time64_end(gint day, gint month, gint year)
Same as gnc_dmy2time64, but last second of the day.
void gnc_gdate_set_prev_fiscal_year_start(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the first day of the fiscal year prior to the one in whic...
void gnc_gdate_set_quarter_end(GDate *date)
This function modifies a GDate to set it to the last day of the quarter in which it falls...
time64 gnc_time64_get_today_end(void)
The gnc_time64_get_today_end() routine returns a time64 value corresponding to the last second of tod...
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
time64 gnc_time(time64 *tbuf)
get the current local time
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
void gnc_gdate_set_prev_quarter_end(GDate *date)
This function modifies a GDate to set it to the last day of the quarter prior to the one in which it ...
char * gnc_ctime(const time64 *secs)
Return a string representation of a date from a 64-bit time value.
time64 gnc_time64_get_day_end(time64 time_val)
The gnc_time64_get_day_end() routine will take the given time in seconds and adjust it to the last se...
struct tm utc_tm() const
Obtain a struct tm representing the time in UTC.
Take from locale information.
void qof_date_format_set(QofDateFormat df)
The qof_date_format_set() routine sets date format to one of US, UK, CE, OR ISO.
time64 time64CanonicalDayTime(time64 t)
convert a time64 on a certain day (localtime) to the time64 representing midday on that day...
void gnc_tm_get_today_end(struct tm *tm)
The gnc_tm_get_today_end() routine takes a pointer to a struct tm and fills it in with the last secon...
void gnc_tm_set_day_neutral(struct tm *tm)
The gnc_tm_set_day_neutral() inline routine will set the appropriate fields in the struct tm to indic...
gboolean gnc_date_string_to_dateformat(const gchar *format_string, QofDateFormat *format)
Converts the date format to a printable string.
const gchar * qof_date_format_get_string(QofDateFormat df)
This function returns a strftime formatting string for printing an all numeric date (e...
time64 gnc_time64_get_day_start_gdate(const GDate *date)
The gnc_time64_get_day_start() routine will take the given time in GLib GDate format and adjust it to...
char * gnc_time64_to_iso8601_buff(time64 time, char *buff)
The gnc_time64_to_iso8601_buff() routine takes the input UTC time64 value and prints it as an ISO-860...
QofDateFormat
Enum for determining a date format.
United states: mm/dd/yyyy.
void gnc_gdate_set_prev_quarter_start(GDate *date)
This function modifies a GDate to set it to the first day of the quarter prior to the one in which it...
gint gnc_start_of_week(void)
returns an integer corresponding to locale start of week
void gnc_gdate_set_year_start(GDate *date)
This function modifies a GDate to set it to the first day of the year in which it falls...
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
Convenience: calls through to qof_print_date_dmy_buff().
time64 gnc_time64_get_day_neutral(time64 time_val)
The gnc_time64_get_day_neutral() routine will take the given time in seconds and adjust it to 10:59:0...
GDate * gnc_g_date_new_today()
Returns a newly allocated date of the current clock time, taken from time(2).
void gnc_gdate_set_prev_month_start(GDate *date)
This function modifies a GDate to set it to the first day of the month prior to the one in which it f...