Esempio n. 1
0
static void
attribute_init_date (GckAttribute *attr, gulong attr_type,
                     const GDate *value, GckAllocator allocator)
{
	gchar buffer[9];
	CK_DATE date;
	g_assert (value);
	g_snprintf (buffer, sizeof (buffer), "%04d%02d%02d",
	            (int)g_date_get_year (value),
	            (int)g_date_get_month (value),
	            (int)g_date_get_day (value));
	memcpy (&date.year, buffer + 0, 4);
	memcpy (&date.month, buffer + 4, 2);
	memcpy (&date.day, buffer + 6, 2);
	attribute_init (attr, attr_type, &date, sizeof (CK_DATE), allocator);
}
Esempio n. 2
0
gint
julian_to_year (guint32 julian_day)
{
GDate *tmpdate;
gint year;

	g_return_val_if_fail (g_date_valid_julian (julian_day) == TRUE, 0);

    tmpdate = g_date_new_julian (julian_day);
	g_return_val_if_fail (tmpdate != NULL, 0);

	year = g_date_get_year (tmpdate);
	g_date_free (tmpdate);

    return year;
}
Esempio n. 3
0
static void
gnc_parse_date (struct tm *parsed, const char * datestr)
{
    int day, month, year;
    gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());

    if (!parsed) return;
    if (!datestr) return;

    if (!qof_scan_date (datestr, &day, &month, &year))
    {
        // Couldn't parse date, use today
        struct tm tm_today;

	memset (&tm_today, 0, sizeof (struct tm));
        gnc_tm_get_today_start (&tm_today);
        day = tm_today.tm_mday;
        month = tm_today.tm_mon + 1;
        year = tm_today.tm_year + 1900;
    }

    // If we have an auto-read-only threshold, do not accept a date that is
    // older than the threshold.
    if (use_autoreadonly)
    {
        GDate *d = g_date_new_dmy(day, month, year);
	if (check_readonly_threshold (datestr, d))
	{
	    day = g_date_get_day (d);
	    month = g_date_get_month (d);
	    year = g_date_get_year (d);
	}
	g_date_free (d);
    }

    parsed->tm_mday = day;
    parsed->tm_mon  = month - 1;
    parsed->tm_year = year - 1900;

    gnc_tm_set_day_start(parsed);
    /* Using gnc_mktime purely for its side effect of filling in the
     * rest of parsed and to check that it's valid.
     */
    if (gnc_mktime (parsed) == -1)
        gnc_tm_get_today_start (parsed);
    gnc_mktime (parsed);
}
Esempio n. 4
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;
}
Esempio n. 5
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;
}
Esempio n. 6
0
static void
gtk_dateentry_popup_display (GtkDateEntry * dateentry)
{
const char *str;
	int month;

  //gint height, width, x, y;
  gint old_width, old_height;

	DB( g_print(" (dateentry) popup_display\n****\n\n") );

  old_width = dateentry->popwin->allocation.width;
  old_height  = dateentry->popwin->allocation.height;


/* update */
	str = gtk_entry_get_text (GTK_ENTRY (dateentry->entry));
	g_date_set_parse (dateentry->date, str);

	if(g_date_valid(dateentry->date) == TRUE)
	{
		/* GtkCalendar expects month to be in 0-11 range (inclusive) */
		month = g_date_get_month (dateentry->date) - 1;
		gtk_calendar_select_month (GTK_CALENDAR (dateentry->calendar),
				   CLAMP (month, 0, 11),
				   g_date_get_year (dateentry->date));
        gtk_calendar_select_day (GTK_CALENDAR (dateentry->calendar),
				 g_date_get_day (dateentry->date));
	}

	position_popup(dateentry);

  gtk_widget_show (dateentry->popwin);

  gtk_grab_add (dateentry->popwin);

  // this close the popup */

  gdk_pointer_grab (dateentry->popwin->window, TRUE,
		    GDK_BUTTON_PRESS_MASK |
		    GDK_BUTTON_RELEASE_MASK |
		    GDK_POINTER_MOTION_MASK,
		    NULL, NULL, GDK_CURRENT_TIME);

}
Esempio n. 7
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;
}
Esempio n. 8
0
File: convert.c Progetto: gpg/gpa
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;
}
Esempio n. 9
0
void
select_date_day_cb (GtkWidget *widget, gpointer user_data)
{
guint year, month, day;
GDate *cdate;

	MESSAGE *msg = (MESSAGE *) user_data;
	cdate = g_date_new_julian ((guint32) msg->data);
	g_return_if_fail (cdate != NULL);

	day = g_date_get_day (cdate);
	month = g_date_get_month (cdate);
	year = g_date_get_year (cdate);
	g_date_free (cdate);

	jump_to_date (day, month - 1, year, msg->appGUI);
	update_aux_calendars (msg->appGUI);
	fullyear_window_close_cb (GTK_WIDGET (widget), NULL, msg->appGUI);
}
Esempio n. 10
0
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);
}
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 void
yearCriteriaSetWidgetData (GtkWidget *widget, GValue *val)
{
	GDate *date = NULL;
	gulong num = g_value_get_ulong (val);
	gint display_year;
	g_assert (num <= G_MAXINT);

	if (num != 0) {
	  /* Create a date structure to get year from */
	  date = g_date_new();
	  g_date_set_julian (date, num);
	  display_year = (gint)g_date_get_year(date);
	  g_date_free(date);
	} else {
	  display_year = 0;
	}
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), display_year);
}
Esempio n. 13
0
File: gpgmeedit.c Progetto: gpg/gpa
/* Generate the edit parameters needed for setting owner trust.  */
static struct edit_parms_s *
card_edit_genkey_parms_new (GpaContext *ctx,
                            gpa_keygen_para_t *parms, gpgme_data_t out)
{
  struct edit_parms_s *edit_parms;
  struct genkey_parms_s *genkey_parms;

  edit_parms = xcalloc (1, sizeof *edit_parms);
  genkey_parms = xcalloc (1, sizeof *genkey_parms);

  edit_parms->state = CARD_START;
  edit_parms->action = card_edit_genkey_fnc_action;
  edit_parms->transit = card_edit_genkey_fnc_transit;
  edit_parms->save_error = card_edit_genkey_save_error;
  edit_parms->out = out;
  edit_parms->opaque = genkey_parms;

  assert (sizeof (genkey_parms->expiration_day) > 10);
  if (g_date_valid (&parms->expire))
    snprintf (genkey_parms->expiration_day,
              sizeof genkey_parms->expiration_day,
              "%04d-%02d-%02d",
              g_date_get_year (&parms->expire),
              g_date_get_month (&parms->expire),
              g_date_get_day (&parms->expire));
  else /* Never expire.  */
    strcpy (genkey_parms->expiration_day, "0");

  genkey_parms->name = parms->name;
  genkey_parms->email = parms->email;
  genkey_parms->comment = parms->comment;
  genkey_parms->backup = parms->backup;
  genkey_parms->error_desc_adr = &parms->r_error_desc;

  /* Make sure the cleanup is run when the edit completes */
  edit_parms->signal_id =
    g_signal_connect (G_OBJECT (ctx), "done",
		      G_CALLBACK (card_edit_genkey_parms_release),
		      edit_parms);

  return edit_parms;
}
Esempio n. 14
0
gchar* date_str()
{
	/* get current time of day */
	//GTimeVal timeval;
	//g_get_current_time(&timeval);

	/* get current date */
	GString* dateBuffer = g_string_new("");
	GDate* date = g_date_new();

	g_date_set_time(date, time(NULL));
	//g_date_set_time_val(date, &timeval); // Not available in glib 2.8

	gint day = g_date_get_day(date);
	gint month = g_date_get_month(date);
	gint year = g_date_get_year(date);
	g_string_append_printf(dateBuffer, "%02d.%02d.%04d", day, month, year);
	g_date_free(date);
	return g_string_free(dateBuffer, FALSE);
}
Esempio n. 15
0
static void
print_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
{
  int i, num;

  num = gst_tag_list_get_tag_size (list, tag);
  for (i = 0; i < num; ++i) {
    const GValue *val;

    /* Note: when looking for specific tags, use the g_tag_list_get_xyz() API,
     * we only use the GValue approach here because it is more generic */
    val = gst_tag_list_get_value_index (list, tag, i);
    if (G_VALUE_HOLDS_STRING (val)) {
      const char* unformatted = g_value_get_string (val);
      gchar* formatted = strescape(unformatted,"\"","\"");
      g_print ("(%s . \"%s\")\n", tag, formatted);
      g_free(formatted);
    } else if (G_VALUE_HOLDS_UINT (val)) {
	  unsigned int uint = g_value_get_uint (val);
	  if(uint > 0xf)
      	g_print ("(%s . #x%x)\n", tag, uint);
    } else if (G_VALUE_HOLDS_DOUBLE (val)) {
      g_print ("(%s . %g)\n", tag, g_value_get_double (val));
    } else if (G_VALUE_HOLDS_BOOLEAN (val)) {
      g_print ("(%s . %s)\n", tag,
          (g_value_get_boolean (val)) ? "#t" : "#f");
    } else if (GST_VALUE_HOLDS_BUFFER (val)) {
      g_print ("(%s . (buffer %u))", tag,
              gst_buffer_get_size(gst_value_get_buffer (val)));
    } else if (GST_VALUE_HOLDS_DATE_TIME (val)) {
	   GDate* date = (GDate*)g_value_get_boxed(val);
      g_print ("(%s . (date 0 0 0 %u %u %u))\n", tag,
	  	g_date_get_day(date),
		g_date_get_month(date),
        g_date_get_year (date));
    } else {
      g_print ("(%20s . (type %s))", tag, G_VALUE_TYPE_NAME (val));
    }
  }

}
Esempio n. 16
0
/* Event handler for day groups in the month item.  A button press makes the calendar jump to the
 * selected day and destroys the Go-to dialog box.
 */
