static void
chat_text_maybe_append_date_and_time (EmpathyChatTextView *view,
				      time_t               timestamp)
{
	EmpathyChatTextViewPriv *priv = GET_PRIV (view);
	GDate                   *date, *last_date;
	gboolean                 append_date = FALSE;
	gboolean                 append_time = FALSE;

	/* Get the date from last message */
	last_date = g_date_new ();
	g_date_set_time_t (last_date, priv->last_timestamp);

	/* Get the date of the message we are appending */
	date = g_date_new ();
	g_date_set_time_t (date, timestamp);

	/* If last message was from another day we append date and time */
	if (g_date_compare (date, last_date) > 0) {
		append_date = TRUE;
		append_time = TRUE;
	}
	
	g_date_free (last_date);
	g_date_free (date);

	/* If last message is 'old' append the time */
	if (timestamp - priv->last_timestamp >= TIMESTAMP_INTERVAL) {
		append_time = TRUE;
	}

	if (append_date || (!priv->only_if_date && append_time)) {
		chat_text_view_append_timestamp (view, timestamp, append_date);
	}
}
Exemple #2
0
static
void
convert_timestamp_to_string(
  const time_t timestamp,
  std::string& timestamp_string)
{
  GDate mtime, now;
  gint days_diff;
  struct tm tm_mtime;
  time_t time_now;
  const gchar *format;
  gchar buf[256];

  if (timestamp == 0)
  {
    timestamp_string = "Unknown";
    return;
  }

  localtime_r(&timestamp, &tm_mtime);

  g_date_set_time_t(&mtime, timestamp);
  time_now = time(NULL);
  g_date_set_time_t(&now, time_now);

  days_diff = g_date_get_julian(&now) - g_date_get_julian(&mtime);

  if (days_diff == 0)
  {
    format = "Today at %H:%M";
  }
  else if (days_diff == 1)
  {
    format = "Yesterday at %H:%M";
  }
  else
  {
    if (days_diff > 1 && days_diff < 7)
    {
      format = "%A"; /* Days from last week */
    }
    else
    {
      format = "%x"; /* Any other date */
    }
  }

  if (strftime(buf, sizeof(buf), format, &tm_mtime) != 0)
  {
    timestamp_string = buf;
  }
  else
  {
    timestamp_string = "Unknown";
  }
}
int main (int argc, char **argv)
{
	RBPodcastChannel *data;
	GList *l;
	GDate date = {0,};
	char datebuf[1024];
	GError *error = NULL;

	g_type_init ();
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

	if (argv[2] != NULL && strcmp (argv[2], "--debug") == 0) {
		debug = TRUE;
	}

	data = g_new0 (RBPodcastChannel, 1);
	if (rb_podcast_parse_load_feed (data, argv[1], FALSE, &error) == FALSE) {
		g_warning ("Couldn't parse %s: %s", argv[1], error->message);
		g_clear_error (&error);
		return 1;
	}

	g_date_set_time_t (&date, data->pub_date);
	g_date_strftime (datebuf, 1024, "%F %T", &date);

	g_print ("Podcast title: %s\n", data->title);
	g_print ("Description: %s\n", data->description);
	g_print ("Author: %s\n", data->author);
	g_print ("Date: %s\n", datebuf);
	g_print ("\n");

	for (l = data->posts; l != NULL; l = l->next) {
		RBPodcastItem *item = l->data;

		g_date_set_time_t (&date, item->pub_date);
		g_date_strftime (datebuf, 1024, "%F %T", &date);

		g_print ("\tItem title: %s\n", item->title);
		g_print ("\tURL: %s\n", item->url);
		g_print ("\tAuthor: %s\n", item->author);
		g_print ("\tDate: %s\n", datebuf);
		g_print ("\tDescription: %s\n", item->description);
		g_print ("\n");
	}

	return 0;
}
Exemple #4
0
gboolean gtodo_todo_item_set_stop_date_today(GTodoItem *item)
{
	if(item == NULL) return FALSE;
	if(item->stop == NULL) item->stop = g_date_new();
	g_date_set_time_t(item->stop, time(NULL));
	return TRUE;
}
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;
}
/**
 * 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 );
}
Exemple #7
0
static char *
create_default_label (void)
{
        GDate     *now;
        char       buf [129];
        char      *str;
        char      *last;

        now = g_date_new ();

        g_date_set_time_t (now, time (NULL));

        /*
          translators: see strftime man page for meaning of %b, %d and %Y
          the maximum length for this field is 32 bytes
        */
        g_date_strftime (buf, sizeof (buf), _("Personal Data, %b %d, %Y"), now);

        g_date_free (now);

        /* Cut off at 32 bytes */
        last = str = buf;
        while (*str != 0 &&
               (str - buf) < MAX_ISO_NAME_LEN) {
                last = str;
                str = g_utf8_next_char (str);
        }
        if (*str != 0) {
                *last = 0;
        }

        return g_strdup (buf);
}
Exemple #8
0
/*
** parse the gtkentry and store the GDate
*/
static void gtk_dateentry_entry_new(GtkWidget *gtkentry, gpointer user_data)
{
GtkDateEntry *dateentry = user_data;
const gchar *str;

	DB( g_print(" (dateentry) entry validation\n") );

 	str = gtk_entry_get_text (GTK_ENTRY (dateentry->entry));

	//1) we parse the string according to the locale
	g_date_set_parse (dateentry->date, str);
	if(g_date_valid(dateentry->date) == FALSE)
	{
		//2) give a try to tokens: day, day/month, month/day
		gtk_dateentry_tokens(gtkentry, user_data);
	}

	//3) at last if date still invalid, put today's dateentry_signals
	// we should consider just warn the user here
	if(g_date_valid(dateentry->date) == FALSE)
	{
		/* today's date */
		g_date_set_time_t(dateentry->date, time(NULL));
	}

	gtk_dateentry_datetoentry(dateentry);

}
Exemple #9
0
GDate *
utl_date_new_current (void)
{
	GDate *d = g_date_new ();
	g_date_set_time_t (d, time (NULL));

	return d;
}
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);
}
Exemple #11
0
EphyWebApplication *
ephy_web_application_for_profile_directory (const char *profile_dir)
{
  EphyWebApplication *app;
  char *desktop_file_path;
  const char *id;
  GDesktopAppInfo *desktop_info;
  const char *exec;
  int argc;
  char **argv;
  GFile *file;
  GFileInfo *file_info;
  guint64 created;
  GDate *date;

  id = get_app_id_from_profile_directory (profile_dir);
  if (!id)
    return NULL;

  app = g_new0 (EphyWebApplication, 1);
  app->id = g_strdup (id);

  app->desktop_file = get_app_desktop_filename (id);
  desktop_file_path = g_build_filename (profile_dir, app->desktop_file, NULL);
  desktop_info = g_desktop_app_info_new_from_filename (desktop_file_path);
  if (!desktop_info) {
    ephy_web_application_free (app);
    g_free (desktop_file_path);
    return NULL;
  }

  app->name = g_strdup (g_app_info_get_name (G_APP_INFO (desktop_info)));
  app->icon_url = g_desktop_app_info_get_string (desktop_info, "Icon");
  exec = g_app_info_get_commandline (G_APP_INFO (desktop_info));
  if (g_shell_parse_argv (exec, &argc, &argv, NULL)) {
    app->url = g_strdup (argv[argc - 1]);
    g_strfreev (argv);
  }

  g_object_unref (desktop_info);

  file = g_file_new_for_path (desktop_file_path);

  /* FIXME: this should use TIME_CREATED but it does not seem to be working. */
  file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
  created = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

  date = g_date_new ();
  g_date_set_time_t (date, (time_t)created);
  g_date_strftime (app->install_date, 127, "%x", date);

  g_date_free (date);
  g_object_unref (file);
  g_object_unref (file_info);
  g_free (desktop_file_path);

  return app;
}
Exemple #12
0
/* GTODO_NO_DUE_DATE = no due date */
gint32 gtodo_todo_item_check_due(GTodoItem *item)
{
	GDate *today;
	int i;
	if(item->due == NULL) return GTODO_NO_DUE_DATE;
	today = g_date_new();
	g_date_set_time_t(today, time(NULL));
	i = g_date_days_between(item->due,today);
	g_date_free(today);
	return i;
}
gchar *
get_readable_date (const gchar * format_string,
                   const time_t file_time_raw)
{
	struct tm * file_time;
	gchar * format;
	GDate * today;
	GDate * file_date;
	guint32 file_date_age;
	gchar * readable_date;

	file_time = localtime (&file_time_raw);

	/* Base format of date column on nautilus date_format key */
	if (format_string != NULL) {
		if (strcmp(format_string, GSEARCH_DATE_FORMAT_LOCALE) == 0) {
			return gsearchtool_strdup_strftime ("%c", file_time);
		} else if (strcmp (format_string, GSEARCH_DATE_FORMAT_ISO) == 0) {
			return gsearchtool_strdup_strftime ("%Y-%m-%d %H:%M:%S", file_time);
		}
	}

	file_date = g_date_new_dmy (file_time->tm_mday,
			       file_time->tm_mon + 1,
			       file_time->tm_year + 1900);

	today = g_date_new ();
	g_date_set_time_t (today, time (NULL));

	file_date_age = g_date_get_julian (today) - g_date_get_julian (file_date);

	g_date_free (today);
	g_date_free (file_date);

	if (file_date_age == 0)	{
	/* Translators:  Below are the strings displayed in the 'Date Modified'
	   column of the list view.  The format of this string can vary depending
	   on age of a file.  Please modify the format of the timestamp to match
	   your locale.  For example, to display 24 hour time replace the '%-I'
	   with '%-H' and remove the '%p'.  (See bugzilla report #120434.) */
		format = g_strdup(_("today at %-I:%M %p"));
	} else if (file_date_age == 1) {
		format = g_strdup(_("yesterday at %-I:%M %p"));
	} else if (file_date_age < 7) {
		format = g_strdup(_("%A, %B %-d %Y at %-I:%M:%S %p"));
	} else {
		format = g_strdup(_("%A, %B %-d %Y at %-I:%M:%S %p"));
	}

	readable_date = gsearchtool_strdup_strftime (format, file_time);
	g_free (format);

	return readable_date;
}
static GtkWidget *
yearCriteriaCreateWidget (gboolean *constrain)
{
	GtkWidget *spin;
	GDate date = {0, };
	spin = gtk_spin_button_new_with_range (0.0, (double)G_MAXINT, 1.0);

	/* set it to the current year */
	g_date_set_time_t (&date, time (NULL));
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), g_date_get_year (&date));
	return spin;
}
Exemple #15
0
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
    {
        g_date_set_time_t(&r->start, time(NULL));
    }

    /* 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;
    }
}
Exemple #16
0
/* use this to add an todo item */
GTodoItem * gtodo_client_create_new_todo_item(GTodoClient *cl)
{
	GTodoItem *item = gtodo_client_create_empty_todo_item();
	time_t now = time(NULL);

	/* give an nice "random" id */
	item->id = (guint32)now;
	/* set the start time */
	item->start = g_date_new();
	g_date_set_time_t(item->start, now);
	return item;
}
/*
 * Foreach entry we copy the various individual waypoint properties into the tree store
 *  formatting & converting the internal values into something for display
 */
