/* nth_weekday_compare() is a helper function for the PERIOD_{NTH,LAST}_WEEKDAY case. It returns the offset, in days, from 'next' to the nth weekday specified by the 'start' date (and the period type), in the same month as 'next'. A negative offset means earlier than 'next'; a zero offset means 'next' *is* the nth weekday in that month; a positive offset means later than 'next'. */ static gint nth_weekday_compare(const GDate *start, const GDate *next, PeriodType pt) { GDateDay sd, nd; gint matchday, dim, week; nd = g_date_get_day(next); sd = g_date_get_day(start); week = sd / 7 > 3 ? 3 : sd / 7; if (week > 0 && sd % 7 == 0 && sd != 28) --week; /* matchday has a week part, capped at 3 weeks, and a day part, capped at 7 days, so max(matchday) == 3*7 + 7 == 28. */ matchday = 7 * week + //((sd - 1) / 7 == 4 ? 3 : (sd - 1) / 7) + (nd - g_date_get_weekday(next) + g_date_get_weekday(start) + 7) % 7; /* That " + 7" is to avoid negative modulo in case nd < 6. */ dim = g_date_get_days_in_month( g_date_get_month(next), g_date_get_year(next)); if ((dim - matchday) >= 7 && pt == PERIOD_LAST_WEEKDAY) matchday += 7; /* Go to the fifth week, if needed */ if (pt == PERIOD_NTH_WEEKDAY && (matchday % 7 == 0)) matchday += 7; return matchday - nd; /* Offset from 'next' to matchday */ }
static void show_book_details (AcctPeriodInfo *info) { QofBook *currbook; char close_date_str[MAX_DATE_LENGTH]; char prev_close_date_str[MAX_DATE_LENGTH]; const char *period_text; char *str; const char *cstr; int ntrans, nacc; ENTER ("info=%p", info); /* Tell user about how the previous book closing went. */ cstr = get_close_status_str (info); gtk_label_set_text (info->close_results, cstr); info->close_status = -1; /* 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); qof_print_date_dmy_buff (close_date_str, MAX_DATE_LENGTH, g_date_get_day(&info->closing_date), g_date_get_month(&info->closing_date), g_date_get_year(&info->closing_date)); currbook = gnc_get_current_book(); ntrans = get_num_xactions_before_date(currbook, gnc_timet_get_day_end_gdate (&info->closing_date)); nacc = gnc_account_n_descendants (gnc_book_get_root_account (currbook)); /* Display the book info */ period_text = _("You have asked for a book to be created. This book " "will contain all transactions up to midnight %s " "(for a total of %d transactions spread over %d accounts). " "Click on 'Forward' to create this book. " "Click on 'Back' to adjust the dates."); str = g_strdup_printf (period_text, close_date_str, ntrans, nacc); gtk_label_set_text (info->book_details, str); g_free (str); /* Weird bug fix ! */ gtk_widget_show (GTK_WIDGET (info->book_details)); /* Create default settings for the title, notes fields */ qof_print_date_dmy_buff (prev_close_date_str, MAX_DATE_LENGTH, g_date_get_day(&info->prev_closing_date), g_date_get_month(&info->prev_closing_date), g_date_get_year(&info->prev_closing_date)); str = g_strdup_printf (_("Period %s - %s"), prev_close_date_str, close_date_str); gtk_entry_set_text (info->book_title, str); xxxgtk_textview_set_text (info->book_notes, str); g_free (str); }
void calendar_display_ics (GDate *date, GUI *appGUI) { gchar *ical_name, *ical_filename; GtkTreeIter iter; gboolean flag, desc_flag, year_flag; GSList *node, *node2; struct ics_file *entry; struct ics_entry *item; gint i, j, k; for (i = 0, node = appGUI->cal->ics_files_list; node != NULL; node = node->next, i++) { entry = g_slist_nth_data (appGUI->cal->ics_files_list, i); k = 0; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(appGUI->opt->calendar_ical_files_store), &iter, NULL, k++)) { gtk_tree_model_get(GTK_TREE_MODEL(appGUI->opt->calendar_ical_files_store), &iter, ICAL_COLUMN_NAME, &ical_name, ICAL_COLUMN_FILENAME, &ical_filename, ICAL_COLUMN_VALID_FLAG, &flag, ICAL_COLUMN_ENABLE_DESC, &desc_flag, ICAL_COLUMN_USE_YEAR, &year_flag, -1); if (!strcmp(entry->filename, ical_filename)) break; g_free (ical_name); g_free (ical_filename); } if (ical_filename != NULL) { g_free (ical_filename); } if (entry->entries_list != NULL && flag == TRUE) { for (j = 0, node2 = entry->entries_list; node2 != NULL; node2 = node2->next, j++) { item = g_slist_nth_data (entry->entries_list, j); if (year_flag == TRUE) { if (g_date_get_day (date) == item->date.day && g_date_get_month (date) == item->date.month && g_date_get_year (date) == item->date.year) { add_ics_entry_to_day_info_panel (ical_name, item->summary, item->description, desc_flag, appGUI); break; } } else if (g_date_get_day (date) == item->date.day && g_date_get_month (date) == item->date.month) { add_ics_entry_to_day_info_panel (ical_name, item->summary, item->description, desc_flag, appGUI); break; } } } if (ical_name != NULL) { g_free (ical_name); } } }
static void _monthly_append_when(Recurrence *r, GString *buf) { GDate date = recurrenceGetDate(r); if (recurrenceGetPeriodType(r) == PERIOD_LAST_WEEKDAY) { gchar day_name_buf[abbrev_day_name_bufsize]; gnc_dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7); /* translators: %s is an already-localized form of the day of the week. */ g_string_append_printf(buf, _("last %s"), day_name_buf); } else if (recurrenceGetPeriodType(r) == PERIOD_NTH_WEEKDAY) { int week = 0; int day_of_month_index = 0; const char *numerals[] = {N_("1st"), N_("2nd"), N_("3rd"), N_("4th")}; gchar day_name_buf[abbrev_day_name_bufsize]; gnc_dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7); day_of_month_index = g_date_get_day(&date) - 1; week = day_of_month_index / 7 > 3 ? 3 : day_of_month_index / 7; if (week > 0 && day_of_month_index % 7 == 0) --week; /* translators: %s is the string 1st, 2nd, 3rd and so on, and * %s is an already-localized form of the day of the week. */ g_string_append_printf(buf, _("%s %s"), _(numerals[week]), day_name_buf); } else { /* translators: %u is the day of month */ g_string_append_printf(buf, "%u", g_date_get_day(&date)); } }
/** * itl_HijriGreg: * * @DateIn: (in): Date struct to convert * @Hijri: (in): DateIn date type; TRUE=Hijri, FALSE=Gregorian * @UmmAlQura: (in): TRUE=Use Umm Al-Qura algorithm, FALSE=otherwise * * Convert Hijri date to Gregorian date using Umm Ul-Qura algorithm * * Return value: (transfer full): Converted Date struct */ GDate *itl_HijriGreg (GDate *DateIn, gboolean Hijri, gboolean UmmAlQura) { sDate ITLDate; GDate *cdate; int ret; if(Hijri) { if(UmmAlQura) { ret = H2G(&ITLDate, (int) g_date_get_day(DateIn), (int) g_date_get_month(DateIn), (int) g_date_get_year(DateIn)); } else { ret = h_date(&ITLDate, (int) g_date_get_day(DateIn), (int) g_date_get_month(DateIn), (int) g_date_get_year(DateIn)); } } else { if(UmmAlQura) { ret = G2H(&ITLDate, (int) g_date_get_day(DateIn), (int) g_date_get_month(DateIn), (int) g_date_get_year(DateIn)); } else { ret = g_date(&ITLDate, (int) g_date_get_day(DateIn), (int) g_date_get_month(DateIn), (int) g_date_get_year(DateIn)); } } cdate = g_date_new_dmy(ITLDate.day, ITLDate.month, ITLDate.year); return(cdate); }
GST_END_TEST GST_START_TEST (test_date_tags) { GstTagList *tag_list, *tag_list2; GDate *date, *date2; gchar *str; date = g_date_new_dmy (14, 10, 2005); tag_list = gst_tag_list_new_empty (); gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_DATE, date, NULL); str = gst_tag_list_to_string (tag_list); fail_if (str == NULL); fail_if (strstr (str, "2005-10-14") == NULL); tag_list2 = gst_tag_list_new_from_string (str); fail_if (tag_list2 == NULL); fail_if (!gst_tag_list_get_date (tag_list2, GST_TAG_DATE, &date2)); fail_unless (gst_tag_list_is_equal (tag_list2, tag_list)); gst_tag_list_unref (tag_list2); g_free (str); fail_if (g_date_compare (date, date2) != 0); fail_if (g_date_get_day (date) != 14); fail_if (g_date_get_month (date) != 10); fail_if (g_date_get_year (date) != 2005); fail_if (g_date_get_day (date2) != 14); fail_if (g_date_get_month (date2) != 10); fail_if (g_date_get_year (date2) != 2005); g_date_free (date2); gst_tag_list_unref (tag_list); g_date_free (date); }
void recurrenceSet(Recurrence *r, guint16 mult, PeriodType pt, const GDate *_start, WeekendAdjust wadj) { r->ptype = VALID_PERIOD_TYPE(pt) ? pt : PERIOD_MONTH; r->mult = (pt == PERIOD_ONCE) ? 0 : (mult > 0 ? mult : 1); if (_start && g_date_valid(_start)) { r->start = *_start; } else { gnc_gdate_set_today (&r->start); } /* Some of the unusual period types also specify phase. For those types, we ensure that the start date agrees with that phase. */ switch (r->ptype) { case PERIOD_END_OF_MONTH: g_date_set_day(&r->start, g_date_get_days_in_month (g_date_get_month(&r->start), g_date_get_year(&r->start))); break; case PERIOD_LAST_WEEKDAY: { GDateDay dim; dim = g_date_get_days_in_month(g_date_get_month(&r->start), g_date_get_year(&r->start)); while (dim - g_date_get_day(&r->start) >= 7) g_date_add_days(&r->start, 7); } break; case PERIOD_NTH_WEEKDAY: if ((g_date_get_day(&r->start) - 1) / 7 == 4) /* Fifth week */ r->ptype = PERIOD_LAST_WEEKDAY; break; default: break; } switch (r->ptype) { case PERIOD_MONTH: case PERIOD_END_OF_MONTH: case PERIOD_YEAR: r->wadj = wadj; break; default: r->wadj = WEEKEND_ADJ_NONE; break; } }
static void log_window_updating_calendar_month_cb (GObject *manager, GAsyncResult *result, gpointer user_data) { EmpathyLogWindow *window = user_data; GList *dates; GList *l; guint year_selected; guint month_selected; GError *error = NULL; if (log_window == NULL) return; if (!tpl_log_manager_get_dates_finish (TPL_LOG_MANAGER (manager), result, &dates, &error)) { DEBUG ("Unable to retrieve messages' dates: %s. Aborting", error->message); empathy_chat_view_append_event (window->chatview_find, "Unable to retrieve messages' dates"); g_error_free (error); return; } gtk_calendar_clear_marks (GTK_CALENDAR (window->calendar_chats)); g_object_get (window->calendar_chats, "month", &month_selected, "year", &year_selected, NULL); /* We need this here because it appears that the months start from 0 */ month_selected++; for (l = dates; l; l = l->next) { GDate *date = l->data; if (g_date_get_year (date) == year_selected && g_date_get_month (date) == month_selected) { DEBUG ("Marking date: %04u-%02u-%02u", g_date_get_year (date), g_date_get_month (date), g_date_get_day (date)); gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), g_date_get_day (date)); } } g_list_foreach (dates, (GFunc) g_free, NULL); g_list_free (dates); DEBUG ("Currently showing month %d and year %d", month_selected, year_selected); }
/* * 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); } }
DATE* julian_to_date (guint32 julian_day) { DATE *date; GDate *cdate; date = g_new0 (DATE, 1); if (date == NULL) { return date; } if (g_date_valid_julian(julian_day)) { cdate = g_date_new_julian (julian_day); if (cdate != NULL) { if (g_date_valid (cdate)) { date->year = g_date_get_year (cdate); date->month = g_date_get_month (cdate); date->day = g_date_get_day (cdate); } g_date_free(cdate); } return date; /* you have to free DATE struct after use! */ } else { return NULL; } }
/** * itl_prayer_getNextDayFajr: * * @prayer: (in): an #ItlPrayer * @cdate: (in): Date for which to calculate Fajr for the day after * * This function calculates prayer times for the given date * * Return value: (transfer full): DateTime struct for next day fajr time */ GDateTime * itl_prayer_getNextDayFajr (ItlPrayer *prayer, GDate *cdate) { Date ITLDate; Prayer cPrayer; GDateTime *NextDayFajr; g_return_val_if_fail (GOBJECT_IS_PRAYER (prayer), 0); g_object_ref (prayer); ITLDate.day = g_date_get_day(cdate); ITLDate.month = g_date_get_month(cdate); ITLDate.year = g_date_get_year(cdate); getNextDayFajr (&prayer->priv->loc, &prayer->priv->method, &ITLDate, &cPrayer); NextDayFajr = g_date_time_new_local(ITLDate.year, ITLDate.month, ITLDate.day, cPrayer.hour, cPrayer.minute, cPrayer.second); g_object_unref (prayer); return(NextDayFajr); }
static int _get_monthly_combobox_index(Recurrence *r) { GDate recurrence_date = recurrenceGetDate(r); int week = 0; int day_of_month_index = g_date_get_day(&recurrence_date) - 1; if (recurrenceGetPeriodType(r) == PERIOD_END_OF_MONTH) { day_of_month_index = LAST_DAY_OF_MONTH_OPTION_INDEX; } else if (recurrenceGetPeriodType(r) == PERIOD_LAST_WEEKDAY) { day_of_month_index = LAST_DAY_OF_MONTH_OPTION_INDEX + g_date_get_weekday(&recurrence_date); } else if (recurrenceGetPeriodType(r) == PERIOD_NTH_WEEKDAY) { week = day_of_month_index / 7 > 3 ? 3 : day_of_month_index / 7; if (week > 0 && day_of_month_index % 7 == 0) --week; day_of_month_index = LAST_DAY_OF_MONTH_OPTION_INDEX + 7 + g_date_get_weekday(&recurrence_date) + 7 * week; } /* else { default value } */ return day_of_month_index; }
static void gnc_period_select_set_date_common (GncPeriodSelect *period, const GDate *date) { GncPeriodSelectPrivate *priv; priv = GNC_PERIOD_SELECT_GET_PRIVATE(period); if (date) { if (priv->date_base) g_date_free(priv->date_base); priv->date_base = g_date_new_dmy(g_date_get_day(date), g_date_get_month(date), g_date_get_year(date)); if (priv->date_label == NULL) { priv->date_align = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_alignment_set_padding(GTK_ALIGNMENT(priv->date_align), 0, 0, 6, 0); gtk_box_pack_start(GTK_BOX(period), priv->date_align, TRUE, TRUE, 0); priv->date_label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(priv->date_align), priv->date_label); gtk_widget_show_all(priv->date_align); } gnc_period_sample_update_date_label(period); return; } if (priv->date_base) { g_date_free(priv->date_base); priv->date_base = NULL; gtk_widget_destroy(priv->date_align); priv->date_align = NULL; priv->date_label = NULL; } }
static void addTagToMap(const GstTagList *list, const gchar *tag, gpointer user_data) { QMap<QByteArray, QVariant> *map = reinterpret_cast<QMap<QByteArray, QVariant>* >(user_data); GValue val; val.g_type = 0; gst_tag_list_copy_value(&val,list,tag); switch( G_VALUE_TYPE(&val) ) { case G_TYPE_STRING: { const gchar *str_value = g_value_get_string(&val); map->insert(QByteArray(tag), QString::fromUtf8(str_value)); break; } case G_TYPE_INT: map->insert(QByteArray(tag), g_value_get_int(&val)); break; case G_TYPE_UINT: map->insert(QByteArray(tag), g_value_get_uint(&val)); break; case G_TYPE_LONG: map->insert(QByteArray(tag), qint64(g_value_get_long(&val))); break; case G_TYPE_BOOLEAN: map->insert(QByteArray(tag), g_value_get_boolean(&val)); break; case G_TYPE_CHAR: map->insert(QByteArray(tag), g_value_get_char(&val)); break; case G_TYPE_DOUBLE: map->insert(QByteArray(tag), g_value_get_double(&val)); break; default: // GST_TYPE_DATE is a function, not a constant, so pull it out of the switch if (G_VALUE_TYPE(&val) == GST_TYPE_DATE) { const GDate *date = gst_value_get_date(&val); if (g_date_valid(date)) { int year = g_date_get_year(date); int month = g_date_get_month(date); int day = g_date_get_day(date); map->insert(QByteArray(tag), QDate(year,month,day)); if (!map->contains("year")) map->insert("year", year); } } else if (G_VALUE_TYPE(&val) == GST_TYPE_FRACTION) { int nom = gst_value_get_fraction_numerator(&val); int denom = gst_value_get_fraction_denominator(&val); if (denom > 0) { map->insert(QByteArray(tag), double(nom)/denom); } } break; } g_value_unset(&val); }
static void new_lines_cb (LogviewLog *log, const char **lines, GSList *new_days, GError *error, gpointer user_data) { int i; guint8 day; Day *day_s; GSList *days, *l; for (i = 0; lines[i]; i++) { g_print ("line %d: %s\n", i, lines[i]); } g_print ("outside read, lines no %u\n", logview_log_get_cached_lines_number (log)); days = log_read_dates (lines, logview_log_get_timestamp (log)); g_print ("\ndays %p\n", days); for (l = days; l; l = l->next) { day_s = l->data; g_print ("\nday %u month %u\n", g_date_get_day (day_s->date), g_date_get_month (day_s->date)); } g_object_unref (log); g_main_loop_quit (loop); }
const char* darxen_conversions_format_date_time(GDate *date, int seconds) { int intWeekday; int intMonth; intWeekday = g_date_get_weekday(date) - 1; intMonth = g_date_get_month(date) - 1; if (chrDateTime) g_free(chrDateTime); chrDateTime = g_new0(char, 26); sprintf(chrDateTime, "%s %02i:%02i:%02iZ %i-%s-%i", chrDays[intWeekday], darxen_conversions_time_get_hours(seconds), darxen_conversions_time_get_minutes(seconds), darxen_conversions_time_get_seconds(seconds), g_date_get_day(date), chrMonths[intMonth], g_date_get_year(date) ); return chrDateTime; }
size_t qof_print_gdate( char *buf, size_t len, const GDate *gd ) { return qof_print_date_dmy_buff( buf, len, g_date_get_day(gd), g_date_get_month(gd), g_date_get_year(gd) ); }
static char * gdate_to_char (GDate* date) { return g_strdup_printf ("%04i%02i%02iT000000.0", g_date_get_year (date), g_date_get_month (date), g_date_get_day (date)); }
guint gnc_gdate_hash( gconstpointer gd ) { gint val = (g_date_get_year( (GDate*)gd ) * 10000) + (g_date_get_month( (GDate*)gd ) * 100) + g_date_get_day( (GDate*)gd ); return g_int_hash( &val ); }
static void log_window_chats_get_messages (EmpathyLogWindow *window, GDate *date) { TpAccount *account; gchar *chat_id; gboolean is_chatroom; guint year_selected; guint month_selected; guint day; if (!log_window_chats_get_selected (window, &account, &chat_id, &is_chatroom)) { return; } g_signal_handlers_block_by_func (window->calendar_chats, log_window_calendar_chats_day_selected_cb, window); /* Either use the supplied date or get the last */ if (date == NULL) { /* Get a list of dates and show them on the calendar */ tpl_log_manager_get_dates_async (window->log_manager, account, chat_id, is_chatroom, log_manager_got_dates_cb, (gpointer) window); /* signal unblocked at the end of the CB flow */ } else { day = g_date_get_day (date); gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats), &year_selected, &month_selected, NULL); month_selected++; if (g_date_get_year (date) != year_selected && g_date_get_month (date) != month_selected) { day = 0; } gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day); g_signal_handlers_unblock_by_func (window->calendar_chats, log_window_calendar_chats_day_selected_cb, window); } if (date != NULL) { /* Show messages of the selected date */ log_window_get_messages_for_date (window, date); } g_object_unref (account); g_free (chat_id); }
void utl_date_get_dmy (const GDate *date, gint *day, gint *month, gint *year) { g_return_if_fail (g_date_valid (date)); if (day != NULL) *day = g_date_get_day (date); if (month != NULL) *month = g_date_get_month (date); if (year != NULL) *year = g_date_get_year (date); }
guint utl_date_get_current_day (void) { GDate *d = utl_date_new_current (); guint day = g_date_get_day (d); g_date_free (d); return day; }
void hippo_platform_impl_windows_migrate_cookie(const char *from_web_host, const char *to_web_host) { char *username; char *password; // See if we already have a cookie from the new host if (read_ie_login_cookie(to_web_host, &username, &password)) { g_free(username); g_free(password); return; } if (!read_ie_login_cookie(from_web_host, &username, &password)) return; GDate *date = g_date_new(); GTimeVal timeval; g_get_current_time(&timeval); g_date_set_time_val(date, &timeval); g_date_add_days(date, 5 * 365); // 5 years, more or less // Can't use g_date_strftime, since that would be unpredictably located // while we need fixed english-locale DAY, DD-MMM-YYYY HH:MM:SS GMT static const char *days[] = { "Mon", "Tue", "Wed", "The", "Fri", "Sat", "Sun" }; static const char * const months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; char *cookieUTF8 = g_strdup_printf("auth=host=%s&name=%s&password=%s; Path=/; expires = %s, %02d-%s-%04d 00:00:00 GMT", to_web_host, username, password, days[(int)g_date_get_weekday(date) - 1], g_date_get_day(date), months[(int)g_date_get_month(date) - 1], g_date_get_year(date)); g_date_free(date); HippoBSTR cookie; cookie.setUTF8(cookieUTF8, -1); g_free(cookieUTF8); HippoBSTR authUrl; makeAuthUrl(to_web_host, &authUrl); InternetSetCookie(authUrl, NULL, cookie); g_free(username); g_free(password); }
char * gth_datetime_to_exif_date (GthDateTime *dt) { if (gth_datetime_valid (dt)) return g_strdup_printf ("%4d:%02d:%02d %02d:%02d:%02d", g_date_get_year (dt->date), g_date_get_month (dt->date), g_date_get_day (dt->date), dt->time->hour, dt->time->min, dt->time->sec); else if (g_date_valid (dt->date)) return g_strdup_printf ("%4d:%02d:%02d 00:00:00", g_date_get_year (dt->date), g_date_get_month (dt->date), g_date_get_day (dt->date)); else return g_strdup (""); }
static void update_calendar (TpawCalendarButton *self) { if (self->priv->calendar == NULL) return; gtk_calendar_clear_marks (GTK_CALENDAR (self->priv->calendar)); if (self->priv->date == NULL) return; gtk_calendar_select_day (GTK_CALENDAR (self->priv->calendar), g_date_get_day (self->priv->date)); gtk_calendar_select_month (GTK_CALENDAR (self->priv->calendar), g_date_get_month (self->priv->date) - 1, g_date_get_year (self->priv->date)); gtk_calendar_mark_day (GTK_CALENDAR (self->priv->calendar), g_date_get_day (self->priv->date)); }
static gboolean check_conversion (const char * str, Timespec expected_ts) { Timespec ts; int day, month, year; GDate d1, d2; ts = gnc_iso8601_to_timespec_gmt (str); // We test the conversion to GDate against the timespec2dmy // conversion, and also the conversion back to timespec and again // to GDate so that it is still the original GDate gnc_timespec2dmy(ts, &day, &month, &year); d1 = timespec_to_gdate(ts); d2 = timespec_to_gdate(gdate_to_timespec(d1)); if ((g_date_compare(&d1, &d2) != 0) || (g_date_get_day(&d1) != day) || (g_date_get_month(&d1) != month) || (g_date_get_year(&d1) != year)) { fprintf (stderr, "\nmis-converted \"%s\" to GDate. " "Got d1(Y-M-D) = %i-%i-%i, d2(Y-M-D) = %i-%i-%i\n", str, year, month, day, g_date_get_year(&d2), g_date_get_month(&d2), g_date_get_day(&d2)); failure ("misconverted timespec"); return FALSE; } if ((expected_ts.tv_sec != ts.tv_sec) || (expected_ts.tv_nsec != ts.tv_nsec)) { fprintf (stderr, "\nmis-converted \"%s\" to %" G_GUINT64_FORMAT ".%09ld seconds\n" "\twas expecting %" G_GUINT64_FORMAT ".%09ld seconds\n", str, ts.tv_sec, ts.tv_nsec, expected_ts.tv_sec, expected_ts.tv_nsec); failure ("misconverted timespec"); return FALSE; } success ("good conversion"); return TRUE; }
static gboolean is_ambiguous_relative(const GDate *date) { GDateDay d; guint8 dim; d = g_date_get_day(date); dim = g_date_get_days_in_month( g_date_get_month(date), g_date_get_year(date)); return ((d - 1) / 7 == 3) && (dim - d < 7); }
static void xform_from_g_date(const GValue *src_value, GValue *dest_value) { MalgtkDate *d = malgtk_date_new(); const GDate *src = g_value_get_boxed(src_value); malgtk_date_set_dmy(d, g_date_get_day(src), g_date_get_month(src), g_date_get_year(src)); g_value_take_boxed(dest_value, d); }
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) ); }
void utl_date_get_current_dmy (gint *day, gint *month, gint *year) { GDate *d = utl_date_new_current (); if (day != NULL) *day = g_date_get_day (d); if (month != NULL) *month = g_date_get_month (d); if (year != NULL) *year = g_date_get_year (d); g_date_free (d); }