static void
ecal_event (ECalendarItem *calitem, gpointer user_data)
{
	GoToDialog *dlg = user_data;
	GDate start_date, end_date;
	struct icaltimetype tt = icaltime_null_time ();
	time_t et;

	e_calendar_item_get_selection (calitem, &start_date, &end_date);

	tt.year = g_date_get_year (&start_date);
	tt.month = g_date_get_month (&start_date);
	tt.day = g_date_get_day (&start_date);

	et = icaltime_as_timet_with_zone (tt, gnome_calendar_get_timezone (dlg->gcal));

	gnome_calendar_goto (dlg->gcal, et);

	gtk_dialog_response (GTK_DIALOG (dlg->dialog), GTK_RESPONSE_NONE);
	/* gnome_dialog_close (GNOME_DIALOG (dlg->dialog)); */
}
Esempio n. 17
0
void
cal_add_note (GDate *date, gchar *color_str, gchar *text_note, GUI *appGUI)
{
struct note *a;

	g_return_if_fail (text_note != NULL);

	a = g_malloc (sizeof (struct note));
	g_assert (a != NULL);

	a->date = g_date_get_julian (date);
	a->day = g_date_get_day (date);
	a->month = g_date_get_month (date);
	a->year = g_date_get_year (date);
	a->color = (color_str != NULL) ? g_strdup (color_str) : NULL;
	a->note = g_strdup (text_note);

	cal_remove_note (date, appGUI);

	appGUI->cal->notes_list = g_slist_append (appGUI->cal->notes_list, a);
}
Esempio n. 18
0
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\n",
                 str);
        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;
}
Esempio n. 19
0
/**
 * go_val_bucketer_apply :
 * @bucketer : #GOValBucketer
 * @v : #GOVal
 *
 * Calculate which bucket @v falls into.
 *
 * Returns -1 on general failure, and 0 for out of range below the start of the domain.
 *	Some bucketer types will also create a bucket on the high end for out of range above.
 **/
