ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/misc.c
Revision: 9865
Committed: Sat Jan 2 18:42:37 2021 UTC (3 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 2150 byte(s)
Log Message:
- Bump copyright years

File Contents

# User Rev Content
1 michael 5052 /*
2 michael 5351 * Copyright (c) 2002 Erik Fears
3 michael 9865 * Copyright (c) 2014-2021 ircd-hybrid development team
4 michael 5351 *
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 michael 5052
21     #include "setup.h"
22    
23     #include <stdio.h>
24 michael 7724 #include <string.h>
25 michael 5052 #include <time.h>
26    
27     #include "misc.h"
28    
29    
30 michael 6970 const char *
31     date_iso8601(time_t lclock)
32     {
33     static char buf[32];
34     static time_t lclock_last;
35    
36 michael 8555 if (lclock == 0)
37 michael 6970 lclock = time(0);
38    
39     if (lclock_last != lclock)
40     {
41     lclock_last = lclock;
42     strftime(buf, sizeof(buf), "%FT%T%z", localtime(&lclock));
43     }
44    
45     return buf;
46     }
47    
48 michael 5052 /*
49     * Split a time_t into an English-language explanation of how
50     * much time it represents, e.g. "2 hours 45 minutes 8 seconds"
51     */
52 michael 5917 const char *
53 michael 6968 time_dissect(time_t duration)
54 michael 5052 {
55 michael 6968 static char buf[32]; /* 32 = sizeof("9999999999999999 days, 23:59:59") */
56 michael 6568 unsigned int days = 0, hours = 0, minutes = 0, seconds = 0;
57 michael 5052
58 michael 6788 while (duration >= 60 * 60 * 24)
59 michael 5368 {
60 michael 6788 duration -= 60 * 60 * 24;
61 michael 6568 ++days;
62 michael 5368 }
63 michael 5052
64 michael 6788 while (duration >= 60 * 60)
65 michael 5368 {
66 michael 6788 duration -= 60 * 60;
67 michael 6568 ++hours;
68 michael 5368 }
69 michael 5052
70 michael 6788 while (duration >= 60)
71 michael 5368 {
72 michael 6788 duration -= 60;
73 michael 6568 ++minutes;
74 michael 5368 }
75 michael 5052
76 michael 6788 seconds = duration;
77 michael 5052
78 michael 6568 snprintf(buf, sizeof(buf), "%u day%s, %02u:%02u:%02u",
79     days, days == 1 ? "" : "s", hours, minutes, seconds);
80 michael 5368 return buf;
81 michael 5052 }
82 michael 7711
83 michael 7802 const char *
84 michael 7724 stripws(char *txt)
85 michael 7711 {
86 michael 7724 while (*txt == '\t' || *txt == ' ')
87     ++txt;
88 michael 7711
89 michael 7724 char *tmp = txt + strlen(txt) - 1;
90     while (tmp >= txt && (*tmp == '\t' || *tmp == ' '))
91     --tmp;
92 michael 7711
93 michael 7724 *(tmp + 1) = '\0';
94 michael 7711
95 michael 7724 return txt;
96 michael 7711 }

Properties

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