36 #ifdef HAVE_LANGINFO_D_FMT 37 # include <langinfo.h> 47 #include <unicode/calendar.h> 48 #include "unicode/dtitvfmt.h" 49 #include "unicode/smpdtfmt.h" 52 #include "gnc-date-p.h" 53 #include "gnc-datetime.hpp" 54 #include "gnc-timezone.hpp" 55 #define BOOST_ERROR_CODE_HEADER_ONLY 56 #include <boost/date_time/local_time/local_time.hpp> 58 #define N_(string) string //So that xgettext will find it 60 #ifdef HAVE_LANGINFO_D_FMT 61 # define GNC_D_FMT (nl_langinfo (D_FMT)) 62 # define GNC_D_T_FMT (nl_langinfo (D_T_FMT)) 63 # define GNC_T_FMT (nl_langinfo (T_FMT)) 64 #elif defined(G_OS_WIN32) 65 # define GNC_D_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATE)) 66 # define GNC_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_TIME)) 67 # define GNC_D_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATETIME)) 69 # define GNC_D_FMT "%Y-%m-%d" 70 # define GNC_D_T_FMT "%Y-%m-%d %r" 71 # define GNC_T_FMT "%r" 90 static int dateCompletionBackMonths = 6;
93 static QofLogModule log_module = QOF_MOD_ENGINE;
105 auto time =
static_cast<struct tm*
>(calloc(1,
sizeof(
struct tm)));
119 *time =
static_cast<struct tm
>(
GncDateTime(*secs));
122 catch(std::invalid_argument&)
129 normalize_time_component (
int *inner,
int *outer,
int divisor)
136 while (*inner >= divisor)
144 normalize_struct_tm (
struct tm* time)
146 gint year = time->tm_year + 1900;
152 if (year < 1400) year += 1400;
153 if (year > 9999) year %= 10000;
155 normalize_time_component (&(time->tm_sec), &(time->tm_min), 60);
156 normalize_time_component (&(time->tm_min), &(time->tm_hour), 60);
157 normalize_time_component (&(time->tm_hour), &(time->tm_mday), 24);
158 normalize_time_component (&(time->tm_mon), &year, 12);
161 while (time->tm_mday < 1)
163 normalize_time_component (&(--time->tm_mon), &year, 12);
165 time->tm_mday += last_day;
168 while (time->tm_mday > last_day)
170 time->tm_mday -= last_day;
171 normalize_time_component(&(++time->tm_mon), &year, 12);
174 time->tm_year = year - 1900;
183 auto time =
static_cast<struct tm*
>(calloc(1,
sizeof(
struct tm)));
187 catch(std::invalid_argument&)
198 static int cached_result = 0;
202 UErrorCode err = U_ZERO_ERROR;
203 auto cal = icu::Calendar::createInstance (err);
206 PERR(
"ICU error: %s\n", u_errorName (err));
211 cached_result = cal->getFirstDayOfWeek (err);
215 return cached_result;
223 normalize_struct_tm (time);
225 *time =
static_cast<struct tm
>(gncdt);
226 return static_cast<time64>(gncdt);
228 catch(std::invalid_argument&)
239 normalize_struct_tm(time);
241 *time =
static_cast<struct tm
>(gncdt);
242 time->tm_sec -= gncdt.
offset();
243 normalize_struct_tm(time);
244 #ifdef HAVE_STRUcT_TM_GMTOFF 249 catch(std::invalid_argument&)
265 auto time =
static_cast<time64>(gncdt);
274 PWARN (
"gnc_difftime is deprecated");
275 return (
double)secs1 - (double)secs2;
312 if (!strcmp(fmt_str,
"us"))
314 else if (!strcmp(fmt_str,
"uk"))
316 else if (!strcmp(fmt_str,
"ce"))
318 else if (!strcmp(fmt_str,
"utc"))
320 else if (!strcmp(fmt_str,
"iso"))
322 else if (!strcmp(fmt_str,
"locale"))
324 else if (!strcmp(fmt_str,
"custom"))
326 else if (!strcmp(fmt_str,
"unset"))
338 switch (static_cast<uint8_t>(format))
340 case GNCDATE_MONTH_NUMBER:
342 case GNCDATE_MONTH_ABBREV:
344 case GNCDATE_MONTH_NAME:
357 if (!strcmp(fmt_str,
"number"))
358 *format = GNCDATE_MONTH_NUMBER;
359 else if (!strcmp(fmt_str,
"abbrev"))
360 *format = GNCDATE_MONTH_ABBREV;
361 else if (!strcmp(fmt_str,
"name"))
362 *format = GNCDATE_MONTH_NAME;
375 auto sstr = gncdt.
format(format);
377 char* cstr =
static_cast<char*
>(malloc(sstr.length() + 1));
378 memset(cstr, 0, sstr.length() + 1);
379 strncpy(cstr, sstr.c_str(), sstr.length());
382 catch(std::runtime_error& err)
384 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
387 catch(std::logic_error& err)
389 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
408 gnc_tm_set_day_middle(&tm);
415 static int last_day_of_month[12] =
416 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
418 g_assert(month >= 0 && month < 12);
423 return last_day_of_month[month] +
424 (month == 1 && year % 4 == 0 && !(year % 100 == 0 && year % 400 != 0) ?
436 auto dfi{
static_cast<uint8_t
>(df)};
437 if (dfi >= DATE_FORMAT_FIRST && dfi <= DATE_FORMAT_LAST)
439 prevQofDateFormat = dateFormat;
445 PERR(
"non-existent date format set attempted. Setting ISO default");
446 prevQofDateFormat = dateFormat;
478 PERR(
"non-existent date completion set attempted. Setting current year completion as default");
486 else if (backmonths > 11)
490 dateCompletionBackMonths = backmonths;
513 return "%Y-%m-%dT%H:%M:%SZ";
535 return "%Y-%m-%dT%H:%M:%SZ";
554 GncDate date(year, month, day);
556 strncpy(buff, str.c_str(), len);
557 if (str.length() >= len)
558 buff[len - 1] =
'\0';
560 catch(std::logic_error& err)
562 PWARN(
"Error processing year-month-day %d-%d-%d: %s",
563 year, month, day, err.what());
565 catch(std::runtime_error& err)
567 PWARN(
"Error processing year-month-day %d-%d-%d: %s",
568 year, month, day, err.what());
582 strncpy(buff, str.c_str(), len);
583 if (str.length() >= len)
584 buff[len - 1] =
'\0';
586 catch(std::logic_error& err)
588 PWARN(
"Error processing time64 %" PRId64
": %s", t, err.what());
590 catch(std::runtime_error& err)
592 PWARN(
"Error processing time64 %" PRId64
": %s", t, err.what());
601 g_date_clear (&date, 1);
604 g_date_get_day(&date),
605 g_date_get_month(&date),
606 g_date_get_year(&date) );
613 memset (buff, 0,
sizeof (buff));
615 return g_strdup (buff);
618 static icu::DateIntervalFormat*
619 get_icu_date_interval_formatter ()
621 static std::unique_ptr<icu::DateIntervalFormat> difmt;
624 auto locale = icu::Locale::getDefault();
625 UErrorCode status = U_ZERO_ERROR;
626 difmt.reset(icu::DateIntervalFormat::createInstance(UDAT_YEAR_NUM_MONTH_DAY, locale, status));
627 if (U_FAILURE(status))
629 PWARN (
"icu::DateIntervalFormat::createInstance error %d", status);
637 icu_date_interval_format (
time64 from_date,
time64 to_date)
639 auto difmt = get_icu_date_interval_formatter();
643 if (from_date > to_date)
644 std::swap(from_date, to_date);
646 icu::DateInterval interval (from_date * 1000.0, to_date * 1000.0);
647 icu::UnicodeString result;
648 icu::FieldPosition fp;
649 UErrorCode status = U_ZERO_ERROR;
650 difmt->format (&interval, result, fp, status);
651 if (U_FAILURE(status))
653 PWARN(
"Error formatting interval: %d", status);
657 std::string interval_string;
658 result.toUTF8String(interval_string);
660 return g_strdup (interval_string.c_str());
664 gnc_date_interval_format (
time64 from_date,
time64 to_date)
669 rv = icu_date_interval_format (from_date, to_date);
677 rv = g_strdup_printf (gettext(
"%s to %s"), from_buff, to_buff);
688 floordiv(
int a,
int b)
696 return - ((-a - 1) / b) - 1;
705 static inline std::string
706 normalize_format (
const std::string& format)
709 std::string normalized;
711 format.begin(), format.end(), back_inserter(normalized),
713 bool r = (is_pct && (e ==
'E' || e ==
'O' || e ==
'-'));
743 qof_scan_date_internal (
const char *buff,
int *day,
int *month,
int *year,
746 char *dupe, *tmp, *first_field, *second_field, *third_field;
747 int iday, imonth, iyear;
748 int now_day, now_month, now_year;
752 if (!buff)
return(FALSE);
757 || strptime (buff,
"%Y-%m-%d", &utc))
760 *month = utc.tm_mon + 1;
761 *year = utc.tm_year + 1900;
769 dupe = g_strdup (buff);
772 first_field =
nullptr;
773 second_field =
nullptr;
774 third_field =
nullptr;
779 static const char *delims =
".,-+/\\()년월年月 ";
781 first_field = strtok (tmp, delims);
784 second_field = strtok (
nullptr, delims);
787 third_field = strtok (
nullptr, delims);
797 now_day = now->tm_mday;
798 now_month = now->tm_mon + 1;
799 now_year = now->tm_year + 1900;
808 switch (which_format)
815 memset(&thetime, -1,
sizeof(
struct tm));
816 char *strv = strptime (buff, normalize_format(GNC_D_FMT).c_str(),
825 iyear = thetime.tm_year + 1900;
826 iday = thetime.tm_mday;
827 imonth = thetime.tm_mon + 1;
829 else if (second_field)
832 if (thetime.tm_year == -1)
835 iday = thetime.tm_mday;
836 imonth = thetime.tm_mon + 1;
838 else if (thetime.tm_mon != -1)
841 imonth = atoi(first_field);
842 iday = atoi(second_field);
847 iday = atoi(first_field);
848 imonth = atoi(second_field);
851 else if (first_field)
853 iday = atoi(first_field);
861 iday = atoi(first_field);
862 imonth = atoi(second_field);
863 iyear = atoi(third_field);
865 else if (second_field)
867 iday = atoi(first_field);
868 imonth = atoi(second_field);
870 else if (first_field)
872 iday = atoi(first_field);
878 iyear = atoi(first_field);
879 imonth = atoi(second_field);
880 iday = atoi(third_field);
882 else if (second_field)
884 imonth = atoi(first_field);
885 iday = atoi(second_field);
887 else if (first_field)
889 iday = atoi(first_field);
896 imonth = atoi(first_field);
897 iday = atoi(second_field);
898 iyear = atoi(third_field);
900 else if (second_field)
902 imonth = atoi(first_field);
903 iday = atoi(second_field);
905 else if (first_field)
907 iday = atoi(first_field);
914 if ((imonth == 0) || (iday == 0))
917 if ((12 < imonth) || (31 < iday))
932 if ((which_format != prevQofDateFormat) &&
933 qof_scan_date_internal(buff, day, month, year, prevQofDateFormat))
937 if ((12 < imonth) && (12 >= iday))
967 iyear = now_year - floordiv(imonth - now_month +
968 dateCompletionBackMonths, 12);
975 iyear += ((int) ((now_year + 50 - iyear) / 100)) * 100;
979 tm.tm_year = iyear - 1900;
980 tm.tm_mon = imonth - 1;
982 normalize_struct_tm(&tm);
984 if (year) *year = tm.tm_year + 1900;
985 if (month) *month = tm.tm_mon + 1;
986 if (day) *day = tm.tm_mday;
993 return qof_scan_date_internal(buff, day, month, year, dateFormat);
1001 static char locale_separator =
'\0';
1015 if (locale_separator !=
'\0')
1016 return locale_separator;
1027 auto normalized_fmt =
1029 qof_strftime(
string,
sizeof(
string), normalized_fmt.c_str(), &tm);
1031 for (s =
string; *s !=
'\0'; s++)
1033 return (locale_separator = *s);
1043 qof_time_format_from_utf8(
const gchar *utf8_format)
1046 GError *error =
nullptr;
1048 retval = g_locale_from_utf8(utf8_format, -1,
nullptr,
nullptr, &error);
1052 g_warning(
"Could not convert format '%s' from UTF-8: %s", utf8_format,
1054 g_error_free(error);
1060 qof_formatted_time_to_utf8(
const gchar *locale_string)
1063 GError *error =
nullptr;
1065 retval = g_locale_to_utf8(locale_string, -1,
nullptr,
nullptr, &error);
1069 g_warning(
"Could not convert '%s' to UTF-8: %s", locale_string,
1071 g_error_free(error);
1078 qof_format_time(
const gchar *format,
const struct tm *tm)
1080 gchar *locale_format, *tmpbuf, *retval;
1081 gsize tmplen, tmpbufsize;
1083 g_return_val_if_fail(format, 0);
1084 g_return_val_if_fail(tm, 0);
1086 locale_format = qof_time_format_from_utf8(format);
1090 tmpbufsize = MAX(128, strlen(locale_format) * 2);
1093 tmpbuf =
static_cast<gchar*
>(g_malloc(tmpbufsize));
1099 tmplen = strftime(tmpbuf, tmpbufsize, locale_format, tm);
1101 if (tmplen == 0 && tmpbuf[0] !=
'\0')
1106 if (tmpbufsize > 65536)
1108 g_warning(
"Maximum buffer size for qof_format_time " 1109 "exceeded: giving up");
1110 g_free(locale_format);
1120 g_free(locale_format);
1122 retval = qof_formatted_time_to_utf8(tmpbuf);
1129 qof_strftime(gchar *buf, gsize max,
const gchar *format,
const struct tm *tm)
1131 gsize convlen, retval;
1134 g_return_val_if_fail(buf, 0);
1135 g_return_val_if_fail(max > 0, 0);
1136 g_return_val_if_fail(format, 0);
1137 g_return_val_if_fail(tm, 0);
1139 convbuf = qof_format_time(format, tm);
1146 convlen = strlen(convbuf);
1151 gchar *end = g_utf8_find_prev_char(convbuf, convbuf + max);
1152 g_assert(end !=
nullptr);
1153 convlen = end - convbuf;
1163 memcpy(buf, convbuf, convlen);
1164 buf[convlen] =
'\0';
1177 return g_strdup(timestamp.c_str());
1187 #define ISO_DATE_FORMAT "%d-%d-%d %d:%d:%lf%s" 1191 if (!cstr)
return INT64_MAX;
1195 return static_cast<time64>(gncdt);
1197 catch(std::logic_error& err)
1199 PWARN(
"Error processing %s: %s", cstr, err.what());
1202 catch(std::runtime_error& err)
1204 PWARN(
"Error processing time64 %s: %s", cstr, err.what());
1215 if (!buff)
return nullptr;
1221 memset(buff, 0, sstr.length() + 1);
1222 strncpy(buff, sstr.c_str(), sstr.length());
1223 return buff + sstr.length();
1225 catch(std::logic_error& err)
1227 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
1230 catch(std::runtime_error& err)
1232 PWARN(
"Error processing time64 %" PRId64
": %s", time, err.what());
1237 #define THIRTY_TWO_YEARS 0x3c30fc00LL 1240 gnc_dmy2time64_internal (
int day,
int month,
int year, DayPart day_part)
1244 auto date =
GncDate(year, month, day);
1247 catch(
const std::logic_error& err)
1249 PWARN(
"Date computation error from Y-M-D %d-%d-%d: %s",
1250 year, month, day, err.what());
1253 catch(
const std::runtime_error& err)
1255 PWARN(
"Date computation error from Y-M-D %d-%d-%d: %s",
1256 year, month, day, err.what());
1264 return gnc_dmy2time64_internal (day, month, year, DayPart::start);
1270 return gnc_dmy2time64_internal (day, month, year, DayPart::end);
1276 return gnc_dmy2time64_internal (day, month, year, DayPart::neutral);
1288 g_date_clear (&result, 1);
1290 auto date = time.date().year_month_day();
1291 g_date_set_dmy (&result, date.day, static_cast<GDateMonth>(date.month),
1293 g_assert(g_date_valid (&result));
1300 GDate* rv = g_date_new ();
1308 g_return_if_fail (gd !=
nullptr);
1310 g_date_set_dmy (gd, ymd.day, static_cast<GDateMonth>(ymd.month), ymd.year);
1318 g_date_set_dmy (gd, tm.tm_mday,
1319 static_cast<GDateMonth>(tm.tm_mon + 1),
1326 g_date_get_month(&d),
1327 g_date_get_year(&d));
1331 gnc_tm_get_day_start (
struct tm *tm,
time64 time_val)
1336 gnc_tm_set_day_start(tm);
1342 auto time_val{gnc_dmy2time64_internal(tm->tm_mday, tm->tm_mon + 1,
1343 tm->tm_year + 1900, DayPart::neutral)};
1348 gnc_tm_get_day_neutral (
struct tm *tm,
time64 time_val)
1357 gnc_tm_get_day_end (
struct tm *tm,
time64 time_val)
1362 gnc_tm_set_day_end(tm);
1371 gnc_tm_get_day_start(&tm, time_val);
1381 return gnc_dmy2time64_internal(tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900,
1391 gnc_tm_get_day_end(&tm, time_val);
1401 gnc_tm_get_day_start(tm,
gnc_time(
nullptr));
1407 gnc_tm_get_day_neutral(tm,
gnc_time(
nullptr));
1413 gnc_tm_get_day_end(tm,
gnc_time(
nullptr));
1421 gnc_tm_get_day_start(&tm,
gnc_time(
nullptr));
1430 gnc_tm_get_day_end(&tm,
gnc_time(
nullptr));
1440 memset(buf, 0, buf_len);
1441 memset(&my_tm, 0,
sizeof(
struct tm));
1442 my_tm.tm_wday = dow;
1452 time64_boxed_copy_func (
Time64 *in_time64)
1455 *newvalue = *in_time64;
1461 time64_boxed_free_func (
Time64 *in_time64)
1466 G_DEFINE_BOXED_TYPE (
Time64,
time64, time64_boxed_copy_func, time64_boxed_free_func)
1473 return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
1479 gint val = (g_date_get_year( (GDate*)gd ) * 10000)
1480 + (g_date_get_month( (GDate*)gd ) * 100)
1481 + g_date_get_day( (GDate*)gd );
1482 return g_int_hash( &val );
1494 g_date_to_struct_tm (date, &stm);
1508 g_date_to_struct_tm(date, &stm);
1526 g_date_set_day(date, 1);
1540 g_date_set_day(date, 1);
1541 g_date_add_months(date, 1);
1544 g_date_subtract_days(date, 1);
1557 g_date_set_day(date, 1);
1558 g_date_subtract_months(date, 1);
1572 g_date_set_day(date, 1);
1573 g_date_subtract_days(date, 1);
1584 g_date_set_day(date, 1);
1587 months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
1588 g_date_subtract_months(date, months);
1594 const GDateMonth months[] = {G_DATE_MARCH, G_DATE_JUNE,
1595 G_DATE_SEPTEMBER, G_DATE_DECEMBER};
1596 const GDateDay days[] = {31, 30, 30, 31};
1597 int quarter = (g_date_get_month (date) - 1) / 3;
1599 g_date_set_month (date, months[quarter]);
1600 g_date_set_day (date, days[quarter]);
1606 g_date_subtract_months(date, 3);
1613 g_date_subtract_months(date, 3);
1622 g_date_set_month(date, G_DATE_JANUARY);
1623 g_date_set_day(date, 1);
1629 g_date_set_month(date, G_DATE_DECEMBER);
1630 g_date_set_day(date, 31);
1637 g_date_subtract_years(date, 1);
1644 g_date_subtract_years(date, 1);
1651 const GDate *fy_end)
1656 g_return_if_fail(date);
1657 g_return_if_fail(fy_end);
1661 g_date_set_year(&temp, g_date_get_year(date));
1664 new_fy = (g_date_compare(date, &temp) > 0);
1668 g_date_add_days(date, 1);
1670 g_date_subtract_years(date, 1);
1675 const GDate *fy_end)
1680 g_return_if_fail(date);
1681 g_return_if_fail(fy_end);
1685 g_date_set_year(&temp, g_date_get_year(date));
1688 new_fy = (g_date_compare(date, &temp) > 0);
1693 g_date_add_years(date, 1);
1698 const GDate *fy_end)
1700 g_return_if_fail(date);
1701 g_return_if_fail(fy_end);
1704 g_date_subtract_years(date, 1);
1709 const GDate *fy_end)
1711 g_return_if_fail(date);
1712 g_return_if_fail(fy_end);
1715 g_date_subtract_years(date, 1);
1719 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...
gnc_ymd year_month_day() const
Get the year, month, and day from the date as a gnc_ymd.
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 (deprecated)
std::string format(const char *format) const
Format the GncDateTime into a std::string.
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 time
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
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...