int
go_val_bucketer_apply (GOValBucketer const *bucketer, GOVal const *v)
{
	g_return_val_if_fail (bucketer != NULL, 0);
	g_return_val_if_fail (v != NULL, 0);

	if (bucketer->type == GO_VAL_BUCKET_NONE)
		return 0;

	/* Time based */
	if (bucketer->type <= GO_VAL_BUCKET_HOUR) {
		switch (bucketer->type) {
		case GO_VAL_BUCKET_SECOND :
			break;
		case GO_VAL_BUCKET_MINUTE :
			break;
		default : g_assert_not_reached ();
		}
	}
	/* date based */
	if (bucketer->type <= GO_VAL_BUCKET_YEAR) {
		static GODateConventions const default_conv = {FALSE};
		GDate d;
		if (!datetime_value_to_g (&d, v, &default_conv))
			return -1;

		switch (bucketer->type) {
		case GO_VAL_BUCKET_DAY_OF_YEAR :	return 1 + g_date_get_day_of_year (&d);
		case GO_VAL_BUCKET_MONTH :		return g_date_get_month (&d);
		case GO_VAL_BUCKET_CALENDAR_QUARTER :	return 1 + ((g_date_get_month (&d)-1) / 3);
		case GO_VAL_BUCKET_YEAR :		return 1 + g_date_get_year (&d);
		default : g_assert_not_reached ();
		}
	}

	/* >= GO_VAL_BUCKET_SERIES_LINEAR) */

	return 0;
}
Esempio n. 20
0
void
gnc_gdate_set_fiscal_year_end (GDate *date,
                               const GDate *fy_end)
{
    GDate temp;
    gboolean new_fy;

    g_return_if_fail(date);
    g_return_if_fail(fy_end);

    /* Compute the FY end that occurred this CY */
    temp = *fy_end;
    g_date_set_year(&temp, g_date_get_year(date));

    /* Has it already passed? */
    new_fy = (g_date_compare(date, &temp) > 0);

    /* Set end date */
    *date = temp;
    if (new_fy)
        g_date_add_years(date, 1);
}
Esempio n. 21
0
/**
 * gda_sql_value_stringify
 * @value: a #GValue pointer
 *
 * Simplified version of gda_value_stringify().
 *
 * Returns: a new string
 */
