ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/misc.c
Revision: 5207
Committed: Mon Dec 29 19:38:22 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3071 byte(s)
Log Message:
- Removed AC_HEADER_STDC configure test

File Contents

# Content
1 /*
2 Copyright (C) 2002 Erik Fears
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16
17 Foundation, Inc.
18 59 Temple Place - Suite 330
19 Boston, MA 02111-1307, USA.
20
21 */
22
23 #include "setup.h"
24
25 #include <stdio.h>
26 #include <time.h>
27 #include <string.h>
28
29 #include "compat.h"
30 #include "config.h"
31 #include "misc.h"
32
33
34 /*
35 * Split a time_t into an English-language explanation of how
36 * much time it represents, e.g. "2 hours 45 minutes 8 seconds"
37 */
38 char *dissect_time(time_t time)
39 {
40 static char buf[64];
41 unsigned int years, weeks, days, hours, minutes, seconds;
42
43 years = weeks = days = hours = minutes = seconds = 0;
44
45 while (time >= 60 * 60 * 24 * 365)
46 {
47 time -= 60 * 60 * 24 * 365;
48 years++;
49 }
50
51 while (time >= 60 * 60 * 24 * 7)
52 {
53 time -= 60 * 60 * 24 * 7;
54 weeks++;
55 }
56
57 while (time >= 60 * 60 * 24)
58 {
59 time -= 60 * 60 * 24;
60 days++;
61 }
62
63 while (time >= 60 * 60)
64 {
65 time -= 60 * 60;
66 hours++;
67 }
68
69 while (time >= 60)
70 {
71 time -= 60;
72 minutes++;
73 }
74
75 seconds = time;
76
77 if (years)
78 {
79 snprintf(buf, sizeof(buf),
80 "%d year%s, %d week%s, %d day%s, %02d:%02d:%02d",
81 years, years == 1 ? "" : "s", weeks,
82 weeks == 1 ? "" : "s", days, days == 1 ? "" : "s",
83 hours, minutes, seconds);
84 }
85 else if (weeks)
86 {
87 snprintf(buf, sizeof(buf),
88 "%d week%s, %d day%s, %02d:%02d:%02d", weeks,
89 weeks == 1 ? "" : "s", days, days == 1 ? "" : "s",
90 hours, minutes, seconds);
91 }
92 else if (days)
93 {
94 snprintf(buf, sizeof(buf), "%d day%s, %02d:%02d:%02d",
95 days, days == 1 ? "" : "s", hours, minutes, seconds);
96 }
97 else if (hours)
98 {
99 if (minutes || seconds)
100 {
101 snprintf(buf, sizeof(buf),
102 "%d hour%s, %d minute%s, %d second%s", hours,
103 hours == 1 ? "" : "s", minutes,
104 minutes == 1 ? "" : "s", seconds,
105 seconds == 1 ? "" : "s");
106 }
107 else
108 {
109 snprintf(buf, sizeof(buf), "%d hour%s", hours,
110 hours == 1 ? "" : "s");
111 }
112 }
113 else if (minutes)
114 {
115 snprintf(buf, sizeof(buf), "%d minute%s, %d second%s",
116 minutes, minutes == 1 ? "" : "s", seconds,
117 seconds == 1 ? "" : "s");
118 }
119 else
120 {
121 snprintf(buf, sizeof(buf), "%d second%s", seconds,
122 seconds == 1 ? "" : "s");
123 }
124
125 return(buf);
126 }

Properties

Name Value
svn:eol-style native
svn:keywords Id