bool DateTime::is_same_minute(const DateTime& a, const DateTime& b)
{
    if (!is_same_day(a,b))
        return false;

    const auto adt = a.get();
    const auto bdt = b.get();
    return (g_date_time_get_hour(adt) == g_date_time_get_hour(bdt))
        && (g_date_time_get_minute(adt) == g_date_time_get_minute(bdt));
}
Пример #2
0
gboolean
datetime_is_date (GDateTime *dt)
{
  return g_date_time_get_hour (dt) == 0 &&
         g_date_time_get_minute (dt) == 0 &&
         g_date_time_get_seconds (dt) == 0;
}
static guint
calculate_seconds_until_next_minute (void)
{
  guint seconds;
  GTimeSpan diff;
  GDateTime * now;
  GDateTime * next;
  GDateTime * start_of_next;

  now = g_date_time_new_now_local ();
  next = g_date_time_add_minutes (now, 1);
  start_of_next = g_date_time_new_local (g_date_time_get_year (next),
                                         g_date_time_get_month (next),
                                         g_date_time_get_day_of_month (next),
                                         g_date_time_get_hour (next),
                                         g_date_time_get_minute (next),
                                         1);

  diff = g_date_time_difference (start_of_next, now);
  seconds = (diff + (G_TIME_SPAN_SECOND - 1)) / G_TIME_SPAN_SECOND;

  /* cleanup */
  g_date_time_unref (start_of_next);
  g_date_time_unref (next);
  g_date_time_unref (now);

  return seconds;
}
gdouble
gsd_night_light_frac_day_from_dt (GDateTime *dt)
{
        return g_date_time_get_hour (dt) +
                (gdouble) g_date_time_get_minute (dt) / 60.f +
                (gdouble) g_date_time_get_second (dt) / 3600.f;
}
Пример #5
0
static void _tgenmain_log(GLogLevelFlags level, const gchar* fileName, const gint lineNum, const gchar* functionName, const gchar* format, ...) {
    if(level > tgenLogFilterLevel) {
        return;
    }

    va_list vargs;
    va_start(vargs, format);

    gchar* fileStr = fileName ? g_path_get_basename(fileName) : g_strdup("n/a");
    const gchar* functionStr = functionName ? functionName : "n/a";

    GDateTime* dt = g_date_time_new_now_local();
    GString* newformat = g_string_new(NULL);

    g_string_append_printf(newformat, "%04i-%02i-%02i %02i:%02i:%02i %"G_GINT64_FORMAT".%06i [%s] [%s:%i] [%s] %s",
            g_date_time_get_year(dt), g_date_time_get_month(dt), g_date_time_get_day_of_month(dt),
            g_date_time_get_hour(dt), g_date_time_get_minute(dt), g_date_time_get_second(dt),
            g_date_time_to_unix(dt), g_date_time_get_microsecond(dt),
            _tgenmain_logLevelToString(level), fileStr, lineNum, functionName, format);

    gchar* message = g_strdup_vprintf(newformat->str, vargs);
    g_print("%s\n", message);
    g_free(message);

    g_string_free(newformat, TRUE);
    g_date_time_unref(dt);
    g_free(fileStr);

    va_end(vargs);
}
void
gcal_time_selector_set_time (GcalTimeSelector *selector,
                             GDateTime        *time)
{
  g_return_if_fail (GCAL_IS_TIME_SELECTOR (selector));

  if (selector->time != time)
    {
      gint hour, minute;

      g_clear_pointer (&selector->time, g_date_time_unref);
      selector->time = g_date_time_new_local (g_date_time_get_year (time),
                                              g_date_time_get_month (time),
                                              g_date_time_get_day_of_month (time),
                                              g_date_time_get_hour (time),
                                              g_date_time_get_minute (time),
                                              0);

      /* Update the spinners */
      g_signal_handlers_block_by_func (selector->hour_adjustment, update_time, selector);
      g_signal_handlers_block_by_func (selector->minute_adjustment, update_time, selector);

      hour = g_date_time_get_hour (time);
      minute = g_date_time_get_minute (time);

      if (!selector->format_24h)
        {
          g_signal_handlers_block_by_func (selector->period_combo, update_time, selector);

          gtk_combo_box_set_active (GTK_COMBO_BOX (selector->period_combo), hour >= 12);
          hour =  hour % 12;
          hour = (hour == 0)? 12 : hour;

          g_signal_handlers_unblock_by_func (selector->period_combo, update_time, selector);
        }

      gtk_adjustment_set_value (selector->hour_adjustment, hour);
      gtk_adjustment_set_value (selector->minute_adjustment, minute);

      update_label (selector);

      g_signal_handlers_unblock_by_func (selector->hour_adjustment, update_time, selector);
      g_signal_handlers_unblock_by_func (selector->minute_adjustment, update_time, selector);

      g_object_notify (G_OBJECT (selector), "time");
    }
}
Пример #7
0
gchar*
balde_datetime_logging(GDateTime *dt)
{
    return g_strdup_printf("%02d/%s/%04d %02d:%02d:%02d",
        g_date_time_get_day_of_month(dt), months[g_date_time_get_month(dt) - 1],
        g_date_time_get_year(dt), g_date_time_get_hour(dt),
        g_date_time_get_minute(dt), g_date_time_get_second(dt));
}
Пример #8
0
/**
 * gst_date_time_get_hour:
 * @datetime: a #GstDateTime
 *
 * Retrieves the hour of the day represented by @datetime in the gregorian
 * calendar. The return is in the range of 0 to 23.
 * Call gst_date_time_has_time() before, to avoid warnings.
 *
 * Return value: the hour of the day
 */
