ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.1.x/src/misc.c
Revision: 7004
Committed: Fri Jan 1 00:06:28 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 1900 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * Copyright (c) 2002 Erik Fears
3 * Copyright (c) 2014-2016 ircd-hybrid development team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20
21 #include "setup.h"
22
23 #include <stdio.h>
24 #include <time.h>
25
26 #include "misc.h"
27
28
29 const char *
30 date_iso8601(time_t lclock)
31 {
32 static char buf[32];
33 static time_t lclock_last;
34
35 if (!lclock)
36 lclock = time(0);
37
38 if (lclock_last != lclock)
39 {
40 lclock_last = lclock;
41 strftime(buf, sizeof(buf), "%FT%T%z", localtime(&lclock));
42 }
43
44 return buf;
45 }
46
47 /*
48 * Split a time_t into an English-language explanation of how
49 * much time it represents, e.g. "2 hours 45 minutes 8 seconds"
50 */
51 const char *
52 time_dissect(time_t duration)
53 {
54 static char buf[32]; /* 32 = sizeof("9999999999999999 days, 23:59:59") */
55 unsigned int days = 0, hours = 0, minutes = 0, seconds = 0;
56
57 while (duration >= 60 * 60 * 24)
58 {
59 duration -= 60 * 60 * 24;
60 ++days;
61 }
62
63 while (duration >= 60 * 60)
64 {
65 duration -= 60 * 60;
66 ++hours;
67 }
68
69 while (duration >= 60)
70 {
71 duration -= 60;
72 ++minutes;
73 }
74
75 seconds = duration;
76
77 snprintf(buf, sizeof(buf), "%u day%s, %02u:%02u:%02u",
78 days, days == 1 ? "" : "s", hours, minutes, seconds);
79 return buf;
80 }

Properties

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