]> err.no Git - sope/blob - sope-mime/NGMime/NSCalendarDate+RFC822.m
more code directory reorganizations
[sope] / sope-mime / NGMime / NSCalendarDate+RFC822.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "common.h"
24
25 @implementation NSCalendarDate(RFC822Dates)
26
27 static NSString *dateFormats[] = {
28   /*
29     short-weekday, day short-month year hour:minute:second timezoneoffset
30     eg: Mon, 01 Mar 1999 13:13:13 +0000
31   */
32   @"%a, %d %b %Y %H:%M:%S %z",
33
34   /*
35     short-weekday, day short-month year hour:minute:second timezonename
36     eg: Mon, 01 Mar 1999 13:13:13 GMT
37   */
38   @"%a, %d %b %Y %H:%M:%S %Z",
39
40   /*
41     short-weekday, day short-month year hour:minute:second timezonename
42     eg: Mon, 01 Mar 1999 13:13 +0000
43   */
44   @"%a, %d %b %Y %H:%M %z",
45
46   /*
47     short-weekday, day short-month year hour:minute:second timezonename
48     eg: Mon, 01 Mar 1999 13:13 (+0000)
49   */
50   @"%a, %d %b %Y %H:%M (%z)",
51
52   /*
53     short-weekday, day short-month year hour:minute:second timezonename
54     eg: Mon, 01 Mar 1999 13:13 (GMT)
55   */
56   @"%a, %d %b %Y %H:%M (%Z)",
57
58   /*
59     short-weekday, day short-month year hour:minute:second
60     eg: Mon, 01 Mar 1999 13:13:13
61   */
62   @"%a, %d %b %Y %H:%M:%S",
63
64   /*
65     day short-month year hour:minute:second timezoneoffset
66     eg: 01 Oct 1999 18:20:12 +0200
67   */
68   @"%d %b %Y %H:%M:%S %z",
69   
70   /*
71     day short-month year hour:minute:second timezonename
72     eg: 01 Oct 1999 18:20:12 EST
73   */
74   @"%d %b %Y %H:%M:%S %Z",
75   
76   /*
77     day short-month year hour:minute:second (timezoneoffset)
78     eg: 30 Sep 1999 21:00:05  (+0200)
79   */
80   @"%d %b %Y %H:%M:%S  (%z)",
81
82   /*
83     day short-month year hour:minute:second (timezonename)
84     eg: 30 Sep 1999 21:00:05  (MEST)
85   */
86   @"%d %b %Y %H:%M:%S  (%Z)",
87   /*
88     day short-month year hour:minute:second (timezonename)
89     eg: 30 Sep 1999 21:00:05  (MEST)
90   */
91   @"%d %b %Y %H:%M:%S  (%Z)",
92
93   /*
94     short-weekday, day short-month year hour:minute:second timezoneoffset
95     eg: Mon, 01 Mar 1999 13:13:13 +0000
96   */
97   @"%a %b %d %H:%M:%S %Y  (%Z)",
98
99   /*
100     eg: '16 Jun 2002 10:28 GMT'
101   */
102   @"%d %b %Y %H:%M %Z",
103
104   /*
105     eg: '16 Jun 2002 10:28 +0000'
106   */
107   @"%d %b %Y %H:%M %z",
108
109   /* terminate list */
110   nil
111 };
112
113 + (NSCalendarDate *)calendarDateWithRfc822DateString:(NSString *)_str {
114   // TODO: optimize MUCH more - calformat parsing is *slow*
115   NSCalendarDate *date       = nil;
116   NSString       *dateString = nil;
117   int i;  
118   
119   dateString = [_str stringByTrimmingSpaces];
120   if ([dateString length] == 0)
121     return nil;
122   
123   /* check various date formats */
124   
125   for (i = 0, date = nil; (date == nil) && (dateFormats[i] != nil); i++) {
126     date = [NSCalendarDate dateWithString:dateString
127                            calendarFormat:dateFormats[i]];
128   }
129   return [date y2kDate];
130 }
131
132 @end /* NSCalendarDate(RFC822Dates) */