static void trw_layer_waypoint_list_add ( vik_trw_waypoint_list_t *vtdl,
                                          GtkTreeStore *store,
                                          vik_units_height_t height_units )
{
	GtkTreeIter t_iter;
	VikWaypoint *wpt = vtdl->wpt;
	VikTrwLayer *vtl = vtdl->vtl;

	// Get start date
	gchar time_buf[32];
	time_buf[0] = '\0';
	if ( wpt->has_timestamp ) {

#if GLIB_CHECK_VERSION(2,26,0)
		GDateTime* gdt = g_date_time_new_from_unix_utc ( wpt->timestamp );
		gchar *time = g_date_time_format ( gdt, WAYPOINT_LIST_DATE_FORMAT );
		strncpy ( time_buf, time, sizeof(time_buf) );
		g_free ( time );
		g_date_time_unref ( gdt);
#else
		GDate* gdate_start = g_date_new ();
		g_date_set_time_t ( gdate_start, wpt->timestamp );
		g_date_strftime ( time_buf, sizeof(time_buf), WAYPOINT_LIST_DATE_FORMAT, gdate_start );
		g_date_free ( gdate_start );
#endif
	}

	// NB: doesn't include aggegrate visibility
	gboolean visible = VIK_LAYER(vtl)->visible && wpt->visible;
	visible = visible && vik_trw_layer_get_waypoints_visibility(vtl);

	gdouble alt = wpt->altitude;
	switch (height_units) {
	case VIK_UNITS_HEIGHT_FEET: alt = VIK_METERS_TO_FEET(alt); break;
	default:
		// VIK_UNITS_HEIGHT_METRES: no need to convert
		break;
	}

	gtk_tree_store_append ( store, &t_iter, NULL );
	gtk_tree_store_set ( store, &t_iter,
	                     0, VIK_LAYER(vtl)->name,
	                     1, wpt->name,
	                     2, time_buf,
	                     3, visible,
	                     4, wpt->comment,
	                     5, (gint)round(alt),
	                     6, get_wp_sym_small (wpt->symbol),
	                     TRW_COL_NUM, vtl,
	                     WPT_COL_NUM, wpt,
	                     -1 );
}
Exemple #18
0
G_MODULE_EXPORT void
on_today_clicked (GtkButton *widget, gpointer arg) {
	GDate date;
	GtkStuff *stuff = (GtkStuff*) (arg);

	g_date_set_time_t (&date, time (NULL));
	gtk_calendar_select_month (stuff->calendar,
				g_date_get_month (&date) - 1,
				g_date_get_year (&date));
	gtk_calendar_select_day (stuff->calendar,
				g_date_get_day (&date));
	on_calendar1_day_selected (stuff->calendar, stuff);
}
Exemple #19
0
guint32 get_current_date()
{
	GDate *date = g_date_new ();

	g_date_set_time_t(date, time(NULL));


	guint32 julian = g_date_get_julian (date);

	g_date_free(date);
	
	return julian;
}
Exemple #20
0
/* return an julian date ... -1 = no date set */
guint32 gtodo_todo_item_get_last_edited_date_as_julian(GTodoItem *item)
{
	if(item->last_edited == 0 ) return 1;
	else
	{
		GDate *date = g_date_new();
		guint32 julian=1;
		g_date_set_time_t(date, item->last_edited);
		julian = g_date_get_julian(date);
		g_date_free(date);
		return julian;
	}
}
static void
result_cb (RBPodcastSearch *search, RBPodcastChannel *data)
{
	char datebuf[1025];
	GDate date;

	g_date_set_time_t (&date, data->pub_date);
	g_date_strftime (datebuf, 1024, "%F %T", &date);

	g_print ("Result from %s\n", G_OBJECT_TYPE_NAME (search));

	g_print ("Podcast title: %s\n", data->title);
	g_print ("Description: %s\n", data->description);
	g_print ("Author: %s\n", data->author);
	g_print ("Date: %s\n", datebuf);

	if (data->num_posts > 0) {
		g_print ("Number of episodes: %d\n", data->num_posts);
		g_print ("\n");
	} else {
		GList *l;
		g_print ("Number of episodes: %d\n", g_list_length (data->posts));
		g_print ("\n");
		for (l = data->posts; l != NULL; l = l->next) {
			RBPodcastItem *item = l->data;

			g_date_set_time_t (&date, item->pub_date);
			g_date_strftime (datebuf, 1024, "%F %T", &date);

			g_print ("\tItem title: %s\n", item->title);
			g_print ("\tURL: %s\n", item->url);
			g_print ("\tAuthor: %s\n", item->author);
			g_print ("\tDate: %s\n", datebuf);
			g_print ("\tDescription: %s\n", item->description);
			g_print ("\n");
		}
	}
}
Exemple #22
0
void gtk_dateentry_set_date(GtkDateEntry * dateentry, guint julian_days)
{
	g_return_if_fail (GTK_IS_DATE_ENTRY (dateentry));

	if(g_date_valid_julian(julian_days))
	{
		g_date_set_julian (dateentry->date, julian_days);
	}
	else
	{
		g_date_set_time_t(dateentry->date, time(NULL));
	}
	gtk_dateentry_datetoentry(dateentry);
}
Exemple #23
0
/** 
 * seahorse_util_get_date_string:
 * @time: Time value to parse
 *
 * Creates a string representation of @time for use with gpg.
 *
 * Returns: A string representing @time. The returned string should be freed
 * with #g_free when no longer needed.
 **/
