Skip to content
Newer
Older
100644 72 lines (56 sloc) 2.89 KB
f40e389 @jenkins-telenav first commit
jenkins-telenav authored
1 /*ISO8601DateFormatter.h
2 *
3 *Created by Peter Hosey on 2009-04-11.
4 *Copyright 2009 Peter Hosey. All rights reserved.
5 */
6
7 #import <Foundation/Foundation.h>
8
9 /*This class converts dates to and from ISO 8601 strings. A good introduction to ISO 8601: <http://www.cl.cam.ac.uk/~mgk25/iso-time.html>
10 *
11 *Parsing can be done strictly, or not. When you parse loosely, leading whitespace is ignored, as is anything after the date.
12 *The loose parser will return an NSDate for this string: @" \t\r\n\f\t 2006-03-02!!!"
13 *Leading non-whitespace will not be ignored; the string will be rejected, and nil returned. See the README that came with this addition.
14 *
15 *The strict parser will only accept a string if the date is the entire string. The above string would be rejected immediately, solely on these grounds.
16 *Also, the loose parser provides some extensions that the strict parser doesn't.
17 *For example, the standard says for "-DDD" (an ordinal date in the implied year) that the logical representation (meaning, hierarchically) would be "--DDD", but because that extra hyphen is "superfluous", it was omitted.
18 *The loose parser will accept the extra hyphen; the strict parser will not.
19 *A full list of these extensions is in the README file.
20 */
21
22 /*The format to either expect or produce.
23 *Calendar format is YYYY-MM-DD.
24 *Ordinal format is YYYY-DDD, where DDD ranges from 1 to 366; for example, 2009-32 is 2009-02-01.
25 *Week format is YYYY-Www-D, where ww ranges from 1 to 53 (the 'W' is literal) and D ranges from 1 to 7; for example, 2009-W05-07.
26 */
27 enum {
28 ISO8601DateFormatCalendar,
29 ISO8601DateFormatOrdinal,
30 ISO8601DateFormatWeek,
31 };
32 typedef NSUInteger ISO8601DateFormat;
33
34 //The default separator for time values. Currently, this is ':'.
35 extern unichar ISO8601DefaultTimeSeparatorCharacter;
36
37 @interface ISO8601DateFormatter: NSFormatter
38 {
39 NSTimeZone *defaultTimeZone;
40 ISO8601DateFormat format;
41 unichar timeSeparator;
42 BOOL includeTime;
43 BOOL parsesStrictly;
44 }
45
46 @property(retain) NSTimeZone *defaultTimeZone;
47
48 #pragma mark Parsing
49
50 //As a formatter, this object converts strings to dates.
51
52 @property BOOL parsesStrictly;
53
54 - (NSDateComponents *) dateComponentsFromString:(NSString *)string;
55 - (NSDateComponents *) dateComponentsFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone;
56 - (NSDateComponents *) dateComponentsFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone range:(out NSRange *)outRange;
57
58 - (NSDate *) dateFromString:(NSString *)string;
59 - (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone;
60 - (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone range:(out NSRange *)outRange;
61
62 #pragma mark Unparsing
63
64 @property ISO8601DateFormat format;
65 @property BOOL includeTime;
66 @property unichar timeSeparator;
67
68 - (NSString *) stringFromDate:(NSDate *)date;
69 - (NSString *) stringFromDate:(NSDate *)date timeZone:(NSTimeZone *)timeZone;
70
71 @end
Something went wrong with that request. Please try again.