gint
gst_date_time_get_hour (const GstDateTime * datetime)
{
  g_return_val_if_fail (datetime != NULL, 0);
  g_return_val_if_fail (gst_date_time_has_time (datetime), 0);

  return g_date_time_get_hour (datetime->datetime);
}
Пример #9
0
gchar*
balde_datetime_rfc5322(GDateTime *dt)
{
    // datetime must be utc
    return g_strdup_printf("%s, %02d %s %04d %02d:%02d:%02d GMT",
        days[g_date_time_get_day_of_week(dt) - 1],
        g_date_time_get_day_of_month(dt), months[g_date_time_get_month(dt) - 1],
        g_date_time_get_year(dt), g_date_time_get_hour(dt),
        g_date_time_get_minute(dt), g_date_time_get_second(dt));
}
Пример #10
0
static unsigned long get_frame_offset_day_now(GCContext *context, int day)
{
    GCConfig      *config = context->config;
    GDateTime     *dt     = g_date_time_new_now(config->timeZone);
    unsigned long  f      = get_frame_offset_day(context, day);

    f += (g_date_time_get_hour(dt) * 60 + g_date_time_get_minute(dt)) * get_frames_per_minute(context);

    g_date_time_unref(dt);

    return (f >= config->number_of_frames) ? 0 : f;
}
Пример #11
0
/* Get current time and copy to src. */
void
time_get_now (gchar *src)
{
    GDateTime *time;
    gint hr, mi, se;

    time = g_date_time_new_now_local ();
    hr = g_date_time_get_hour (time);
    mi = g_date_time_get_minute (time);
    se = g_date_time_get_second (time);

    g_sprintf (src, "%.2d:%.2d:%.2d: ", hr, mi, se);
}
Пример #12
0
static void
gnc_g_date_time_fill_struct_tm (GDateTime *gdt, struct tm* time)
{
     g_date_time_get_ymd (gdt, &(time->tm_year), &(time->tm_mon), &(time->tm_mday));
     time->tm_sec = g_date_time_get_second (gdt);
     time->tm_min = g_date_time_get_minute (gdt);
     time->tm_hour = g_date_time_get_hour (gdt);
     // Watch out: struct tm has wday=0..6 with Sunday=0, but GDateTime has wday=1..7 with Sunday=7.
     time->tm_wday = g_date_time_get_day_of_week (gdt) % 7;
     time->tm_yday = g_date_time_get_day_of_year (gdt);
     time->tm_isdst = g_date_time_is_daylight_savings (gdt);
     time->tm_year -= 1900;
     --time->tm_mon;
}
Пример #13
0
GSList *
chat_log_get_previous(const gchar * const login, const gchar * const recipient,
    GSList *history)
{
    GTimeZone *tz = g_time_zone_new_local();

    GDateTime *now = g_date_time_new_now_local();
    GDateTime *log_date = g_date_time_new(tz,
        g_date_time_get_year(session_started),
        g_date_time_get_month(session_started),
        g_date_time_get_day_of_month(session_started),
        g_date_time_get_hour(session_started),
        g_date_time_get_minute(session_started),
        g_date_time_get_second(session_started));

    // get data from all logs from the day the session was started to today
    while (g_date_time_compare(log_date, now) != 1) {
        char *filename = _get_log_filename(recipient, login, log_date, FALSE);

        FILE *logp = fopen(filename, "r");
        char *line;
        if (logp != NULL) {
            GString *gs_header = g_string_new("");
            g_string_append_printf(gs_header, "%d/%d/%d:",
                g_date_time_get_day_of_month(log_date),
                g_date_time_get_month(log_date),
                g_date_time_get_year(log_date));
            char *header = strdup(gs_header->str);
            history = g_slist_append(history, header);
            g_string_free(gs_header, TRUE);

            while ((line = prof_getline(logp)) != NULL) {
                history = g_slist_append(history, line);
            }

            fclose(logp);
        }

        free(filename);
        GDateTime *next = g_date_time_add_days(log_date, 1);
        g_date_time_unref(log_date);
        log_date = g_date_time_ref(next);
    }

    g_time_zone_unref(tz);

    return history;
}
Пример #14
0
/* Auxiliary methods */
static gboolean
update_grid_scroll_position (GcalWeekView *self)
{
  g_autoptr(GDateTime) week_start = NULL;
  g_autoptr(GDateTime) week_end = NULL;
  g_autoptr(GDateTime) now = NULL;
  GtkAdjustment *vadjustment;
  gdouble minutes, real_value;
  gdouble max, page, page_increment, value;

  /* While the scrolled window is not mapped, we keep waiting */
  if (!gtk_widget_get_realized (self->scrolled_window) ||
      !gtk_widget_get_mapped (self->scrolled_window))
    {
      GCAL_RETURN (G_SOURCE_CONTINUE);
    }

  now = g_date_time_new_now_local ();
  week_start = get_start_of_week (self->date);
  week_end = get_end_of_week (self->date);

  /* Don't animate when not today */
  if (datetime_compare_date (now, week_start) < 0 || datetime_compare_date (now, week_end) >= 0)
    GCAL_GOTO (out);

  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolled_window));
  minutes = g_date_time_get_hour (now) * 60 + g_date_time_get_minute (now);
  page = gtk_adjustment_get_page_size (vadjustment);
  max = gtk_adjustment_get_upper (vadjustment);

  real_value = max / MINUTES_PER_DAY * minutes - (page / 2.0);
  page_increment = gtk_adjustment_get_page_increment (vadjustment);
  value = gtk_adjustment_get_value (vadjustment);

  gtk_adjustment_set_page_increment (vadjustment, real_value - value);

  g_signal_emit_by_name (self->scrolled_window,
                         "scroll-child",
                         GTK_SCROLL_PAGE_FORWARD,
                         FALSE);

  gtk_adjustment_set_page_increment (vadjustment, page_increment);

