void DiveLogExportDialog::exportHTMLstatistics(const QString &filename) { QFile file(filename); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); int i = 0; out << "divestat=["; while (stats_yearly != NULL && stats_yearly[i].period) { out << "{"; out << "\"YEAR\":\"" << stats_yearly[i].period << "\","; out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\","; out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\","; out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\","; out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\","; out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\","; out << "\"AVG_DEPTH\":\"" << get_depth_string(stats_yearly[i].avg_depth) << "\","; out << "\"MIN_DEPTH\":\"" << get_depth_string(stats_yearly[i].min_depth) << "\","; out << "\"MAX_DEPTH\":\"" << get_depth_string(stats_yearly[i].max_depth) << "\","; out << "\"AVG_SAC\":\"" << get_volume_string(stats_yearly[i].avg_sac) << "\","; out << "\"MIN_SAC\":\"" << get_volume_string(stats_yearly[i].min_sac) << "\","; out << "\"MAX_SAC\":\"" << get_volume_string(stats_yearly[i].max_sac) << "\","; out << "\"AVG_TEMP\":\"" << QString::number(stats_yearly[i].combined_temp / stats_yearly[i].combined_count, 'f', 1) << "\","; out << "\"MIN_TEMP\":\"" << get_temp_units(stats_yearly[i].min_temp, NULL) << "\","; out << "\"MAX_TEMP\":\"" << get_temp_units(stats_yearly[i].max_temp, NULL) << "\","; out << "},"; i++; } out << "]"; file.close(); }
static void process_interval_stats(stats_t stats_interval, GtkTreeIter *parent, GtkTreeIter *row) { double value; const char *unit; char value_str[40]; GtkTreeStore *store; store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(yearly_tree))); /* Year or month */ snprintf(value_str, sizeof(value_str), "%d", stats_interval.period); add_row_to_tree(store, value_str, 0, row, parent); /* Dives */ snprintf(value_str, sizeof(value_str), "%d", stats_interval.selection_size); add_cell_to_tree(store, value_str, 1, row); /* Total duration */ add_cell_to_tree(store, get_time_string(stats_interval.total_time.seconds, 0), 2, row); /* Average dive duration */ add_cell_to_tree(store, get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size), 3, row); /* Shortest duration */ add_cell_to_tree(store, get_minutes(stats_interval.shortest_time.seconds), 4, row); /* Longest duration */ add_cell_to_tree(store, get_minutes(stats_interval.longest_time.seconds), 5, row); /* Average depth */ add_cell(store, row, stats_interval.avg_depth.mm, 6, TRUE); /* Smallest maximum depth */ add_cell(store, row, stats_interval.min_depth.mm, 7, TRUE); /* Deepest maximum depth */ add_cell(store, row, stats_interval.max_depth.mm, 8, TRUE); /* Average air consumption */ add_cell(store, row, stats_interval.avg_sac.mliter, 9, FALSE); /* Smallest average air consumption */ add_cell(store, row, stats_interval.min_sac.mliter, 10, FALSE); /* Biggest air consumption */ add_cell(store, row, stats_interval.max_sac.mliter, 11, FALSE); /* Average water temperature */ value = get_temp_units(stats_interval.min_temp, &unit); if (stats_interval.combined_temp && stats_interval.combined_count) { snprintf(value_str, sizeof(value_str), "%.1f %s", stats_interval.combined_temp / (stats_interval.combined_count * 1.0), unit); add_cell_to_tree(store, value_str, 12, row); } else { add_cell_to_tree(store, "", 12, row); } /* Coldest water temperature */ if (value > -100.0) { snprintf(value_str, sizeof(value_str), "%.1f %s\t", value, unit); add_cell_to_tree(store, value_str, 13, row); } else { add_cell_to_tree(store, "", 13, row); } /* Warmest water temperature */ value = get_temp_units(stats_interval.max_temp, &unit); if (value > -100.0) { snprintf(value_str, sizeof(value_str), "%.1f %s", value, unit); add_cell_to_tree(store, value_str, 14, row); } else { add_cell_to_tree(store, "", 14, row); } }
int Listfiles::get_minutesremanig(){ unsigned long long minu = 0; if (get_minutes()==-1)return 0; minu = (unsigned long long)get_hours()*60+(unsigned long long)get_minutes(); minu = minu-minu*card.getSdPosition()/card.getFileSize(); minu = minu%60; return (int) minu; }
static void exportHTMLstatistics(const QString filename, struct htmlExportSetting &hes) { QFile file(filename); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); stats_summary_auto_free stats; stats_t total_stats; calculate_stats_summary(&stats, hes.selectedOnly); total_stats.selection_size = 0; total_stats.total_time.seconds = 0; int i = 0; out << "divestat=["; if (hes.yearlyStatistics) { while (stats.stats_yearly != NULL && stats.stats_yearly[i].period) { out << "{"; out << "\"YEAR\":\"" << stats.stats_yearly[i].period << "\","; out << "\"DIVES\":\"" << stats.stats_yearly[i].selection_size << "\","; out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats.stats_yearly[i].total_time.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\","; out << "\"AVERAGE_TIME\":\"" << get_minutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\","; out << "\"SHORTEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].shortest_time.seconds) << "\","; out << "\"LONGEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].longest_time.seconds) << "\","; out << "\"AVG_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].avg_depth) << "\","; out << "\"MIN_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].min_depth) << "\","; out << "\"MAX_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].max_depth) << "\","; out << "\"AVG_SAC\":\"" << get_volume_string(stats.stats_yearly[i].avg_sac) << "\","; out << "\"MIN_SAC\":\"" << get_volume_string(stats.stats_yearly[i].min_sac) << "\","; out << "\"MAX_SAC\":\"" << get_volume_string(stats.stats_yearly[i].max_sac) << "\","; if (stats.stats_yearly[i].combined_count) { temperature_t avg_temp; avg_temp.mkelvin = stats.stats_yearly[i].combined_temp.mkelvin / stats.stats_yearly[i].combined_count; out << "\"AVG_TEMP\":\"" << get_temperature_string(avg_temp) << "\","; } else { out << "\"AVG_TEMP\":\"0.0\","; } out << "\"MIN_TEMP\":\"" << (stats.stats_yearly[i].min_temp.mkelvin == 0 ? 0 : get_temperature_string(stats.stats_yearly[i].min_temp)) << "\","; out << "\"MAX_TEMP\":\"" << (stats.stats_yearly[i].max_temp.mkelvin == 0 ? 0 : get_temperature_string(stats.stats_yearly[i].max_temp)) << "\","; out << "},"; total_stats.selection_size += stats.stats_yearly[i].selection_size; total_stats.total_time.seconds += stats.stats_yearly[i].total_time.seconds; i++; } exportHTMLstatisticsTotal(out, &total_stats); } out << "]"; file.close(); }
QVariant YearStatisticsItem::data(int column, int role) const { double value; QVariant ret; if (role == Qt::FontRole) { QFont font = defaultModelFont(); font.setBold(stats_interval.is_year); return font; } else if (role != Qt::DisplayRole) { return ret; } switch(column) { case YEAR: if (stats_interval.is_trip) { ret = stats_interval.location; } else { ret = stats_interval.period; } break; case DIVES: ret = stats_interval.selection_size; break; case TOTAL_TIME: ret = get_time_string(stats_interval.total_time.seconds, 0); break; case AVERAGE_TIME: ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size); break; case SHORTEST_TIME: ret = get_minutes(stats_interval.shortest_time.seconds); break; case LONGEST_TIME: ret = get_minutes(stats_interval.longest_time.seconds); break; case AVG_DEPTH: ret = get_depth_string(stats_interval.avg_depth); break; case MIN_DEPTH: ret = get_depth_string(stats_interval.min_depth); break; case MAX_DEPTH: ret = get_depth_string(stats_interval.max_depth); break; case AVG_SAC: ret = get_volume_string(stats_interval.avg_sac); break; case MIN_SAC: ret = get_volume_string(stats_interval.min_sac); break; case MAX_SAC: ret = get_volume_string(stats_interval.max_sac); break; case AVG_TEMP: if (stats_interval.combined_temp && stats_interval.combined_count) { ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1); } break; case MIN_TEMP: value = get_temp_units(stats_interval.min_temp, NULL); if (value > -100.0) ret = QString::number(value, 'f', 1); break; case MAX_TEMP: value = get_temp_units(stats_interval.max_temp, NULL); if (value > -100.0) ret = QString::number(value, 'f', 1); break; } return ret; }
std::string DateTime::to_short_time_string() const { throw_if_null(); // hh:mm StringFormat format("%1:%2"); format.set_arg(1, get_hour(), 2); format.set_arg(2, get_minutes(), 2); return format.get_result(); }
std::string DateTime::to_long_time_string() const { throw_if_null(); // hh:mm:ss StringFormat format("%1:%2:%3"); format.set_arg(1, get_hour(), 2); format.set_arg(2, get_minutes(), 2); format.set_arg(3, get_seconds(), 2); return format.get_result(); }
int Listfiles::get_hoursremaning(){ unsigned long long hours = 0; if (get_hours()==0)return 0; hours =(unsigned long long)get_hours()*60+(unsigned long long)get_minutes(); Serial.println((long)hours); hours = hours-hours*card.getSdPosition()/card.getFileSize(); Serial.println((long)hours); hours = hours/60; Serial.println((long)hours); return (int) hours; }
std::string DateTime::to_short_datetime_string() const { throw_if_null(); // 2008-04-01 StringFormat format("%1-%2-%3 %4:%5:%6"); format.set_arg(1, get_year(), 4); format.set_arg(2, get_month(), 2); format.set_arg(3, get_day(), 2); format.set_arg(4, get_hour(), 2); format.set_arg(5, get_minutes(), 2); format.set_arg(6, get_seconds(), 2); return format.get_result(); }
int main() { assert(fabs(seconds_difference(1800.0, 3600.0) - 1800.0) < DBL_EPSILON); assert(fabs(seconds_difference(3600.0, 1800.0) - -1800.0) < DBL_EPSILON ); assert(fabs(seconds_difference(1800.0, 2160.0) - 360.0) < DBL_EPSILON); assert(fabs(seconds_difference(1800.0, 1800.0) - 0.00) < DBL_EPSILON); assert(fabs(hours_difference(1800.0, 3600.0) - 0.5) < DBL_EPSILON); assert(fabs(hours_difference(3600.0, 1800.0) - -0.5) < DBL_EPSILON); assert(fabs(hours_difference(1800.0, 2160.0) - 0.1) < DBL_EPSILON); assert(fabs(hours_difference(1800.0, 1800.0) - 0.0) < DBL_EPSILON); assert(fabs(to_float_hours(0, 15, 0) - 0.25) < DBL_EPSILON); assert(fabs(to_float_hours(2, 45, 9) - 2.7525) < DBL_EPSILON); assert(fabs(to_float_hours(1, 0, 36) - 1.01) < DBL_EPSILON); assert(fabs(to_24_hour_clock(24) - 0) < DBL_EPSILON); assert(fabs(to_24_hour_clock(48) - 0) < DBL_EPSILON); assert(fabs(to_24_hour_clock(25) - 1) < DBL_EPSILON); assert(fabs(to_24_hour_clock(4) - 4) < DBL_EPSILON); assert(fabs(to_24_hour_clock(28.5) - 4.5) < DBL_EPSILON); assert(fabs(get_hours(3800) - 1) < DBL_EPSILON); assert(fabs(get_minutes(3800) - 3) < DBL_EPSILON); assert(fabs(get_seconds(3800) - 20) < DBL_EPSILON); assert(fabs(time_to_utc(+0, 12.0) - 12.0) < DBL_EPSILON); assert(fabs(time_to_utc(+1, 12.0) - 11.0) < DBL_EPSILON); assert(fabs(time_to_utc(-1, 12.0) - 13.0) < DBL_EPSILON); assert(fabs(time_to_utc(-11, 18.0) - 5.0) < DBL_EPSILON); assert(fabs(time_to_utc(-1, 0.0) - 1.0) < DBL_EPSILON); assert(fabs(time_to_utc(-1, 23.0) - 0.0) < DBL_EPSILON); assert(fabs(time_from_utc(+0, 12.0) - 12.0) < DBL_EPSILON); assert(fabs(time_from_utc(+1, 12.0) - 13.0) < DBL_EPSILON); assert(fabs(time_from_utc(-1, 12.0) - 11.0) < DBL_EPSILON); assert(fabs(time_from_utc(+6, 6.0) - 12.0) < DBL_EPSILON); assert(fabs(time_from_utc(-7, 6.0) - 23.0) < DBL_EPSILON); assert(fabs(time_from_utc(-1, 0.0) - 23.0) < DBL_EPSILON); assert(fabs(time_from_utc(-1, 23.0) - 22.0) < DBL_EPSILON); assert(fabs(time_from_utc(+1, 23.0) - 0.0) < DBL_EPSILON); return 0; }
/** * Update the ticking label in hh:mm:ss format. */ static void update_ticker_label (glong current_diff_seconds) { /** * Crude check to see if the preferences page is active * FIXME: Nicer way to check if the widgets are available rather * than a global boolean? */ gchar *str = g_strdup_printf ("%02d:%02d:%02d", (guint) get_hours(current_diff_seconds), (guint) get_minutes(current_diff_seconds), (guint) get_seconds(current_diff_seconds)); if (prefs_active) gtk_label_set_text (GTK_LABEL (countdown), (gchar *) str); if(si_alarm) gtk_widget_set_tooltip_text(si_alarm, str); g_free(str); }
std::string DateTime::to_string() const { throw_if_null(); // Mon Feb 3 12:32:54 2008 std::string months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; std::string days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; StringFormat format("%1 %2 %3 %4:%5:%6 %7"); format.set_arg(1, days[get_day_of_week()]); format.set_arg(2, months[get_month() - 1]); format.set_arg(3, get_day()); format.set_arg(4, get_hour(), 2); format.set_arg(5, get_minutes(), 2); format.set_arg(6, get_seconds(), 2); format.set_arg(7, get_year()); return format.get_result(); }
int main() { assert((seconds_difference(1800.0, 3600.0) - 1800.0 < DBL_EPSILON) && "test-1"); assert((seconds_difference(3600.0, 1800.0) -( -1800.0) < DBL_EPSILON) && "test-2"); assert((seconds_difference(1800.0, 2160.0) - 360.0 < DBL_EPSILON) && "test-3"); assert((seconds_difference(1800.0, 1800.0) < DBL_EPSILON) && "test-4"); assert((hours_difference(1800.0, 3600.0) - 0.5 < DBL_EPSILON) && "test-5"); assert((hours_difference(3600.0, 1800.0) -(-0.5) < DBL_EPSILON) && "test-6"); assert((hours_difference(1800.0, 2160.0) - 0.1 < DBL_EPSILON) && "test-7"); assert((hours_difference(1800.0, 1800.0) < DBL_EPSILON) && "test-8"); assert((to_float_hours(0, 15, 0) - 0.25 < DBL_EPSILON) && "test-9"); assert((to_float_hours(2, 45, 9) - 2.7525 < DBL_EPSILON) && "test-10"); assert((to_float_hours(1, 0, 36) - 1.01 < DBL_EPSILON) && "test-11"); assert((to_24_hour_clock(24) < DBL_EPSILON) && "test-12"); assert((to_24_hour_clock(48) < DBL_EPSILON) && "test-13"); assert((to_24_hour_clock(25) - 1 < DBL_EPSILON) && "test-14"); assert((to_24_hour_clock(4) - 4 < DBL_EPSILON) && "test-15"); assert((to_24_hour_clock(28.5) - 4.5 < DBL_EPSILON) && "test-16"); assert((get_hours(3800) == 1) && "test-17"); assert((get_minutes(3800) == 3) && "test-18"); assert((get_seconds(3800) == 20) && "test-19"); assert((time_to_utc(0, 12.0) - 12.0 < DBL_EPSILON) && "test-20"); assert((time_to_utc(1, 12.0) - 11.0 < DBL_EPSILON) && "test-21"); assert((time_to_utc(-1, 12.0) - 13.0 < DBL_EPSILON) && "test-22"); assert((time_to_utc(-11, 18.0) - 5.0 < DBL_EPSILON) && "test-23"); assert((time_to_utc(-1, 0.0) - 1.0 < DBL_EPSILON) && "test-24"); assert((time_to_utc(-1, 23.0) - 0.0 < DBL_EPSILON) && "test-25"); assert((time_from_utc(0, 12.0) - 12.0 < DBL_EPSILON) && "test-26"); assert((time_from_utc(1, 12.0) - 13.0 < DBL_EPSILON) && "test-27"); assert((time_from_utc(-1, 12.0) - 11.0 < DBL_EPSILON) && "test-28"); assert((time_from_utc(6, 6.0) - 12.0 < DBL_EPSILON) && "test-29"); assert((time_from_utc(-7, 6.0) - 23.0 < DBL_EPSILON) && "test-30"); assert((time_from_utc(-1, 0.0) - 23.0 < DBL_EPSILON) && "test-31"); assert((time_from_utc(-1, 23.0) - 22.0 < DBL_EPSILON) && "test-32"); assert((time_from_utc(1, 23.0) < DBL_EPSILON) && "test-33"); }
//--------------------------------------------------------------------------------------- //Output Date (dd-mm-yy) & Time (hh:mm:ss) int output_date_time(void){ // Get the current date and time ds1307_read_date_time(); // Get binary values + convert to ascii string bin_to_ascii(get_seconds(), secondASCII); bin_to_ascii(get_minutes(), minuteASCII); bin_to_ascii(get_hours(), hourASCII); bin_to_ascii(get_day(), dayASCII); bin_to_ascii(get_month(), monthASCII); bin_to_ascii(get_year(), yearASCII); // Send to LCD lcd_send_cmd(LINE1); lcd_printf(hourASCII); lcd_printf(":"); lcd_printf(minuteASCII); lcd_printf(":"); lcd_printf(secondASCII); lcd_send_cmd(LINE2); lcd_printf(dayASCII); lcd_printf("-"); lcd_printf(monthASCII); lcd_printf("-"); lcd_printf(yearASCII); return 0; }
oldgaa_error_code PRIVATE oldgaa_evaluate_time_cond(oldgaa_conditions_ptr condition, UNUSED(oldgaa_options_ptr options)) { int j = 0; int hr, min, sec; int cond_hr, cond_min, cond_sec; char cond[MAX_COND_LENGTH] = {NUL}; strcpy(cond, condition->value); if(oldgaa_strings_match(condition->authority, HOUR_SCALE_24)) { char *hr_str; char *min_str; char *sec_str; char *value; /* current hour */ hr_str = get_hr_24(); hr = atoi(hr_str); free(hr_str); /* current minutes */ min_str = get_minutes(); min = atoi(min_str); free(min_str); /* current seconds */ sec_str = get_seconds(); sec = atoi(sec_str); free(sec_str); /* get hours from condition value */ value = get_value(&j, cond, ':'); cond_hr = atoi(value); free(value); if (hr < cond_hr) return OLDGAA_NO; /* get minutes from condition value */ value = get_value(&j, cond, ':'); cond_min = atoi(value); free(value); /* get seconds from condition value */ value = get_value(&j, cond, '-'); cond_sec = atoi(value); free(value); if (cond_hr == hr) { /* if hours are equal, check minutes */ if (min < cond_min) return OLDGAA_NO; if (cond_min == min) { /* if minutes are equal, check seconds */ if (sec < cond_sec) return OLDGAA_NO; else goto success; } } /* hours are greater, check second time value */ /* get hours from condition value */ value = get_value(&j, cond, ':'); cond_hr = atoi(value); free(value); if (cond_hr < hr) return OLDGAA_NO; /* get minutes from condition value */ value = get_value(&j, cond, ':'); cond_min = atoi(value); free(value); /* get seconds from condition value */ value = get_value(&j, cond, ':'); cond_sec = atoi(value); free(value); if (cond_hr == hr) {/* if hours are equal, check minutes */ if (cond_min < min) return OLDGAA_NO; if (cond_min == min) { /* if minutes are equal, check seconds */ if (cond_sec < sec) return OLDGAA_NO; else goto success; } } success: return OLDGAA_YES; } return OLDGAA_MAYBE; /* unsupported time format */ }
int main() { assert(get_minutes(3800) == 3); }
void mc146818_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { switch (id) { case TIMER_PERIODIC: m_data[REG_C] |= REG_C_PF; update_irq(); break; case TIMER_CLOCK: if (!(m_data[REG_B] & REG_B_SET)) { /// TODO: find out how the real chip deals with updates when binary/bcd values are already outside the normal range int seconds = get_seconds() + 1; if (seconds < 60) { set_seconds(seconds); } else { set_seconds(0); int minutes = get_minutes() + 1; if (minutes < 60) { set_minutes(minutes); } else { set_minutes(0); int hours = get_hours() + 1; if (hours < 24) { set_hours(hours); } else { set_hours(0); int dayofweek = get_dayofweek() + 1; if (dayofweek <= 7) { set_dayofweek(dayofweek); } else { set_dayofweek(1); } int dayofmonth = get_dayofmonth() + 1; if (dayofmonth <= gregorian_days_in_month(get_month(), get_year() + 2000)) { set_dayofmonth(dayofmonth); } else { set_dayofmonth(1); int month = get_month() + 1; if (month <= 12) { set_month(month); } else { set_month(1); set_year((get_year() + 1) % 100); } } } } } if ((m_data[REG_ALARM_SECONDS] == m_data[REG_SECONDS] || (m_data[REG_ALARM_SECONDS] & ALARM_DONTCARE) == ALARM_DONTCARE) && (m_data[REG_ALARM_MINUTES] == m_data[REG_MINUTES] || (m_data[REG_ALARM_MINUTES] & ALARM_DONTCARE) == ALARM_DONTCARE) && (m_data[REG_ALARM_HOURS] == m_data[REG_HOURS] || (m_data[REG_ALARM_HOURS] & ALARM_DONTCARE) == ALARM_DONTCARE)) { // set the alarm interrupt flag AF m_data[REG_C] |= REG_C_AF; } // set the update-ended interrupt Flag UF m_data[REG_C] |= REG_C_UF; update_irq(); m_last_refresh = machine().time(); } break; } }
MicroTime::MicroTime(qint64 time) :QTime(get_hours(time) % 60, get_minutes(time) % 60, get_seconds(time) % 60 ) {}