summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-09-19 17:35:52 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-09-19 17:35:52 -0700
commitdce08deb34939eaed349d315777214c3181c1a8d (patch)
tree4c9695b79277edba4cbf1e75dbcc4bec026511b6 /statistics.c
parentd14932058f191de2a812a9b3b9ad87c5febd2b3e (diff)
downloadsubsurface-dce08deb34939eaed349d315777214c3181c1a8d.tar.gz
Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t'
This makes the time type unambiguous, and we can use G_TYPE_INT64 for it in the divelist too. It also implements a portable (and thread-safe) "utc_mkdate()" function that acts kind of like gmtime_r(), but using the 64-bit timestamp_t. It matches our original "utc_mktime()". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/statistics.c b/statistics.c
index 5e1c8804a..35b9cecb9 100644
--- a/statistics.c
+++ b/statistics.c
@@ -364,7 +364,7 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive)
{
int idx;
struct dive *dp;
- struct tm *tm;
+ struct tm tm;
int current_year = 0;
int current_month = 0;
int year_iter = 0;
@@ -408,12 +408,12 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive)
process_dive(dp, &stats);
/* yearly statistics */
- tm = gmtime(&dp->when);
+ utc_mkdate(dp->when, &tm);
if (current_year == 0)
- current_year = tm->tm_year + 1900;
+ current_year = tm.tm_year + 1900;
- if (current_year != tm->tm_year + 1900) {
- current_year = tm->tm_year + 1900;
+ if (current_year != tm.tm_year) {
+ current_year = tm.tm_year + 1900;
process_dive(dp, &(stats_yearly[++year_iter]));
} else
process_dive(dp, &(stats_yearly[year_iter]));
@@ -423,10 +423,10 @@ static void process_all_dives(struct dive *dive, struct dive **prev_dive)
/* monthly statistics */
if (current_month == 0) {
- current_month = tm->tm_mon + 1;
+ current_month = tm.tm_mon + 1;
} else {
- if (current_month != tm->tm_mon + 1)
- current_month = tm->tm_mon + 1;
+ if (current_month != tm.tm_mon + 1)
+ current_month = tm.tm_mon + 1;
if (prev_month != current_month || prev_year != current_year)
month_iter++;
}
@@ -495,17 +495,17 @@ static void show_single_dive_stats(struct dive *dive)
const char *unit;
int idx, offset, gas_used;
struct dive *prev_dive;
- struct tm *tm;
+ struct tm tm;
process_all_dives(dive, &prev_dive);
- tm = gmtime(&dive->when);
+ utc_mkdate(dive->when, &tm);
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);
+ 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);