]> err.no Git - sope/blob - sope-mime/NGMime/NSCalendarDate+RFC822.m
fixed to qualifier handling
[sope] / sope-mime / NGMime / NSCalendarDate+RFC822.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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   SOPE 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 SOPE; 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
22 #include "common.h"
23
24 @implementation NSCalendarDate(RFC822Dates)
25
26 static NSString *dateFormats[] = {
27   /*
28     short-weekday, day short-month year hour:minute:second timezoneoffset
29     eg: Mon, 01 Mar 1999 13:13:13 +0000
30   */
31   @"%a, %d %b %Y %H:%M:%S %z",
32
33   /*
34     short-weekday, day short-month year hour:minute:second timezonename
35     eg: Mon, 01 Mar 1999 13:13:13 GMT
36   */
37   @"%a, %d %b %Y %H:%M:%S %Z",
38
39   /*
40     short-weekday, day short-month year hour:minute:second timezonename
41     eg: Mon, 01 Mar 1999 13:13 +0000
42   */
43   @"%a, %d %b %Y %H:%M %z",
44
45   /*
46     short-weekday, day short-month year hour:minute:second timezonename
47     eg: Mon, 01 Mar 1999 13:13 (+0000)
48   */
49   @"%a, %d %b %Y %H:%M (%z)",
50
51   /*
52     short-weekday, day short-month year hour:minute:second timezonename
53     eg: Mon, 01 Mar 1999 13:13 (GMT)
54   */
55   @"%a, %d %b %Y %H:%M (%Z)",
56
57   /*
58     short-weekday, day short-month year hour:minute:second
59     eg: Mon, 01 Mar 1999 13:13:13
60   */
61   @"%a, %d %b %Y %H:%M:%S",
62
63   /*
64     day short-month year hour:minute:second timezoneoffset
65     eg: 01 Oct 1999 18:20:12 +0200
66   */
67   @"%d %b %Y %H:%M:%S %z",
68   
69   /*
70     day short-month year hour:minute:second timezonename
71     eg: 01 Oct 1999 18:20:12 EST
72   */
73   @"%d %b %Y %H:%M:%S %Z",
74   
75   /*
76     day short-month year hour:minute:second (timezoneoffset)
77     eg: 30 Sep 1999 21:00:05  (+0200)
78   */
79   @"%d %b %Y %H:%M:%S  (%z)",
80
81   /*
82     day short-month year hour:minute:second (timezonename)
83     eg: 30 Sep 1999 21:00:05  (MEST)
84   */
85   @"%d %b %Y %H:%M:%S  (%Z)",
86   /*
87     day short-month year hour:minute:second (timezonename)
88     eg: 30 Sep 1999 21:00:05  (MEST)
89   */
90   @"%d %b %Y %H:%M:%S  (%Z)",
91
92   /*
93     short-weekday, day short-month year hour:minute:second timezoneoffset
94     eg: Mon, 01 Mar 1999 13:13:13 +0000
95   */
96   @"%a %b %d %H:%M:%S %Y  (%Z)",
97
98   /*
99     eg: '16 Jun 2002 10:28 GMT'
100   */
101   @"%d %b %Y %H:%M %Z",
102
103   /*
104     eg: '16 Jun 2002 10:28 +0000'
105   */
106   @"%d %b %Y %H:%M %z",
107
108   /* terminate list */
109   nil
110 };
111
112 + (NSCalendarDate *)calendarDateWithRfc822DateString:(NSString *)_str {
113   // TODO: optimize MUCH more - calformat parsing is *slow*
114   NSCalendarDate *date       = nil;
115   NSString       *dateString = nil;
116   int i;  
117   
118   dateString = [_str stringByTrimmingSpaces];
119   if ([dateString length] == 0)
120     return nil;
121   
122   /* check various date formats */
123   
124   for (i = 0, date = nil; (date == nil) && (dateFormats[i] != nil); i++) {
125     date = [NSCalendarDate dateWithString:dateString
126                            calendarFormat:dateFormats[i]];
127   }
128   return [date y2kDate];
129 }
130
131 @end /* NSCalendarDate(RFC822Dates) */