static void date_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { int val; struct tm *tm; time_t when; char buffer[40]; gtk_tree_model_get(model, iter, DIVE_DATE, &val, -1); /* 2038 problem */ when = val; tm = gmtime(&when); snprintf(buffer, sizeof(buffer), "%s, %s %d, %d %02d:%02d", weekday(tm->tm_wday), monthname(tm->tm_mon), tm->tm_mday, tm->tm_year + 1900, tm->tm_hour, tm->tm_min); g_object_set(renderer, "text", buffer, NULL); }
static timestamp_t parse_date(const char *date) { int hour, min, sec; struct tm tm; char *p; memset(&tm, 0, sizeof(tm)); tm.tm_mday = strtol(date, &p, 10); if (tm.tm_mday < 1 || tm.tm_mday > 31) return 0; for (tm.tm_mon = 0; tm.tm_mon < 12; tm.tm_mon++) { if (!memcmp(p, monthname(tm.tm_mon), 3)) break; } if (tm.tm_mon > 11) return 0; date = p+3; tm.tm_year = strtol(date, &p, 10); if (date == p) return 0; if (tm.tm_year < 70) tm.tm_year += 2000; if (tm.tm_year < 100) tm.tm_year += 1900; if (sscanf(p, "%d:%d:%d", &hour, &min, &sec) != 3) return 0; tm.tm_hour = hour; tm.tm_min = min; tm.tm_sec = sec; return utc_mktime(&tm); }
int localhttptime(struct tm *tm, char *buf, int size) { return snprintf(buf, size, "%s, %d %s %d %02d:%02d:%02d %s", dayname(tm->tm_wday), tm->tm_mday, monthname(tm->tm_mon), 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec, #ifdef WIN32 ""); #else tm->tm_zone); #endif }
int localsmtptime(struct tm *tm, char *buf, int size) { int tzo = #ifdef WIN32 0; #else RFC822TimeZone(tm->tm_zone)*100; #endif return snprintf(buf, size, "%s, %02d %s %d %02d:%02d:%02d %s%04d", dayname(tm->tm_wday), tm->tm_mday, monthname(tm->tm_mon), 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec, tzo<0?"-":"", abs(tzo)); }
QString get_short_dive_date_string(timestamp_t when) { struct tm tm; utc_mkdate(when, &tm); return translate("gettextFromC", "%1 %2, %3\n%4:%5") .arg(monthname(tm.tm_mon)) .arg(tm.tm_mday) .arg(tm.tm_year + 1900) .arg(tm.tm_hour, 2, 10, QChar('0')) .arg(tm.tm_min, 2, 10, QChar('0')); }
QString get_dive_date_string(timestamp_t when) { struct tm tm; utc_mkdate(when, &tm); return translate("gettextFromC", "%1, %2 %3, %4 %5:%6") .arg(weekday(tm.tm_wday)) .arg(monthname(tm.tm_mon)) .arg(tm.tm_mday) .arg(tm.tm_year + 1900) .arg(tm.tm_hour, 2, 10, QChar('0')) .arg(tm.tm_min, 2, 10, QChar('0')); }
void show_dive_stats(struct dive *dive) { char buf[80]; double value; int decimals; const char *unit; int idx, offset, gas_used; struct dive *prev_dive; struct tm *tm; process_all_dives(dive, &prev_dive); tm = gmtime(&dive->when); snprintf(buf, sizeof(buf), "%s, %s %d, %d %2d:%02d", weekday(tm->tm_wday), monthname(tm->tm_mon), tm->tm_mday, tm->tm_year + 1900, tm->tm_hour, tm->tm_min); set_label(info_stat_w.date, buf); set_label(info_stat_w.dive_time, "%d min", (dive->duration.seconds + 30) / 60); if (prev_dive) set_label(info_stat_w.surf_intv, get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(info_stat_w.surf_intv, "unknown"); value = get_depth_units(dive->maxdepth.mm, &decimals, &unit); set_label(info_stat_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dive->meandepth.mm, &decimals, &unit); set_label(info_stat_w.avg_depth, "%.*f %s", decimals, value, unit); if (dive->watertemp.mkelvin) { value = get_temp_units(dive->watertemp.mkelvin, &unit); set_label(info_stat_w.water_temp, "%.1f %s", value, unit); } else set_label(info_stat_w.water_temp, ""); value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) { set_label(info_stat_w.sac, "%.*f %s/min", decimals, value, unit); } else set_label(info_stat_w.sac, ""); set_label(info_stat_w.otu, "%d", dive->otu); offset = 0; gas_used = 0; buf[0] = '\0'; /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; unsigned int start, end; start = cyl->start.mbar ? : cyl->sample_start.mbar; end = cyl->end.mbar ? : cyl->sample_end.mbar; /* we assume that every valid cylinder has either a working pressure * or a size; but for good measure let's also accept cylinders with * a starting or ending pressure*/ if (cyl->type.workingpressure.mbar || cyl->type.size.mliter || start || end) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = cyl->gasmix.o2.permille ? : 209; if (offset > 0) { snprintf(buf+offset, 80-offset, ", "); offset += 2; } snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (cyl->gasmix.he.permille + 5) / 10); offset = strlen(buf); } /* and if we have size, start and end pressure, we can * calculate the total gas used */ if (cyl->type.size.mliter && start && end) gas_used += cyl->type.size.mliter / 1000.0 * (start - end); }
static void show_single_dive_stats(struct dive *dive) { char buf[80]; double value; int decimals; const char *unit; int idx, offset, gas_used; struct dive *prev_dive; struct tm tm; process_all_dives(dive, &prev_dive); utc_mkdate(dive->when, &tm); snprintf(buf, sizeof(buf), /*++GETTEXT 80 chars: weekday, monthname, day, year, hour, min */ _("%1$s, %2$s %3$d, %4$d %5$2d:%6$02d"), weekday(tm.tm_wday), monthname(tm.tm_mon), tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min); set_label(single_w.date, buf); set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60); if (prev_dive) set_label(single_w.surf_intv, get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(single_w.surf_intv, _("unknown")); value = get_depth_units(dive->maxdepth.mm, &decimals, &unit); set_label(single_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dive->meandepth.mm, &decimals, &unit); set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit); if (dive->watertemp.mkelvin) { value = get_temp_units(dive->watertemp.mkelvin, &unit); set_label(single_w.water_temp, "%.1f %s", value, unit); } else set_label(single_w.water_temp, ""); value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) { set_label(single_w.sac, _("%.*f %s/min"), decimals, value, unit); } else set_label(single_w.sac, ""); set_label(single_w.otu, "%d", dive->otu); offset = 0; gas_used = 0; buf[0] = '\0'; /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; unsigned int start, end; start = cyl->start.mbar ? : cyl->sample_start.mbar; end = cyl->end.mbar ? : cyl->sample_end.mbar; if (!cylinder_none(cyl)) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = cyl->gasmix.o2.permille ? : AIR_PERMILLE; if (offset > 0) { snprintf(buf+offset, 80-offset, ", "); offset += 2; } snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (cyl->gasmix.he.permille + 5) / 10); offset = strlen(buf); } /* and if we have size, start and end pressure, we can * calculate the total gas used */ if (cyl->type.size.mliter && start && end) gas_used += cyl->type.size.mliter / 1000.0 * (start - end); }
static int dive_cb(const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata) { int rc; dc_parser_t *parser = NULL; device_data_t *devdata = userdata; dc_datetime_t dt = {0}; struct tm tm; struct dive *dive; rc = create_parser(devdata, &parser); if (rc != DC_STATUS_SUCCESS) { dev_info(devdata, _("Unable to create parser for %s %s"), devdata->vendor, devdata->product); return rc; } rc = dc_parser_set_data(parser, data, size); if (rc != DC_STATUS_SUCCESS) { dev_info(devdata, _("Error registering the data")); dc_parser_destroy(parser); return rc; } import_dive_number++; dive = alloc_dive(); rc = dc_parser_get_datetime(parser, &dt); if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { dev_info(devdata, _("Error parsing the datetime")); dc_parser_destroy(parser); return rc; } tm.tm_year = dt.year; tm.tm_mon = dt.month-1; tm.tm_mday = dt.day; tm.tm_hour = dt.hour; tm.tm_min = dt.minute; tm.tm_sec = dt.second; dive->when = utc_mktime(&tm); // Parse the divetime. dev_info(devdata, _("Dive %d: %s %d %04d"), import_dive_number, monthname(tm.tm_mon), tm.tm_mday, year(tm.tm_year)); unsigned int divetime = 0; rc = dc_parser_get_field (parser, DC_FIELD_DIVETIME, 0, &divetime); if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { dev_info(devdata, _("Error parsing the divetime")); dc_parser_destroy(parser); return rc; } dive->duration.seconds = divetime; // Parse the maxdepth. double maxdepth = 0.0; rc = dc_parser_get_field(parser, DC_FIELD_MAXDEPTH, 0, &maxdepth); if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { dev_info(devdata, _("Error parsing the maxdepth")); dc_parser_destroy(parser); return rc; } dive->maxdepth.mm = maxdepth * 1000 + 0.5; // Parse the gas mixes. unsigned int ngases = 0; rc = dc_parser_get_field(parser, DC_FIELD_GASMIX_COUNT, 0, &ngases); if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { dev_info(devdata, _("Error parsing the gas mix count")); dc_parser_destroy(parser); return rc; } // Check if the libdivecomputer version already supports salinity double salinity = 1.03; #ifdef DC_FIELD_SALINITY rc = dc_parser_get_field(parser, DC_FIELD_SALINITY, 0, &salinity); if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { dev_info(devdata, _("Error obtaining water salinity")); dc_parser_destroy(parser); return rc; } #endif dive->salinity = salinity * 10000.0 + 0.5; rc = parse_gasmixes(devdata, dive, parser, ngases); if (rc != DC_STATUS_SUCCESS) { dev_info(devdata, _("Error parsing the gas mix")); dc_parser_destroy(parser); return rc; } // Initialize the sample data. rc = parse_samples(devdata, &dive, parser); if (rc != DC_STATUS_SUCCESS) { dev_info(devdata, _("Error parsing the samples")); dc_parser_destroy(parser); return rc; } dc_parser_destroy(parser); /* If we already saw this dive, abort. */ if (!devdata->force_download && find_dive(dive, devdata)) return 0; dive->downloaded = TRUE; record_dive(dive); mark_divelist_changed(TRUE); return 1; }
int localmboxtime(struct tm *tm, char *buf, int size) { return snprintf(buf, size, "%s %s%s%d %02d:%02d:%02d %d", dayname(tm->tm_wday), monthname(tm->tm_mon), tm->tm_mday < 10 ? " " : " ", tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, 1900+tm->tm_year); }
int httptime(struct tm *tm, char *buf, int size) { return snprintf(buf, size, "%s, %d %s %d %02d:%02d:%02d GMT", dayname(tm->tm_wday), tm->tm_mday, monthname(tm->tm_mon), 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); }
/* we try to show the data from the currently selected divecomputer * right now for some values (e.g., surface pressure) we could fall back * to dive data, but for consistency we don't. */ static void show_single_dive_stats(struct dive *dive) { char buf[256]; double value; int decimals; const char *unit; int idx, offset, gas_used, mbar; struct dive *prev_dive; struct tm tm; struct divecomputer *dc; process_all_dives(dive, &prev_dive); if (!dive) return; dc = select_dc(&dive->dc); utc_mkdate(dive->when, &tm); snprintf(buf, sizeof(buf), /*++GETTEXT 80 chars: weekday, monthname, day, year, hour, min */ _("%1$s, %2$s %3$d, %4$d %5$2d:%6$02d"), weekday(tm.tm_wday), monthname(tm.tm_mon), tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min); set_label(single_w.date, buf); set_label(single_w.dive_time, _("%d min"), (dive->duration.seconds + 30) / 60); if (prev_dive) set_label(single_w.surf_intv, get_time_string(dive->when - (prev_dive->when + prev_dive->duration.seconds), 4)); else set_label(single_w.surf_intv, _("unknown")); value = get_depth_units(dc->maxdepth.mm, &decimals, &unit); set_label(single_w.max_depth, "%.*f %s", decimals, value, unit); value = get_depth_units(dc->meandepth.mm, &decimals, &unit); set_label(single_w.avg_depth, "%.*f %s", decimals, value, unit); set_label(single_w.viz, star_strings[dive->visibility]); if (dc->watertemp.mkelvin) { value = get_temp_units(dc->watertemp.mkelvin, &unit); set_label(single_w.water_temp, "%.1f %s", value, unit); } else { set_label(single_w.water_temp, ""); } if (dc->airtemp.mkelvin) { value = get_temp_units(dc->airtemp.mkelvin, &unit); set_label(single_w.air_temp, "%.1f %s", value, unit); } else { if (dive->airtemp.mkelvin) { value = get_temp_units(dive->airtemp.mkelvin, &unit); set_label(single_w.air_temp, "%.1f %s", value, unit); } else { set_label(single_w.air_temp, ""); } } mbar = dc->surface_pressure.mbar; /* it would be easy to get dive data here: * if (!mbar) * mbar = get_surface_pressure_in_mbar(dive, FALSE); */ if (mbar) { set_label(single_w.air_press, "%d mbar", mbar); } else { set_label(single_w.air_press, ""); } value = get_volume_units(dive->sac, &decimals, &unit); if (value > 0) set_label(single_w.sac, _("%.*f %s/min"), decimals, value, unit); else set_label(single_w.sac, ""); set_label(single_w.otu, "%d", dive->otu); offset = 0; gas_used = 0; buf[0] = '\0'; /* for the O2/He readings just create a list of them */ for (idx = 0; idx < MAX_CYLINDERS; idx++) { cylinder_t *cyl = &dive->cylinder[idx]; pressure_t start, end; start = cyl->start.mbar ? cyl->start : cyl->sample_start; end = cyl->end.mbar ?cyl->sample_end : cyl->sample_end; if (!cylinder_none(cyl)) { /* 0% O2 strangely means air, so 21% - I don't like that at all */ int o2 = get_o2(&cyl->gasmix); int he = get_he(&cyl->gasmix); if (offset > 0) { snprintf(buf+offset, 80-offset, ", "); offset += 2; } snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (he + 5) / 10); offset = strlen(buf); } /* and if we have size, start and end pressure, we can * calculate the total gas used */ if (start.mbar && end.mbar) gas_used += gas_volume(cyl, start) - gas_volume(cyl, end); } set_label(single_w.o2he, buf); if (gas_used) { value = get_volume_units(gas_used, &decimals, &unit); set_label(single_w.gas_used, "%.*f %s", decimals, value, unit); } else { set_label(single_w.gas_used, ""); } }