static getEndTuple sxftd_get_end_info(SXFromTransInfo *sxfti) { getEndTuple retval; retval.type = BAD_END; g_date_clear( &(retval.end_date), 1 ); retval.n_occurrences = 0; if (gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxfti->ne_but))) { retval.type = NEVER_END; return retval; } if (gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxfti->ed_but))) { time64 end_tt; retval.type = END_ON_DATE; g_date_clear( &(retval.end_date), 1 ); end_tt = gnc_date_edit_get_date(sxfti->endDateGDE); gnc_gdate_set_time64( &(retval.end_date), end_tt); return retval; } if (gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxfti->oc_but) )) { gchar *text, *endptr; guint n_occs; text = gtk_editable_get_chars(GTK_EDITABLE(sxfti->n_occurences), 0, -1); if (text == NULL || strlen(text) == 0) { n_occs = 0; } else { n_occs = strtoul(text, &endptr, 10); if ( !endptr ) { n_occs = -1; } } g_free(text); retval.type = END_AFTER_N_OCCS; retval.n_occurrences = n_occs; return retval; } return retval; }
/* * Validates the given date or initializes it with the current date */ static void init_dmy (guint year, guint month, guint day, guint *d, guint *m, guint *y) { g_assert (d != NULL); g_assert (m != NULL); g_assert (y != NULL); GDate date; /* Initialize the date with a valid selected date */ if (g_date_valid_dmy (day, month, year)) { *d = day; *m = month; *y = year; } else { /* If selected date is invalid initialize the date with current date */ g_date_clear (&date, 1); g_date_set_time (&date, time (NULL)); *d = g_date_get_day (&date); *m = g_date_get_month (&date); *y = g_date_get_year (&date); } }
/** * Update start date... right now we always base this off the transaction * start date, but ideally we want to respect what the user has in the field, * somehow. **/ static void sxftd_freq_combo_changed( GtkWidget *w, gpointer user_data ) { SXFromTransInfo *sxfti = (SXFromTransInfo*)user_data; GDate date, nextDate; time_t tmp_tt; struct tm *tmpTm; GList *schedule = NULL; tmp_tt = xaccTransGetDate( sxfti->trans ); g_date_set_time_t( &date, tmp_tt ); g_date_clear(&nextDate, 1); sxftd_update_schedule(sxfti, &date, &schedule); recurrenceListNextInstance(schedule, &date, &nextDate); tmpTm = g_new0( struct tm, 1 ); g_date_to_struct_tm( &nextDate, tmpTm ); tmp_tt = mktime( tmpTm ); g_free( tmpTm ); gnc_date_edit_set_time( sxfti->startDateGDE, tmp_tt ); recurrenceListFree(&schedule); sxftd_update_example_cal( sxfti ); }
guint g_date_sunday_week_of_year (GDate *d) { GDateWeekday wd; guint day; GDate first; g_return_val_if_fail (d != NULL, 0); g_return_val_if_fail (g_date_valid (d), 0); if (!d->dmy) { g_date_update_dmy (d); } g_return_val_if_fail (d->dmy, 0); g_date_clear (&first, 1); g_date_set_dmy (&first, 1, 1, d->year); wd = g_date_weekday (&first); if (wd == 7) wd = 0; /* make Sunday day 0 */ day = g_date_day_of_year (d) - 1; return ((day + wd)/7U + (wd == 0 ? 1 : 0)); }
/* Like g_date_add_years, but... * * 1. Do not spew criticals. * 2. Number of years is signed. */ void gnm_date_add_years (GDate *d, int n) { if (!g_date_valid (d)) return; if (n >= 0) { int m = 65535 - g_date_get_year (d); if (n > m) goto bad; g_date_add_years (d, n); } else { int m = g_date_get_year (d) - 1; if (m + n <= 0) goto bad; g_date_subtract_years (d, -n); } return; bad: g_date_clear (d, 1); }
static gboolean ap_validate_menu (GnomeDruidPage *druidpage, GtkWidget *druid, gpointer user_data) { GDate date_now; AcctPeriodInfo *info = user_data; ENTER("info=%p", info); /* Pull info from widget, push into freq spec */ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date); recurrenceListFree(&info->period); gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date); if (0 <= g_date_compare(&info->prev_closing_date, &info->closing_date)) { const char *msg = _("You must select closing date that " "is greater than the closing date " "of the previous book."); gnc_error_dialog (info->window, "%s", msg); return TRUE; } g_date_clear (&date_now, 1); g_date_set_time_t (&date_now, time(NULL)); if (0 < g_date_compare(&info->closing_date, &date_now)) { const char *msg = _("You must select closing date " "that is not in the future."); gnc_error_dialog (info->window, "%s", msg); return TRUE; } return FALSE; }
/* Like g_date_add_months, but... * * 1. Do not spew criticals. * 2. Number of months is signed. */ void gnm_date_add_months (GDate *d, int n) { if (!g_date_valid (d)) return; if (n >= 0) { int m = (65535 - g_date_get_year (d)) * 12 + (12 - g_date_get_month (d)); if (n > m) goto bad; g_date_add_months (d, n); } else { int m = (g_date_get_year (d) - 1) * 12 + (g_date_get_month (d) - 1); if (m + n <= 0) goto bad; g_date_subtract_months (d, -n); } return; bad: g_date_clear (d, 1); }
void gnm_date_add_days (GDate *d, int n) { if (!g_date_valid (d)) return; if (n >= 0) { guint32 lim = 23936166; /* 31-Dec-65535 */ guint32 j = g_date_get_julian (d); if (j > lim || (unsigned)n > lim - j) goto bad; g_date_add_days (d, n); } else { int m = g_date_get_julian (d) - 1; if (m + n <= 0) goto bad; g_date_subtract_days (d, -n); } return; bad: g_date_clear (d, 1); }
void recurrenceListNextInstance(const GList *rlist, const GDate *ref, GDate *next) { const GList *iter; GDate nextSingle; /* The next date for an individual recurrence */ g_date_clear(next, 1); // empty rlist = no recurrence if (rlist == NULL) { return; } g_return_if_fail(ref && next && g_date_valid(ref)); for (iter = rlist; iter; iter = iter->next) { const Recurrence *r = iter->data; recurrenceNextInstance(r, ref, &nextSingle); if (!g_date_valid(&nextSingle)) continue; if (g_date_valid(next)) g_date_order(next, &nextSingle); /* swaps dates if needed */ else *next = nextSingle; /* first date is always earliest so far */ } }
gboolean ap_validate_menu (GtkAssistant *assistant, gpointer user_data) { GDate date_now; AcctPeriodInfo *info = user_data; ENTER("info=%p", info); /* Pull info from widget, push into freq spec */ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date); recurrenceListFree(&info->period); gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date); if (0 <= g_date_compare(&info->prev_closing_date, &info->closing_date)) { /* Closing date must be greater than closing date of previous book */ return FALSE; } g_date_clear (&date_now, 1); gnc_gdate_set_today (&date_now); if (0 < g_date_compare(&info->closing_date, &date_now)) { /* Closing date must be in the future */ return FALSE; } return TRUE; }
GncSxInstanceModel* gnc_sx_get_current_instances(void) { GDate *now = g_date_new(); g_date_clear(now, 1); g_date_set_time_t(now, time(NULL)); return gnc_sx_get_instances(now, FALSE); }
static void gnc_sx_instance_model_init(GTypeInstance *instance, gpointer klass) { GncSxInstanceModel *inst = (GncSxInstanceModel*)instance; g_date_clear(&inst->range_end, 1); inst->sx_instance_list = NULL; inst->qof_event_handler_id = qof_event_register_handler(_gnc_sx_instance_event_handler, inst); }
static void gnc_schedxaction_init(SchedXaction* sx) { sx->schedule = NULL; g_date_clear( &sx->last_date, 1 ); g_date_clear( &sx->start_date, 1 ); g_date_clear( &sx->end_date, 1 ); sx->enabled = 1; sx->num_occurances_total = 0; sx->autoCreateOption = FALSE; sx->autoCreateNotify = FALSE; sx->advanceCreateDays = 0; sx->advanceRemindDays = 0; sx->instance_num = 0; sx->deferredList = NULL; }
void gth_datetime_from_gdate (GthDateTime *dt, GDate *date) { if (date != NULL) *dt->date = *date; else g_date_clear (dt->date, 1); gth_time_clear (dt->time); }
static void prepare_remarks (AcctPeriodInfo *info) { int nperiods; GDate period_begin, period_end, date_now; const char *remarks_text; char * str; ENTER ("info=%p", info); /* Pull info from widget, push into freq spec */ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date); recurrenceListFree(&info->period); gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date); /* Count the number of periods that would be generated. */ g_date_clear (&period_begin, 1); g_date_clear (&period_end, 1); g_date_clear (&date_now, 1); nperiods = 0; period_end = info->closing_date; g_date_set_time_t (&date_now, time(NULL)); while (0 > g_date_compare(&period_end, &date_now )) { nperiods ++; PINFO ("period=%d end date=%d/%d/%d", nperiods, g_date_get_month(&period_end), g_date_get_day(&period_end), g_date_get_year(&period_end)); period_begin = period_end; recurrenceListNextInstance(info->period, &period_begin, &period_end); } /* Display the results */ remarks_text = _("The earliest transaction date found in this book is %s. " "Based on the selection made above, this book will be split " "into %d books. Click on 'Forward' to start closing the " "earliest book."); str = g_strdup_printf (remarks_text, info->earliest_str, nperiods); gtk_label_set_text (info->period_remarks, str); g_free (str); }
GDate xaccSchedXactionGetNextInstance (const SchedXaction *sx, SXTmpStateData *tsd) { GDate prev_occur, next_occur; g_date_clear( &prev_occur, 1 ); if ( tsd != NULL ) prev_occur = tsd->last_date; /* If prev_occur is in the "cleared" state and sx->start_date isn't, then * we're at the beginning. We want to pretend prev_occur is the day before * the start_date in case the start_date is today so that the SX will fire * today. If start_date isn't valid either then the SX will fire anyway, no * harm done. */ if (! g_date_valid( &prev_occur ) && g_date_valid(&sx->start_date)) { /* We must be at the beginning. */ prev_occur = sx->start_date; g_date_subtract_days( &prev_occur, 1 ); } recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur); if ( xaccSchedXactionHasEndDate( sx ) ) { const GDate *end_date = xaccSchedXactionGetEndDate( sx ); if ( g_date_compare( &next_occur, end_date ) > 0 ) { g_date_clear( &next_occur, 1 ); } } else if ( xaccSchedXactionHasOccurDef( sx ) ) { if ((tsd && tsd->num_occur_rem == 0) || (!tsd && sx->num_occurances_remain == 0 )) { g_date_clear( &next_occur, 1 ); } } return next_occur; }
gboolean datetime_value_to_g (GDate *res, GnmValue const *v, GODateConventions const *conv) { int serial = datetime_value_to_serial (v, conv); if (serial == G_MAXINT) { g_date_clear (res, 1); return FALSE; } go_date_serial_to_g (res, serial, conv); return g_date_valid (res); }
GDate kvp_value_get_gdate(const KvpValue * value) { GDate date; g_date_clear(&date, 1); if (!value) return date; if (value->type == KVP_TYPE_GDATE) return value->value.gdate; else return date; }
size_t qof_print_gdate( char *buf, size_t len, const GDate *gd ) { GDate date; g_date_clear (&date, 1); date = *gd; return qof_print_date_dmy_buff( buf, len, g_date_get_day(&date), g_date_get_month(&date), g_date_get_year(&date) ); }
MrpTime * mrp_time2_new (void) { MrpTime *t; t = g_new0 (MrpTime, 1); g_date_clear (&t->date, 1); return t; }
void gnc_date_edit_get_gdate (GNCDateEdit *gde, GDate *date) { time64 t; g_return_if_fail (gde && date); g_return_if_fail (GNC_IS_DATE_EDIT (gde)); t = gnc_date_edit_get_date(gde); g_date_clear (date, 1); gnc_gdate_set_time64 (date, t); }
/* The GDate setter functions all in the end use g_date_set_time_t, * which in turn relies on localtime and is therefore subject to the * 2038 bug. */ GDate timespec_to_gdate (Timespec ts) { GDate result; gint day, month, year; g_date_clear (&result, 1); gnc_timespec2dmy (ts, &day, &month, &year); g_date_set_dmy (&result, day, static_cast<GDateMonth>(month), year); g_assert(g_date_valid (&result)); return result; }
/* The GDate setter functions all in the end use g_date_set_time_t, * which in turn relies on localtime and is therefore subject to the * 2038 bug. */ GDate timespec_to_gdate (Timespec ts) { GDate result; g_date_clear (&result, 1); GncDateTime time(ts.tv_sec); auto date = time.date().year_month_day(); g_date_set_dmy (&result, date.day, static_cast<GDateMonth>(date.month), date.year); g_assert(g_date_valid (&result)); return result; }
GncDenseCalStore* gnc_dense_cal_store_new(int num_marks) { GncDenseCalStore *model = g_object_new(GNC_TYPE_DENSE_CAL_STORE, NULL); model->num_marks = num_marks; model->cal_marks = g_new0(GDate*, num_marks); { int i = 0; for (i = 0; i < model->num_marks; i++) { model->cal_marks[i] = g_date_new(); } } model->num_real_marks = 0; g_date_clear(&model->start_date, 1); gnc_gdate_set_today (&model->start_date); model->end_type = NEVER_END; g_date_clear(&model->end_date, 1); gnc_gdate_set_today (&model->end_date); model->n_occurrences = 0; return model; }
void gth_datetime_from_struct_tm (GthDateTime *dt, struct tm *tm) { if (tm->tm_hour < 0) gth_time_clear (dt->time); else gth_time_set_hms (dt->time, tm->tm_hour, tm->tm_min, tm->tm_sec, 0); if ((tm->tm_year < 0) || (tm->tm_mday < 1) || (tm->tm_mday > 31) || (tm->tm_mon < 0) || (tm->tm_mon > 11)) g_date_clear (dt->date, 1); else g_date_set_dmy (dt->date, tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year); }
static void _fixup_recurrence_start_dates(const GDate *sx_start_date, GList *schedule) { GList *iter; for (iter = schedule; iter != NULL; iter = iter->next) { Recurrence *r; GDate start, next; r = (Recurrence*)iter->data; start = *sx_start_date; g_date_subtract_days(&start, 1); g_date_clear(&next, 1); recurrenceNextInstance(r, &start, &next); g_return_if_fail(g_date_valid(&next)); { gchar date_str[128]; gchar *sched_str; g_date_strftime(date_str, 127, "%x", &next); sched_str = recurrenceToString(r); g_debug("setting recurrence [%s] start date to [%s]", sched_str, date_str); g_free(sched_str); } recurrenceSet(r, recurrenceGetMultiplier(r), recurrenceGetPeriodType(r), &next, recurrenceGetWeekendAdjust(r)); } if (g_list_length(schedule) == 1 && recurrenceGetPeriodType((Recurrence*)g_list_nth_data(schedule, 0)) == PERIOD_ONCE) { char date_buf[128]; Recurrence *fixup = (Recurrence*)g_list_nth_data(schedule, 0); g_date_strftime(date_buf, 127, "%x", sx_start_date); recurrenceSet(fixup, 1, PERIOD_ONCE, sx_start_date, WEEKEND_ADJ_NONE); g_debug("fixed up period=ONCE Recurrence to date [%s]", date_buf); } }
static gint pdbtool_merge(int argc, char *argv[]) { GDate date; GError *error = NULL; GString *merged = NULL; gchar *buff; gboolean ok; if (!merge_dir) { fprintf(stderr, "No directory is specified to merge from\n"); return 1; } if (!patterndb_file) { fprintf(stderr, "No patterndb file is specified to merge to\n"); return 1; } merged = g_string_sized_new(4096); g_date_clear(&date, 1); g_date_set_time_t(&date, time (NULL)); buff = g_markup_printf_escaped("<?xml version='1.0' encoding='UTF-8'?>\n<patterndb version='4' pub_date='%04d-%02d-%02d'>", g_date_get_year(&date), g_date_get_month(&date), g_date_get_day(&date)); g_string_append(merged, buff); g_free(buff); ok = pdbtool_merge_dir(merge_dir, merge_recursive, merged); g_string_append(merged, "</patterndb>\n"); if (ok && !g_file_set_contents(patterndb_file, merged->str, merged->len, &error)) { fprintf(stderr, "Error storing patterndb; filename='%s', errror='%s'\n", patterndb_file, error ? error->message : "Unknown error"); ok = FALSE; } g_string_free(merged, TRUE); return ok ? 0 : 1; }
static void g_date_determine_dmy(void) { GDate d; gchar buf[128]; GDateParseTokens testpt; gint i; DB( g_print(" (dateentry) determine dmy\n") ); g_date_clear (&d, 1); /* clear for scratch use */ /* had to pick a random day - don't change this, some strftimes * are broken on some days, and this one is good so far. */ g_date_set_dmy (&d, 4, 7, 1976); g_date_strftime (buf, 127, "%x", &d); g_date_fill_parse_tokens (buf, &testpt); i = 0; while (i < testpt.num_ints) { switch (testpt.n[i]) { case 7: dmy_order[i] = G_DATE_MONTH; break; case 4: dmy_order[i] = G_DATE_DAY; break; //case 76: //using_twodigit_years = TRUE; /* FALL THRU */ case 1976: dmy_order[2] = G_DATE_YEAR; break; } ++i; } DB( g_print(" dmy legend: 0=day, 1=month, 2=year\n") ); DB( g_print(" dmy is: %d %d %d\n", dmy_order[0], dmy_order[1], dmy_order[2]) ); }
/* Set the "show date" setting on a GncPeriodSelect widget. If set * to TRUE then a GtkLabel will be used to show the date * corresponding to the selected time period. */ void gnc_period_select_set_show_date (GncPeriodSelect *period, const gboolean show_date) { GDate date; g_return_if_fail(period != NULL); g_return_if_fail(GNC_IS_PERIOD_SELECT(period)); if (show_date) { g_date_clear(&date, 1); gnc_gdate_set_time64(&date, gnc_time (NULL)); gnc_period_select_set_date_common(period, &date); } else { gnc_period_select_set_date_common(period, NULL); } }
static void gnc_plugin_page_sx_list_cmd_new(GtkAction *action, GncPluginPageSxList *page) { SchedXaction *new_sx; gboolean new_sx_flag = TRUE; new_sx = xaccSchedXactionMalloc(gnc_get_current_book()); { GDate now; Recurrence *r = new Recurrence;//g_new0(Recurrence, 1); g_date_clear(&now, 1); gnc_gdate_set_today (&now); recurrenceSet(r, 1, PERIOD_MONTH, &now, WEEKEND_ADJ_NONE); RecurrenceList_t schedule = gnc_sx_get_schedule(new_sx); schedule.push_back(r); gnc_sx_set_schedule(new_sx, schedule); } gnc_ui_scheduled_xaction_editor_dialog_create(new_sx, new_sx_flag); }