out:
  self->scroll_grid_timeout_id = 0;
  GCAL_RETURN (G_SOURCE_REMOVE);
}
Пример #15
0
static char *formatLogMessage(const char *file, int line, ShovelerLogLevel level, const char *message)
{
	const char *strippedLocation = strstr(file, logLocationPrefix);
	if(strippedLocation != NULL) {
		strippedLocation += strlen(logLocationPrefix);
	} else {
		strippedLocation = file;
	}

	GDateTime *now = g_date_time_new_now_local();
	GString *result = g_string_new("");

	g_string_append_printf(result, "[%02d:%02d:%02d] (%s:%s:%d) %s", g_date_time_get_hour(now), g_date_time_get_minute(now), g_date_time_get_second(now), getStaticLogLevelName(level), strippedLocation, line, message);

	g_date_time_unref(now);
	return g_string_free(result, false);
}
static void _pcapmain_log(GLogLevelFlags level, const gchar* functionName, const gchar* format, ...) {
    va_list vargs;
    va_start(vargs, format);

    GDateTime* dt = g_date_time_new_now_local();
    GString* newformat = g_string_new(NULL);

    g_string_append_printf(newformat, "%04i-%02i-%02i %02i:%02i:%02i %"G_GINT64_FORMAT".%06i [%s] [%s] %s",
            g_date_time_get_year(dt), g_date_time_get_month(dt), g_date_time_get_day_of_month(dt),
            g_date_time_get_hour(dt), g_date_time_get_minute(dt), g_date_time_get_second(dt),
            g_date_time_to_unix(dt), g_date_time_get_microsecond(dt),
            _pcapmain_logLevelToString(level), functionName, format);
    g_logv(PCAP_LOG_DOMAIN, level, newformat->str, vargs);

    g_string_free(newformat, TRUE);
    g_date_time_unref(dt);

    va_end(vargs);
}
Пример #17
0
static void
change_date (CcDateTimePanel *self)
{
  CcDateTimePanelPrivate *priv = self->priv;
  guint mon, y, d;
  GDateTime *old_date;

  old_date = priv->date;

  mon = 1 + gtk_combo_box_get_active (GTK_COMBO_BOX (W ("month-combobox")));
  y = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("year-spinbutton")));
  d = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (W ("day-spinbutton")));

  priv->date = g_date_time_new_local (y, mon, d,
                                      g_date_time_get_hour (old_date),
                                      g_date_time_get_minute (old_date),
                                      g_date_time_get_second (old_date));
  g_date_time_unref (old_date);
  queue_set_datetime (self);
}
Пример #18
0
static gchar* plank_services_logger_get_time (void) {
	gchar* result = NULL;
	GDateTime* now = NULL;
	GDateTime* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	gchar* _tmp5_ = NULL;
	_tmp0_ = g_date_time_new_now_local ();
	now = _tmp0_;
	_tmp1_ = g_date_time_get_hour (now);
	_tmp2_ = g_date_time_get_minute (now);
	_tmp3_ = g_date_time_get_second (now);
	_tmp4_ = g_date_time_get_microsecond (now);
	_tmp5_ = g_strdup_printf ("%.2d:%.2d:%.2d.%.6d", _tmp1_, _tmp2_, _tmp3_, _tmp4_);
	result = _tmp5_;
	_g_date_time_unref0 (now);
	return result;
}
Пример #19
0
static void
change_time (GtkButton       *button,
             CcDateTimePanel *panel)
{
  CcDateTimePanelPrivate *priv = panel->priv;
  const gchar *widget_name;
  gint direction;
  GDateTime *old_date;

  old_date = priv->date;

  widget_name = gtk_buildable_get_name (GTK_BUILDABLE (button));

  if (strstr (widget_name, "up"))
    direction = 1;
  else
    direction = -1;

  if (widget_name[0] == 'h')
    {
      priv->date = g_date_time_add_hours (old_date, direction);
    }
  else if (widget_name[0] == 'm')
    {
      priv->date = g_date_time_add_minutes (old_date, direction);
    }
  else
    {
      int hour;
      hour = g_date_time_get_hour (old_date);
      if (hour >= 12)
        priv->date = g_date_time_add_hours (old_date, -12);
      else
        priv->date = g_date_time_add_hours (old_date, 12);
    }
  g_date_time_unref (old_date);

  update_time (panel);
  queue_set_datetime (panel);
}
Пример #20
0
icaltimetype*
datetime_to_icaltime (GDateTime *dt)
{
  icaltimetype *idt;

  if (!dt)
    return NULL;

  idt = g_new0 (icaltimetype, 1);

  idt->year = g_date_time_get_year (dt);
  idt->month = g_date_time_get_month (dt);
  idt->day = g_date_time_get_day_of_month (dt);
  idt->hour = g_date_time_get_hour (dt);
  idt->minute = g_date_time_get_minute (dt);
  idt->second = g_date_time_get_seconds (dt);
  idt->is_date = (idt->hour == 0 &&
                  idt->minute == 0 &&
                  idt->second == 0);

  return idt;
}
Пример #21
0
static gboolean
redisplay_clock (gpointer data)
{
  GSource *source;
  GDateTime *now, *expiry;

  now = g_date_time_new_now_local ();
  g_print ("%02d:%02d\n",
	   g_date_time_get_hour (now),
	   g_date_time_get_minute (now));

  expiry = g_date_time_add_seconds (now, 60 - g_date_time_get_second (now));
  source = g_date_time_source_new (expiry, TRUE);
  g_source_set_callback (source, redisplay_clock, NULL, NULL);
  g_source_attach (source, NULL);
  g_source_unref (source);

  g_date_time_unref (expiry);
  g_date_time_unref (now);

  return FALSE;
}
Пример #22
0
static gboolean
time_handler(GtkWidget *widget) {
  // periodical weather update
  printf("weather: update\n");

  // download observation (2 lines (datetime + metar data) from weather.noaa.gov)
  // FIXME: perhaps I could use libcurl or something instead of wget pipe
  char * cmd = (char*)malloc(sizeof(char)*256);
  sprintf(cmd,"wget -qO - http://weather.noaa.gov/pub/data/observations/metar/stations/%s.TXT",station);
  char * datetime = NULL;
  char * observation = NULL;
  FILE *f = (FILE*)popen(cmd,"r");
  if (f) {
    size_t len = 0;
    ssize_t i = getline(&datetime,&len,f);
    //printf("wget: dt = '%s'\n",datetime);
    i = getline(&observation,&len,f);
    //printf("wget: o  = '%s'\n",observation);
    fclose(f);
  } else {
    // failed
    printf("error: cannot download metar data\n");
    return TRUE;
  }

  // decode metar data
  Decoded_METAR MetarStruct, *Mptr = &MetarStruct;
  if( DcdMETAR( observation, Mptr) != 0 ) {
    printf("metar: decoding error - %s\n",observation);             
    return TRUE;
  }
  
  // update labels
  char * title = (char*)malloc(sizeof(char)*256);
  char * temp = (char*)malloc(sizeof(char)*256);
  char * temp_b = (char*)malloc(sizeof(char)*256);
  char * visi = (char*)malloc(sizeof(char)*256);
  char * pres_visi = (char*)malloc(sizeof(char)*256);
  char * wind = (char*)malloc(sizeof(char)*256);
  char * clouds = (char*)malloc(sizeof(char)*256);

  // prepare strings
  sprintf(title,"<b>%s</b>",station_name);
  sprintf(temp,"%d °C ",Mptr->temp);
  sprintf(temp_b,"<b>%s</b>",temp);

  //                   111111 
  //         0123456789012345
  // convert 2011/02/13 12:34\n to "13. Month 2011, HH:MM"
  // FIXME: holy shit, this datetime to datetime conversion is insane
  // FIXME: learn and use glib
  // equivalent pascal code: datetime := FormatDateTime('dd. mmmm yyyy HH:MM',StrToDateTime(s))
  char year[4+1];
  year[0] = datetime[0];
  year[1] = datetime[1];
  year[2] = datetime[2];
  year[3] = datetime[3];
  year[5] = 0;
  char day[2+1];
  day[0] = datetime[8];
  day[1] = datetime[9];
  day[2] = 0;
  int mm = 10*(datetime[5]-'0')+(datetime[6]-'0');
  //printf("mm = %d\n",mm);
  char month[20+1];
  switch (mm) {
    case 1:  strcpy(month,"Január"); break;
    case 2:  strcpy(month,"Február"); break;
    case 3:  strcpy(month,"Marec"); break;
    case 4:  strcpy(month,"Apríl"); break;
    case 5:  strcpy(month,"Máj"); break;
    case 6:  strcpy(month,"Jún"); break;
    case 7:  strcpy(month,"Júl"); break;
    case 8:  strcpy(month,"August"); break;
    case 9:  strcpy(month,"September"); break;
    case 10: strcpy(month,"Október"); break;
    case 11: strcpy(month,"November"); break;
    case 12: strcpy(month,"December"); break;
  }
  char hour[2+1];
  hour[0] = datetime[11];
  hour[1] = datetime[12];
  hour[2] = 0;
  char minute[2+1];
  minute[0] = datetime[14];
  minute[1] = datetime[15];
  minute[2] = 0;
  sprintf(datetime,"%s. %s %s, %s:%s",day,month,year,hour,minute);
  
  // viditelnost
  strcpy(visi,"???");
  if (Mptr->CAVOK)
    strcpy(visi,"výborná");
  if ( (Mptr->prevail_vsbyM > 0)&&(Mptr->prevail_vsbyM < 99000) )
    sprintf(visi,"%1.0f m",Mptr->prevail_vsbyM);
  if ( (Mptr->prevail_vsbyKM > 0)&&(Mptr->prevail_vsbyKM < 200) )
    sprintf(visi,"%1.1f km",Mptr->prevail_vsbyKM);
    
  // tlak a viditelnost
  sprintf(pres_visi,"Tlak %d kPa, viditeľnosť %s",Mptr->hectoPasc_altstng,visi);

  // convert knots to m/s
  int ws = Mptr->winData.windSpeed;
  if (strcmp(Mptr->winData.windUnits,"KT")==0) 
    ws = ws / 0.514444 / 3.6;
  sprintf(wind,"<b>%d m/s</b>",ws);

  // debug
  printf("  title     : %s\n",title);
  printf("  temp      : %s\n",temp);
  printf("  pres_visi : %s\n",pres_visi);

  // tray
  gtk_label_set_markup(labTray1,temp);
  //gtk_image_set_from_icon_name(imgClouds1,"weather-few-clouds",GTK_ICON_SIZE_LARGE_TOOLBAR);

  // dialog
  gtk_label_set_markup(labTitle1,title);
  gtk_label_set_markup(labDateTime1,datetime);
  gtk_label_set_markup(labTemp1,temp_b);
  gtk_label_set_markup(labWind1,wind);
  gtk_label_set_markup(labPressureVisibility1,pres_visi);
  //gtk_image_set_from_icon_name(imgClouds1,"weather-few-clouds",GTK_ICON_SIZE_LARGE_TOOLBAR);
  //gtk_image_set_from_icon_name(imgWind1,"gtk-dialog-error",GTK_ICON_SIZE_LARGE_TOOLBAR);

  // clouds
  sprintf(clouds,"gtk-image-missing");
  printf("Cloud type: %s\n",Mptr->cldTypHgt[0].cloud_type);
  if (
      (strcmp("SKC",Mptr->cldTypHgt[0].cloud_type)==0)
   || (strcmp("CLR",Mptr->cldTypHgt[0].cloud_type)==0) 
   || (strcmp("NSC",Mptr->cldTypHgt[0].cloud_type)==0)
   || (strcmp("",Mptr->cldTypHgt[0].cloud_type)==0) 
     )
    sprintf(clouds,"weather-clear");

  if ( 
     (strcmp("FEW",Mptr->cldTypHgt[0].cloud_type)==0)
  || (strcmp("SCT",Mptr->cldTypHgt[0].cloud_type)==0) )
    sprintf(clouds,"weather-few-clouds");

  if (
     (strcmp("BKN",Mptr->cldTypHgt[0].cloud_type)==0) 
  || (strcmp("OVC",Mptr->cldTypHgt[0].cloud_type)==0) 
     )
    sprintf(clouds,"weather-overcast");
  // is it night already?
#if defined VERY_OLD_GLIB && (VERY_OLD_GLIB > 0)
  gint h = 12;
#else
  GDateTime *dt = g_date_time_new_now_local();
  gint h = g_date_time_get_hour(dt);
  g_date_time_unref(dt);
#endif
  gboolean night = ((h>=0)&&(h<=6)) || (h >= 20);
  
  printf("h=%d night=%d\n",h,night);
  if (night)
    if ( (!(strcmp("OVC",Mptr->cldTypHgt[0].cloud_type)==0)) && (!(strcmp("BKN",Mptr->cldTypHgt[0].cloud_type)==0)) )
      sprintf(clouds,"%s-night",clouds);
  // set icons
  gtk_image_set_from_icon_name(imgClouds1,clouds,GTK_ICON_SIZE_LARGE_TOOLBAR);
  gtk_image_set_from_icon_name(imgTray1,clouds,GTK_ICON_SIZE_LARGE_TOOLBAR);
  
  printf("obstruct = %s\n",Mptr->WxObstruct[0]);
  
  // snow?
  if ( (strcmp(Mptr->WxObstruct[0],"SN")==0)
    || (strcmp(Mptr->WxObstruct[0],"-SN")==0)
    || (strcmp(Mptr->WxObstruct[0],"+SN")==0)
    || (strcmp(Mptr->WxObstruct[0],"SS")==0)
    || (strcmp(Mptr->WxObstruct[0],"-SS")==0)
    || (strcmp(Mptr->WxObstruct[0],"+SS")==0)
    || (strcmp(Mptr->WxObstruct[0],"SG")==0) 
    || (strcmp(Mptr->WxObstruct[0],"-SG")==0) 
    || (strcmp(Mptr->WxObstruct[0],"+SG")==0) ) {
    gtk_image_set_from_icon_name(imgClouds1,"weather-snow",GTK_ICON_SIZE_LARGE_TOOLBAR);
    gtk_image_set_from_icon_name(imgTray1,"weather-snow",GTK_ICON_SIZE_LARGE_TOOLBAR);
  }

  // rain?
  if ( (strcmp(Mptr->WxObstruct[0],"RA")==0) 
    || (strcmp(Mptr->WxObstruct[0],"-RA")==0)
    || (strcmp(Mptr->WxObstruct[0],"+RA")==0) ) {
    gtk_image_set_from_icon_name(imgClouds1,"weather-snow",GTK_ICON_SIZE_LARGE_TOOLBAR);
    gtk_image_set_from_icon_name(imgTray1,"weather-snow",GTK_ICON_SIZE_LARGE_TOOLBAR);
  }

  // thunderstorm?
  // FIXME: i'm not sure if TS in in obstruct field
  if (strcmp(Mptr->WxObstruct[0],"TS")==0) {
    gtk_image_set_from_icon_name(imgClouds1,"weather-storm",GTK_ICON_SIZE_LARGE_TOOLBAR);
    gtk_image_set_from_icon_name(imgTray1,"weather-storm",GTK_ICON_SIZE_LARGE_TOOLBAR);
  }

  // wind direction
  // FIXME: for now only 4 directions, add 8
  int wd = Mptr->winData.windDir;
  // north
  if ( ((wd >= 0)&&(wd < 45)) || (wd >= 315) ) 
    gtk_image_set_from_icon_name(imgWind1,"go-down",GTK_ICON_SIZE_LARGE_TOOLBAR);
  // east
  if ((wd >= 45)&&(wd < 135)) 
    gtk_image_set_from_icon_name(imgWind1,"go-previous",GTK_ICON_SIZE_LARGE_TOOLBAR);
  // south
  if ((wd >= 135)&&(wd < 225)) 
    gtk_image_set_from_icon_name(imgWind1,"go-up",GTK_ICON_SIZE_LARGE_TOOLBAR);
  // west
  if ((wd >= 225)&&(wd < 315)) 
    gtk_image_set_from_icon_name(imgWind1,"go-next",GTK_ICON_SIZE_LARGE_TOOLBAR);
  // no wind, no icon
  if (ws <= 0)
    gtk_image_set_from_icon_name(imgWind1,"face-smile",GTK_ICON_SIZE_LARGE_TOOLBAR);


  // release temporary variables
  free(datetime);
  free(observation);
  free(cmd);

  free(title);
  free(temp);
  free(temp_b);
  free(pres_visi);
  free(wind);
  free(visi);
  free(clouds);
  

/*
/usr/share/icons/Tango/16x16/status/weather-severe-alert.png
/usr/share/icons/Tango/16x16/status/weather-showers.png
/usr/share/icons/Tango/16x16/status/weather-showers-scattered.png
/usr/share/icons/Tango/16x16/status/weather-snow.png
/usr/share/icons/Tango/16x16/status/weather-storm.png
*/









/*

  char * time = (char*)malloc(sizeof(char)*256);
  char * temperature = (char*)malloc(sizeof(char)*256);
  char * wind = (char*)malloc(sizeof(char)*256);
  char * pressure = (char*)malloc(sizeof(char)*256);
  char * clouds = (char*)malloc(sizeof(char)*256);
  
  weather_data_get("LZKZ",time,temperature,wind,pressure,clouds);

  // tray
  gtk_label_set_markup(labTray1,temperature);
  //gtk_image_set_from_icon_name(imgClouds1,"weather-few-clouds",GTK_ICON_SIZE_LARGE_TOOLBAR);

  // dialog
  //gtk_label_set_markup(labTitle1,"<b>Košice, Barca</b>");
  gtk_label_set_markup(labDateTime1,time);
  gtk_label_set_markup(labTemp1,temperature);
  gtk_label_set_markup(labWind1,wind);
  gtk_label_set_markup(labPressureVisibility1,pressure);
  //gtk_image_set_from_icon_name(imgClouds1,"weather-few-clouds",GTK_ICON_SIZE_LARGE_TOOLBAR);
  //gtk_image_set_from_icon_name(imgWind1,"gtk-dialog-error",GTK_ICON_SIZE_LARGE_TOOLBAR);
  
  free(time);
  free(temperature);
  free(wind);
  free(pressure);
  free(clouds);
  
  */
  
  return TRUE;
}
Пример #23
0
BerValue *
gda_ldap_attr_g_value_to_value (LdapConnectionData *cdata, const GValue *cvalue)
{
	BerValue *bv;

	if (!cvalue)
		return NULL;

	bv = g_new (struct berval, 1);

	if (G_VALUE_TYPE (cvalue) == G_TYPE_STRING) {
		const gchar *cstr;
		cstr = g_value_get_string (cvalue);
		bv->bv_val = g_strdup (cstr);
		bv->bv_len = strlen (cstr);
	}
	else if (G_VALUE_TYPE (cvalue) == G_TYPE_DATE_TIME) {
		GDateTime *ts;
		gchar *str;
		ts = g_value_get_boxed (cvalue);
		if (g_date_time_get_second (ts) == (gint) g_date_time_get_seconds (ts)) {
			if (g_date_time_get_utc_offset (ts) == 0)
				str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d",
															 g_date_time_get_year (ts),
															 g_date_time_get_month (ts),
															 g_date_time_get_day_of_month (ts),
															 g_date_time_get_hour (ts),
															 g_date_time_get_minute (ts),
															 g_date_time_get_second (ts));
			else {
				str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d",
															 g_date_time_get_year (ts),
															 g_date_time_get_month (ts),
															 g_date_time_get_day_of_month (ts),
															 g_date_time_get_hour (ts),
															 g_date_time_get_minute (ts),
															 g_date_time_get_second (ts));
				TO_IMPLEMENT;
			}
		}
		else {
			if (g_date_time_get_utc_offset (ts) == 0)
				str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d,%lu",
															 g_date_time_get_year (ts),
															 g_date_time_get_month (ts),
															 g_date_time_get_day_of_month (ts),
															 g_date_time_get_hour (ts),
															 g_date_time_get_minute (ts),
															 g_date_time_get_second (ts),
															 (gulong) ((g_date_time_get_seconds (ts) - g_date_time_get_second (ts)) * 1000000.0));
			else {
				str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d,%lu",
															 g_date_time_get_year (ts),
															 g_date_time_get_month (ts),
															 g_date_time_get_day_of_month (ts),
															 g_date_time_get_hour (ts),
															 g_date_time_get_minute (ts),
															 g_date_time_get_second (ts),
															 (gulong) ((g_date_time_get_seconds (ts) - g_date_time_get_second (ts)) * 1000000.0));
				TO_IMPLEMENT;
			}
		}
		bv->bv_val = str;
		bv->bv_len = strlen (str);
	}
	else if (G_VALUE_TYPE (cvalue) == G_TYPE_DATE) {
		GDate *date;
		gchar *str;
		date = (GDate*) g_value_get_boxed (cvalue);
		str = g_strdup_printf ("%04d-%02d-%02d", g_date_get_year (date), g_date_get_month (date),
				       g_date_get_day (date));
		bv->bv_val = str;
		bv->bv_len = strlen (str);
	}
	else if (G_VALUE_TYPE (cvalue) == GDA_TYPE_NULL) {
		bv->bv_val = NULL;
		bv->bv_len = 0;
	}
	else if (G_VALUE_TYPE (cvalue) == GDA_TYPE_BINARY) {
		TO_IMPLEMENT;
	}
	else if (G_VALUE_TYPE (cvalue) == GDA_TYPE_BLOB) {
		TO_IMPLEMENT;
	}
	else {
		gchar *str;
		str = gda_value_stringify (cvalue);
		bv->bv_val = str;
		bv->bv_len = strlen (str);
	}
	return bv;
}
/* Update the widgets based on the system time */
static void
update_time (CcDateTimePanel *self)
{
  CcDateTimePanelPrivate *priv = self->priv;
  GtkWidget *h_spinbutton;
  GtkWidget *m_spinbutton;
  GtkWidget *am_pm_button;
  char *label;
  gint hour;
  gint minute;
  gboolean use_ampm;

  h_spinbutton = W("h_spinbutton");
  m_spinbutton = W("m_spinbutton");
  am_pm_button = W("am_pm_button");

  g_signal_handlers_block_by_func (h_spinbutton, change_time, self);
  g_signal_handlers_block_by_func (m_spinbutton, change_time, self);
  g_signal_handlers_block_by_func (am_pm_button, am_pm_button_clicked, self);

  if (priv->clock_format == G_DESKTOP_CLOCK_FORMAT_12H)
    use_ampm = TRUE;
  else
    use_ampm = FALSE;

  hour = g_date_time_get_hour (priv->date);
  minute = g_date_time_get_minute (priv->date);

  if (!use_ampm)
    {
      /* Update the hours spinbutton */
      gtk_spin_button_set_range (GTK_SPIN_BUTTON (h_spinbutton), 0, 23);
      gtk_spin_button_set_value (GTK_SPIN_BUTTON (h_spinbutton), hour);
    }
  else
    {
      gboolean is_pm_time;

      is_pm_time = (hour >= 12);

      /* Update the AM/PM button */
      if (is_pm_time)
        gtk_stack_set_visible_child (GTK_STACK (priv->am_pm_stack), priv->pm_label);
      else
        gtk_stack_set_visible_child (GTK_STACK (priv->am_pm_stack), priv->am_label);

      /* Update the hours spinbutton */
      if (is_pm_time)
        hour -= 12;
      if (hour == 0)
        hour = 12;
      gtk_spin_button_set_value (GTK_SPIN_BUTTON (h_spinbutton), hour);
      gtk_spin_button_set_range (GTK_SPIN_BUTTON (h_spinbutton), 1, 12);
    }

  gtk_widget_set_visible (am_pm_button, use_ampm);

  /* Update the minutes spinbutton */
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (m_spinbutton), minute);

  g_signal_handlers_unblock_by_func (h_spinbutton, change_time, self);
  g_signal_handlers_unblock_by_func (m_spinbutton, change_time, self);
  g_signal_handlers_unblock_by_func (am_pm_button, am_pm_button_clicked, self);

  /* Update the time on the listbow row */
  if (use_ampm)
    {
      /* Translators: This is the full date and time format used in 12-hour mode. */
      label = g_date_time_format (priv->date, _("%e %B %Y, %l:%M %p"));
    }
  else
    {
      /* Translators: This is the full date and time format used in 24-hour mode. */
      label = g_date_time_format (priv->date, _("%e %B %Y, %R"));
    }

  gtk_label_set_text (GTK_LABEL (W ("datetime_label")), label);
  g_free (label);
}
Пример #25
0
gint
gst_date_time_get_hour (const GstDateTime * datetime)
{
  return g_date_time_get_hour (datetime->datetime);
}
Пример #26
0
/**
 * vik_datetime_edit_dialog:
 * @parent:         The parent window
 * @title:          The title to use for the dialog
 * @initial_time:   The inital date/time to be shown
 * @tz:             The #GTimeZone this dialog will operate in
 *
 * Returns: A time selected by the user via this dialog
 *          Even though a time of zero is notionally valid - consider it unlikely to be actually wanted!
 *          Thus if the time is zero then the dialog was cancelled or somehow an invalid date was encountered.
 */
