~ubuntu-branches/ubuntu/intrepid/haproxy/intrepid

« back to all changes in this revision

Viewing changes to src/time.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2008-03-09 21:30:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080309213029-8oupnrc607mg5uqw
Tags: 1.3.14.3-1
* New Upstream Version
* Add status argument support to init-script to conform to LSB.
* Cleanup pidfile after stop in init script. Init script return code fixups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
        return __tv_isgt(tv1, tv2);
143
143
}
144
144
 
 
145
char *human_time(int t, short hz_div) {
 
146
        static char rv[sizeof("24855d23h")+1];  // longest of "23h59m" and "59m59s"
 
147
        char *p = rv;
 
148
        int cnt=2;                              // print two numbers
 
149
 
 
150
        if (unlikely(t < 0 || hz_div <= 0)) {
 
151
                sprintf(p, "?");
 
152
                return rv;
 
153
        }
 
154
 
 
155
        if (unlikely(hz_div > 1))
 
156
                t /= hz_div;
 
157
 
 
158
        if (t >= DAY) {
 
159
                p += sprintf(p, "%dd", t / DAY);
 
160
                cnt--;
 
161
        }
 
162
 
 
163
        if (cnt && t % DAY / HOUR) {
 
164
                p += sprintf(p, "%dh", t % DAY / HOUR);
 
165
                cnt--;
 
166
        }
 
167
 
 
168
        if (cnt && t % HOUR / MINUTE) {
 
169
                p += sprintf(p, "%dm", t % HOUR / MINUTE);
 
170
                cnt--;
 
171
        }
 
172
 
 
173
        if ((cnt && t % MINUTE) || !t)                                  // also display '0s'
 
174
                p += sprintf(p, "%ds", t % MINUTE / SEC);
 
175
 
 
176
        return rv;
 
177
}
 
178
 
145
179
/*
146
180
 * Local variables:
147
181
 *  c-indent-level: 8