1 | /*NSCalendarDate+ISO8601Parsing.h |
---|
2 | * |
---|
3 | *Created by Peter Hosey on 2006-02-20. |
---|
4 | *Copyright 2006 Peter Hosey. All rights reserved. |
---|
5 | */ |
---|
6 | |
---|
7 | #import <Foundation/Foundation.h> |
---|
8 | |
---|
9 | /*This addition parses ISO 8601 dates. A good introduction: <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 NSCalendarDate 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 default separator for time values. Currently, this is ':'. |
---|
23 | extern unichar ISO8601ParserDefaultTimeSeparatorCharacter; |
---|
24 | |
---|
25 | @interface NSCalendarDate(ISO8601Parsing) |
---|
26 | |
---|
27 | //This method is the one that does all the work. All the others are convenience methods. |
---|
28 | + (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict getRange:(out NSRange *)outRange; |
---|
29 | + (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict; |
---|
30 | |
---|
31 | //Strictly: NO. |
---|
32 | + (NSCalendarDate *)calendarDateWithString:(NSString *)str timeSeparator:(unichar)timeSep getRange:(out NSRange *)outRange; |
---|
33 | + (NSCalendarDate *)calendarDateWithString:(NSString *)str timeSeparator:(unichar)timeSep; |
---|
34 | + (NSCalendarDate *)calendarDateWithString:(NSString *)str getRange:(out NSRange *)outRange; |
---|
35 | + (NSCalendarDate *)calendarDateWithString:(NSString *)str; |
---|
36 | |
---|
37 | @end |
---|