gchar*
seahorse_util_get_date_string (const time_t time)
{
	GDate *created_date;
	gchar *created_string;
	
	if (time == 0)
		return "0";
	
	created_date = g_date_new ();
	g_date_set_time_t (created_date, time);
	created_string = g_new (gchar, 11);
	g_date_strftime (created_string, 11, "%Y-%m-%d", created_date);
	return created_string;
}
static void
chat_text_view_append_timestamp (EmpathyChatTextView *view,
				 time_t               timestamp,
				 gboolean             show_date)
{
	EmpathyChatTextViewPriv *priv = GET_PRIV (view);
	GtkTextIter              iter;
	gchar                   *tmp;
	GString                 *str;

	str = g_string_new ("- ");

	/* Append date if needed */
	if (show_date) {
		GDate *date;
		gchar  buf[256];

		date = g_date_new ();
		g_date_set_time_t (date, timestamp);
		/* Translators: timestamp displayed between conversations in
		 * chat windows (strftime format string) */
		g_date_strftime (buf, 256, _("%A %B %d %Y"), date);
		g_string_append (str, buf);
		g_string_append (str, ", ");
		g_date_free (date);
	}

	/* Append time */
	tmp = empathy_time_to_string_local (timestamp, EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
	g_string_append (str, tmp);
	g_free (tmp);

	g_string_append (str, " -\n");

	/* Insert the string in the buffer */
	empathy_chat_text_view_append_spacing (view);
	gtk_text_buffer_get_end_iter (priv->buffer, &iter);
	gtk_text_buffer_insert_with_tags_by_name (priv->buffer,
						  &iter,
						  str->str, -1,
						  EMPATHY_CHAT_TEXT_VIEW_TAG_TIME,
						  NULL);

	priv->last_timestamp = timestamp;

	g_string_free (str, TRUE);	
}
Exemple #25
0
static void
gnumeric_hdate_get_date (GnmValue const * const *arg, int *year, int *month, int *day)
{
	GDate date;

	if (arg[0] == NULL || arg[1]  == NULL || arg[2] == NULL)
		g_date_set_time_t (&date, time (NULL));

	*year = (arg[0]) ? value_get_as_int (arg[0])
		: g_date_get_year (&date);
	*month = (arg[1]) ? value_get_as_int (arg[1]) :
		(int)g_date_get_month (&date);
	*day = (arg[2]) ? value_get_as_int (arg[2]) :
		g_date_get_day (&date);

	return;
}
Exemple #26
0
static void gtk_dateentry_tokens(GtkWidget *gtkentry, gpointer user_data)
{
GtkDateEntry *dateentry = user_data;
const gchar *str;
GDateParseTokens pt;

 	str = gtk_entry_get_text (GTK_ENTRY (dateentry->entry));

	g_date_fill_parse_tokens(str, &pt);
	DB( g_print(" -> parsetoken return is %d values :%d %d %d\n", pt.num_ints, pt.n[0], pt.n[1], pt.n[2]) );

	// initialize with today's date
	g_date_set_time_t(dateentry->date, time(NULL));
	
	switch( pt.num_ints )
	{
		case 1:
			DB( g_print(" -> seizured 1 number\n") );
			if(g_date_valid_day(pt.n[0]))
				g_date_set_day(dateentry->date, pt.n[0]);
			break;
		case 2:
			DB( g_print(" -> seizured 2 numbers\n") );
			if( dmy_order[0] != G_DATE_YEAR )
			{
				if( dmy_order[0] == G_DATE_DAY )
				{
					if(g_date_valid_day(pt.n[0]))
					    g_date_set_day(dateentry->date, pt.n[0]);
					if(g_date_valid_month(pt.n[1]))
						g_date_set_month(dateentry->date, pt.n[1]);
				}
				else
				{
					if(g_date_valid_day(pt.n[1]))
					    g_date_set_day(dateentry->date, pt.n[1]);
					if(g_date_valid_month(pt.n[0]))
						g_date_set_month(dateentry->date, pt.n[0]);
				}
			}
			break;
	}


	
}
Exemple #27
0
static GnmValue *
gnumeric_date_get_date (GnmFuncEvalInfo * ei, GnmValue const * const val,
			int *year, int *month, int *day)
{
	GDate date;

	if (val == NULL)
		g_date_set_time_t (&date, time (NULL));
	else if (!datetime_value_to_g (&date, val, DATE_CONV (ei->pos)))
		return value_new_error_NUM (ei->pos);

	*year = g_date_get_year (&date);
	*month = g_date_get_month (&date);
	*day = g_date_get_day (&date);

	return NULL;
}
Exemple #28
0
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;
}
Exemple #29
0
char *
gpa_creation_date_string (unsigned long creation_time)
{
  gchar *result;
  GDate creation_date;

  if( creation_time > 0 )
    {
      g_date_set_time_t (&creation_date, (time_t) creation_time);
      result = g_strdup_printf ("%04d-%02d-%02d",
                                g_date_get_year (&creation_date),
                                g_date_get_month (&creation_date),
                                g_date_get_day (&creation_date));
    }
  else
    result = g_strdup (_("unknown"));
  return result;
}
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);
}