1 /********************************************************************\
2 * BitlBee -- An IRC to other IM-networks gateway *
4 * Copyright 2002-2010 Wilmer van der Gaast and others *
5 \********************************************************************/
7 /* Some stuff that doesn't belong anywhere else. */
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License with
21 the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22 if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 Suite 330, Boston, MA 02111-1307 USA
28 char *set_eval_timezone( set_t
*set
, char *value
)
32 if( strcmp( value
, "local" ) == 0 ||
33 strcmp( value
, "gmt" ) == 0 || strcmp( value
, "utc" ) == 0 )
36 /* Otherwise: +/- at the beginning optional, then one or more numbers,
37 possibly followed by a colon and more numbers. Don't bother bound-
38 checking them since users are free to shoot themselves in the foot. */
40 if( *s
== '+' || *s
== '-' )
46 while( *s
&& isdigit( *s
) ) s
++;
52 /* Otherwise, colon */
60 while( *s
&& isdigit( *s
) ) s
++;
63 return *s
== '\0' ? value
: SET_INVALID
;
66 char *irc_format_timestamp( irc_t
*irc
, time_t msg_ts
)
68 time_t now_ts
= time( NULL
);
72 /* If the timestamp is <= 0 or less than a minute ago, discard it as
73 it doesn't seem to add to much useful info and/or might be noise. */
74 if( msg_ts
<= 0 || msg_ts
> now_ts
- 60 )
77 set
= set_getstr( &irc
->b
->set
, "timezone" );
78 if( strcmp( set
, "local" ) == 0 )
80 localtime_r( &now_ts
, &now
);
81 localtime_r( &msg_ts
, &msg
);
85 int hr
, min
= 0, sign
= 60;
92 else if( set
[0] == '+' )
97 if( sscanf( set
, "%d:%d", &hr
, &min
) >= 1 )
99 msg_ts
+= sign
* ( hr
* 60 + min
);
100 now_ts
+= sign
* ( hr
* 60 + min
);
103 gmtime_r( &now_ts
, &now
);
104 gmtime_r( &msg_ts
, &msg
);
107 if( msg
.tm_year
== now
.tm_year
&& msg
.tm_yday
== now
.tm_yday
)
108 return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
109 msg
.tm_hour
, msg
.tm_min
, msg
.tm_sec
);
111 return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
112 "%02d:%02d:%02d\x02]\x02 ",
113 msg
.tm_year
+ 1900, msg
.tm_mon
+ 1, msg
.tm_mday
,
114 msg
.tm_hour
, msg
.tm_min
, msg
.tm_sec
);