gchar *
gda_sql_value_stringify (const GValue *value)
{
        if (value && !GDA_VALUE_HOLDS_NULL (value)) {
                if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING)) {
                        GValue *string;
                        gchar *str;

                        string = g_value_init (g_new0 (GValue, 1), G_TYPE_STRING);
                        g_value_transform (value, string);
                        str = g_value_dup_string (string);
			gda_value_free (string);
                        return str;
                }
                else {
                        GType type = G_VALUE_TYPE (value);
                        if (type == G_TYPE_DATE) {
                                GDate *date;
                                date = (GDate *) g_value_get_boxed (value);
                                if (date) {
                                        if (g_date_valid (date))
                                                return g_strdup_printf ("%04u-%02u-%02u",
                                                                        g_date_get_year (date),
                                                                        g_date_get_month (date),
                                                                        g_date_get_day (date));
                                        else
                                                return g_strdup_printf ("%04u-%02u-%02u",
                                                                        date->year, date->month, date->day);
                                }
                                else
                                        return g_strdup ("0000-00-00");
                        }
			else
                                return g_strdup ("<type not transformable to string>");
		}
	}
	else
		return g_strdup ("NULL");
}
//LOGGER USER QUERIES
int create_dir()
{
  char tek_day_dir[ 11 ];
  GDate *date = g_date_new();
  const time_t timestamp = time( NULL );
  g_date_set_time_t( date, timestamp );

  if( g_mkdir_with_parents( PATH_TO_LOG_USER_QUERIES, 0755 ) == 0 )
  {
    if( g_chdir( PATH_TO_LOG_USER_QUERIES ) == 0 )
    {
      sprintf( tek_day_dir, "%d-%d-%d", g_date_get_year( date ), g_date_get_month( date ), g_date_get_day( date ) );
      if( g_mkdir_with_parents( tek_day_dir, 0755 ) == 0 )
      {
        g_date_free( date );
        if( g_chdir( tek_day_dir ) == 0 ) return 1;
      }
    }
  }
  g_date_free( date );
  return 0;
}
Esempio n. 23
0
/* 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;

    nd = g_date_get_day(next);
    sd = g_date_get_day(start);

    /* 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 * ((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 */

    return matchday - nd;  /* Offset from 'next' to matchday */
}
Esempio n. 24
0
static void
on_calendar_entry_activated(GtkWidget *widget, GtkWidget *calendar)
{
    GDate *date;
    const gchar *text;

    date = g_date_new();

    text = gtk_entry_get_text(GTK_ENTRY(widget));
    g_date_set_parse(date, text);

    if (g_date_valid(date)) {
	gtk_calendar_freeze(GTK_CALENDAR(calendar));
	gtk_calendar_select_month(GTK_CALENDAR(calendar),
				  g_date_get_month(date) - 1,
				  g_date_get_year(date));
	gtk_calendar_select_day(GTK_CALENDAR(calendar),
				g_date_get_day(date));
	gtk_calendar_thaw(GTK_CALENDAR(calendar));
    }
    g_date_free(date);
}
Esempio n. 25
0
File: utils.c Progetto: rosedu/osmo
guint
utl_get_weekend_days_in_month (const GDate *date)
{
	GDate *tmpdate = NULL;
	guint i, day, days, weekend_days;

	tmpdate = g_date_new_dmy (1, g_date_get_month (date), g_date_get_year (date));
	g_return_val_if_fail (tmpdate != NULL, 0);

	days = utl_date_get_days_in_month (tmpdate);
	weekend_days = 0;

	for (i = 1; i <= days; i++) {
		g_date_set_day (tmpdate, i);
		day = g_date_get_weekday (tmpdate);
		if (day == G_DATE_SATURDAY || day == G_DATE_SUNDAY) {
			weekend_days++;
		}
	}

	g_date_free (tmpdate);
	return weekend_days;
}
Esempio n. 26
0
File: convert.c Progetto: gpg/gpa
char *
gpa_expiry_date_string (unsigned long expiry_time)
{
  gchar *result;
  GDate expiry_date;

  if (sizeof (time_t) <= 4 && expiry_time == (time_t)2145914603)
    {
      /* 2145914603 (2037-12-31 23:23:23) is used by GPGME to indicate
         a time we can't represent. */
      result = g_strdup (">= 2038");
    }
  else if ( expiry_time > 0 )
    {
      g_date_set_time_t (&expiry_date, (time_t) expiry_time);
      result = g_strdup_printf ("%04d-%02d-%02d",
                                g_date_get_year (&expiry_date),
                                g_date_get_month (&expiry_date),
                                g_date_get_day (&expiry_date));
    }
  else
    result = g_strdup (_("never expires"));
  return result;
}
Esempio n. 27
0
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_label = gtk_label_new("");
#if GTK_CHECK_VERSION(3,12,0)
            gtk_widget_set_margin_start (GTK_WIDGET(priv->date_label), 6);
