|
|
1.1 root 1: /* msgdate.c */
2:
3: /* Synchronet RFC822 message date/time string conversion routines */
4:
1.1.1.2 ! root 5: /* $Id: msgdate.c,v 1.3 2007/08/13 22:12:19 deuce Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: /****************************************************************************/
41: /* Convert when_t structure to RFC822 date header field (string) */
42: /****************************************************************************/
43: char* DLLCALL msgdate(when_t when, char* buf)
44: {
45: struct tm tm;
46: char plus='+';
47: short tz;
1.1.1.2 ! root 48: time_t tt;
1.1 root 49:
50: tz=smb_tzutc(when.zone);
51: if(tz<0) {
52: plus='-';
53: tz=-tz;
54: }
1.1.1.2 ! root 55:
! 56: tt=when.time;
! 57: if(localtime_r(&tt,&tm)==NULL)
1.1 root 58: memset(&tm,0,sizeof(tm));
59: sprintf(buf,"%s, %d %s %d %02d:%02d:%02d %c%02u%02u"
60: ,wday[tm.tm_wday]
61: ,tm.tm_mday
62: ,mon[tm.tm_mon]
63: ,1900+tm.tm_year
64: ,tm.tm_hour
65: ,tm.tm_min
66: ,tm.tm_sec
67: /* RFC1123: implementations SHOULD use numeric timezones instead of timezone names */
68: ,plus, tz/60, tz%60
69: );
70: return(buf);
71: }
72:
73: /****************************************************************************/
74: /* Convert RFC822 date header field to when_t structure */
75: /* dd mon yyyy hh:mm:ss [zone] */
76: /****************************************************************************/
77: when_t DLLCALL rfc822date(char* date)
78: {
79: char* p=date;
80: char str[32];
81: char month[32];
82: when_t when;
83: struct tm tm;
84:
85: memset(&tm,0,sizeof(tm));
86: memset(&when,0,sizeof(when));
87:
88: while(*p && *p<=' ') p++;
89: while(*p && !isdigit(*p)) p++;
90: /* DAY */
91: tm.tm_mday=atoi(p);
92: while(*p && isdigit(*p)) p++;
93: /* MONTH */
94: while(*p && *p<=' ') p++;
95: sprintf(month,"%3.3s",p);
96: if(!stricmp(month,"jan"))
97: tm.tm_mon=0;
98: else if(!stricmp(month,"feb"))
99: tm.tm_mon=1;
100: else if(!stricmp(month,"mar"))
101: tm.tm_mon=2;
102: else if(!stricmp(month,"apr"))
103: tm.tm_mon=3;
104: else if(!stricmp(month,"may"))
105: tm.tm_mon=4;
106: else if(!stricmp(month,"jun"))
107: tm.tm_mon=5;
108: else if(!stricmp(month,"jul"))
109: tm.tm_mon=6;
110: else if(!stricmp(month,"aug"))
111: tm.tm_mon=7;
112: else if(!stricmp(month,"sep"))
113: tm.tm_mon=8;
114: else if(!stricmp(month,"oct"))
115: tm.tm_mon=9;
116: else if(!stricmp(month,"nov"))
117: tm.tm_mon=10;
118: else
119: tm.tm_mon=11;
120: p+=4;
121: /* YEAR */
122: tm.tm_year=atoi(p);
123: if(tm.tm_year<Y2K_2DIGIT_WINDOW)
124: tm.tm_year+=100;
125: else if(tm.tm_year>1900)
126: tm.tm_year-=1900;
127:
128: while(*p && isdigit(*p)) p++;
129: /* HOUR */
130: while(*p && *p<=' ') p++;
131: tm.tm_hour=atoi(p);
132: while(*p && isdigit(*p)) p++;
133: /* MINUTE */
134: if(*p) p++;
135: tm.tm_min=atoi(p);
136: while(*p && isdigit(*p)) p++;
137: /* SECONDS */
138: if(*p) p++;
139: tm.tm_sec=atoi(p);
140: while(*p && isdigit(*p)) p++;
141: /* TIME ZONE */
142: while(*p && *p<=' ') p++;
143: if(*p) {
144: if(isdigit(*p) || *p=='-' || *p=='+') { /* [+|-]HHMM format */
145: if(*p=='+') p++;
146: sprintf(str,"%.*s",*p=='-'? 3:2,p);
147: when.zone=atoi(str)*60;
148: p+=(*p=='-') ? 3:2;
149: if(when.zone<0)
150: when.zone-=atoi(p);
151: else
152: when.zone+=atoi(p);
153: }
154: else if(!strnicmp(p,"PDT",3))
155: when.zone=(short)PDT;
156: else if(!strnicmp(p,"MDT",3))
157: when.zone=(short)MDT;
158: else if(!strnicmp(p,"CDT",3))
159: when.zone=(short)CDT;
160: else if(!strnicmp(p,"EDT",3))
161: when.zone=(short)EDT;
162: else if(!strnicmp(p,"PST",3))
163: when.zone=(short)PST;
164: else if(!strnicmp(p,"MST",3))
165: when.zone=(short)MST;
166: else if(!strnicmp(p,"CST",3))
167: when.zone=(short)CST;
168: else if(!strnicmp(p,"EST",3))
169: when.zone=(short)EST;
170: }
171:
172: tm.tm_isdst=-1; /* Don't adjust for daylight-savings-time */
173: when.time=mktime(&tm);
174:
175: return(when);
176: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.