time_t vik_datetime_edit_dialog ( GtkWindow *parent, const gchar *title, time_t initial_time, GTimeZone *tz )
{
	g_return_val_if_fail ( tz, 0 );

	GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
	                                                  parent,
	                                                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
	                                                  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
	                                                  GTK_STOCK_OK,     GTK_RESPONSE_ACCEPT,
	                                                  NULL );

	gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
	GtkWidget *response_w = NULL;
#if GTK_CHECK_VERSION (2, 20, 0)
	response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
#endif

	GtkWidget *label;
	GtkWidget *cal = gtk_calendar_new ();

	// Set according to the given date/time + timezone for display
	GDateTime *gdt_in = g_date_time_new_from_unix_utc ( (gint64)initial_time );
	GDateTime *gdt_tz = g_date_time_to_timezone ( gdt_in, tz );
	g_date_time_unref ( gdt_in );

	gtk_calendar_select_month ( GTK_CALENDAR(cal), g_date_time_get_month(gdt_tz)-1, g_date_time_get_year (gdt_tz) );
	gtk_calendar_select_day ( GTK_CALENDAR(cal), g_date_time_get_day_of_month(gdt_tz) );

	GtkWidget *hbox_time = gtk_hbox_new ( FALSE, 1 );

	label = gtk_label_new ( g_date_time_get_timezone_abbreviation(gdt_tz) );
	gtk_box_pack_start ( GTK_BOX(hbox_time), label, FALSE, FALSE, 5 );

	GtkWidget *sb_hours = gtk_spin_button_new_with_range ( 0.0, 23.0, 1.0 );
	gtk_box_pack_start ( GTK_BOX(hbox_time), sb_hours, FALSE, FALSE, 0 );
	gtk_spin_button_set_value ( GTK_SPIN_BUTTON(sb_hours), g_date_time_get_hour(gdt_tz) );
	g_signal_connect ( sb_hours, "output", G_CALLBACK(on_output), NULL );

	label = gtk_label_new ( ":" );
	gtk_box_pack_start ( GTK_BOX(hbox_time), label, FALSE, FALSE, 0 );

	GtkWidget *sb_minutes = gtk_spin_button_new_with_range ( 0.0, 59.0, 1.0 );
	gtk_box_pack_start ( GTK_BOX(hbox_time), sb_minutes, FALSE, FALSE, 0);
	gtk_spin_button_set_value ( GTK_SPIN_BUTTON(sb_minutes), g_date_time_get_minute(gdt_tz) );
	g_signal_connect ( sb_minutes, "output", G_CALLBACK(on_output), NULL );

	label = gtk_label_new ( ":" );
	gtk_box_pack_start(GTK_BOX(hbox_time), label, FALSE, FALSE, 0);

	GtkWidget *sb_seconds = gtk_spin_button_new_with_range ( 0.0, 59.0, 1.0 );
	gtk_box_pack_start ( GTK_BOX(hbox_time), sb_seconds, FALSE, FALSE, 0 );
	gtk_spin_button_set_value ( GTK_SPIN_BUTTON(sb_seconds), g_date_time_get_second(gdt_tz) );
	g_signal_connect ( sb_seconds, "output", G_CALLBACK(on_output), NULL );

	gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), cal, FALSE, FALSE, 0 );
	gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), hbox_time, FALSE, FALSE, 5 );

	if ( response_w )
		gtk_widget_grab_focus ( response_w );

	g_date_time_unref ( gdt_tz );

	gtk_widget_show_all ( dialog );
	if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) {
		gtk_widget_destroy ( dialog );
		return 0;
	}

	// Read values
	guint year = 0;
	guint month = 0;
	guint day = 0;
	guint hours = 0;
	guint minutes = 0;
	guint seconds = 0;

	gtk_calendar_get_date ( GTK_CALENDAR(cal), &year, &month, &day );
	hours = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(sb_hours) );
	minutes = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(sb_minutes) );
	seconds = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(sb_seconds) );

	gtk_widget_destroy(dialog);

	time_t ans = initial_time;
	GDateTime *gdt_ans = g_date_time_new ( tz, year, month+1, day, hours, minutes, (gdouble)seconds );
	if ( gdt_ans ) {
		ans = g_date_time_to_unix ( gdt_ans );
		g_date_time_unref ( gdt_ans );
	}

	return ans;
}
static void
set_time (GstRTSPTime * time, GstRTSPTime2 * time2, GstRTSPRangeUnit unit,
    GstClockTime clock_time)
{
  memset (time, 0, sizeof (GstRTSPTime));
  memset (time2, 0, sizeof (GstRTSPTime2));

  if (clock_time == GST_CLOCK_TIME_NONE) {
    time->type = GST_RTSP_TIME_END;
    return;
  }

  switch (unit) {
    case GST_RTSP_RANGE_SMPTE:
    case GST_RTSP_RANGE_SMPTE_30_DROP:
    {
      time->seconds = (guint64) (clock_time / GST_SECOND);
      time2->frames = 30003 * (clock_time % GST_SECOND) /
          (gdouble) (1001 * GST_SECOND);
      time->type = GST_RTSP_TIME_FRAMES;
      g_assert (time2->frames < 30);
      break;
    }
    case GST_RTSP_RANGE_SMPTE_25:
    {
      time->seconds = (guint64) (clock_time / GST_SECOND);
      time2->frames = (25 * (clock_time % GST_SECOND)) / (gdouble) GST_SECOND;
      time->type = GST_RTSP_TIME_FRAMES;
      g_assert (time2->frames < 25);
      break;
    }
    case GST_RTSP_RANGE_NPT:
    {
      time->seconds = (gdouble) clock_time / (gdouble) GST_SECOND;
      time->type = GST_RTSP_TIME_SECONDS;
      break;
    }
    case GST_RTSP_RANGE_CLOCK:
    {
      GDateTime *bt, *datetime;
      GstClockTime subsecond = clock_time % GST_SECOND;

      bt = g_date_time_new_utc (1900, 1, 1, 0, 0, 0.0);
      datetime = g_date_time_add_seconds (bt, clock_time / GST_SECOND);

      time2->year = g_date_time_get_year (datetime);
      time2->month = g_date_time_get_month (datetime);
      time2->day = g_date_time_get_day_of_month (datetime);

      time->seconds = g_date_time_get_hour (datetime) * 60 * 60;
      time->seconds += g_date_time_get_minute (datetime) * 60;
      time->seconds += g_date_time_get_seconds (datetime);
      time->seconds += (gdouble) subsecond / (gdouble) GST_SECOND;
      time->type = GST_RTSP_TIME_UTC;

      g_date_time_unref (bt);
      g_date_time_unref (datetime);
      break;
    }
  }

  if (time->seconds < 0.000000001)
    time->seconds = 0;
  if (time2->frames < 0.000000001)
    time2->frames = 0;
}
Пример #28
0
int DateTime::hour() const
{
    return g_date_time_get_hour(get());
}
Пример #29
0
static gint
g_calendar_gregorian_real_get_hour (GCalendar *calendar, /* IN */
                                    GDateTime *datetime) /* IN */
{
  return g_date_time_get_hour (datetime);
}