#else
            gtk_widget_set_margin_left (GTK_WIDGET(priv->date_label), 6);
#endif
            gtk_box_pack_start(GTK_BOX(period), priv->date_label, TRUE, TRUE, 0);
            gtk_widget_show_all(priv->date_label);
        }
        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_label);
        priv->date_label = NULL;
    }
}
Esempio n. 28
0
static char *
gst_value_serialize_xmp (const GValue * value)
{
  switch (G_VALUE_TYPE (value)) {
    case G_TYPE_STRING:
      return g_markup_escape_text (g_value_get_string (value), -1);
    case G_TYPE_INT:
      return g_strdup_printf ("%d", g_value_get_int (value));
    case G_TYPE_UINT:
      return g_strdup_printf ("%u", g_value_get_uint (value));
    default:
      break;
  }
  /* put non-switchable types here */
  if (G_VALUE_TYPE (value) == GST_TYPE_DATE) {
    const GDate *date = gst_value_get_date (value);

    return g_strdup_printf ("%04d-%02d-%02d",
        (gint) g_date_get_year (date), (gint) g_date_get_month (date),
        (gint) g_date_get_day (date));
  } else {
    return NULL;
  }
}
Esempio n. 29
0
/*
 * Returns the number of days in the year for the given date accoring to
 * the day counting system specified by 'basis' argument.  Basis may have
 * one of the following values:
 *
 *	0  for US 30/360 (days in a month/days in a year)
 *	1  for actual days/actual days
 *	2  for actual days/360
 *	3  for actual days/365
 *	4  for European 30/360
 *
 * This function returns 360 for basis 0, 2, and 4, it returns value
 * 365 for basis 3, and value 365 or 366 for basis 1 accoring to the
 * year of the given date (366 is returned if the date is in a leap
 * year).
 */
int
annual_year_basis (GnmValue const *value_date, go_basis_t basis,
		   GODateConventions const *date_conv)
{
        GDate    date;

	switch (basis) {
	case GO_BASIS_MSRB_30_360:
	        return 360;
	case GO_BASIS_ACT_ACT:
		if (!datetime_value_to_g (&date, value_date, date_conv))
		        return -1;
		return g_date_is_leap_year (g_date_get_year (&date))
			? 366 : 365;
	case GO_BASIS_ACT_360:
	        return 360;
	case GO_BASIS_ACT_365:
	        return 365;
	case GO_BASIS_30E_360:
	        return 360;
	default:
	        return -1;
	}
}
Esempio n. 30
0
gchar*
kvp_value_to_string(const KvpValue *val)
{
    gchar *tmp1;
    gchar *tmp2;
    const gchar *ctmp;

    g_return_val_if_fail(val, NULL);

    switch (kvp_value_get_type(val))
    {
    case KVP_TYPE_GINT64:
        return g_strdup_printf("KVP_VALUE_GINT64(%" G_GINT64_FORMAT ")",
                               kvp_value_get_gint64(val));
        break;

    case KVP_TYPE_DOUBLE:
        return g_strdup_printf("KVP_VALUE_DOUBLE(%g)",
                               kvp_value_get_double(val));
        break;

    case KVP_TYPE_NUMERIC:
        tmp1 = gnc_numeric_to_string(kvp_value_get_numeric(val));
        tmp2 = g_strdup_printf("KVP_VALUE_NUMERIC(%s)", tmp1 ? tmp1 : "");
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_STRING:
        tmp1 = kvp_value_get_string (val);
        return g_strdup_printf("KVP_VALUE_STRING(%s)", tmp1 ? tmp1 : "");
        break;

    case KVP_TYPE_GUID:
        gchar guidstr[GUID_ENCODING_LENGTH+1];
        guid_to_string_buff(kvp_value_get_guid(val),guidstr);
        tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", guidstr);
        return tmp2;
        break;

    case KVP_TYPE_TIMESPEC:
        tmp1 = g_new0 (char, 40);
        gnc_timespec_to_iso8601_buff (kvp_value_get_timespec (val), tmp1);
        tmp2 = g_strdup_printf("KVP_VALUE_TIMESPEC(%s)", tmp1);
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_BINARY:
    {
        guint64 len;
        void *data;
        data = kvp_value_get_binary(val, &len);
        tmp1 = binary_to_string(data, len);
        return g_strdup_printf("KVP_VALUE_BINARY(%s)", tmp1 ? tmp1 : "");
    }
    break;

    case KVP_TYPE_GLIST:
        tmp1 = kvp_value_glist_to_string(kvp_value_get_glist(val));
        tmp2 = g_strdup_printf("KVP_VALUE_GLIST(%s)", tmp1 ? tmp1 : "");
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_FRAME:
        tmp1 = kvp_frame_to_string(kvp_value_get_frame(val));
        tmp2 = g_strdup_printf("KVP_VALUE_FRAME(%s)", tmp1 ? tmp1 : "");
        g_free(tmp1);
        return tmp2;
        break;

    case KVP_TYPE_GDATE:
        return g_strdup_printf("KVP_VALUE_GDATE(%04d-%02d-%02d)",
                               g_date_get_year(&val->value.gdate),
                               g_date_get_month(&val->value.gdate),
                               g_date_get_day(&val->value.gdate));
    default:
	break;
    }
    g_assert(FALSE); /* must not be reached */
    return g_strdup("");
}