Anonymous avatar Anonymous committed 739e52b

Adding the ability to provide a custom separator for parsing.

Comments (0)

Files changed (2)


 //This method is the one that does all the work. All the others are convenience methods.
 + (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict getRange:(out NSRange *)outRange;
 + (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict;
 //Strictly: NO.
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str timeSeparator:(unichar)timeSep getRange:(out NSRange *)outRange;
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str timeSeparator:(unichar)timeSep;
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str getRange:(out NSRange *)outRange;
 + (NSCalendarDate *)calendarDateWithString:(NSString *)str;
-+ (NSCalendarDate *)calendarDateWithString:(NSString *)str getRange:(out NSRange *)outRange;


 #import "NSCalendarDate+ISO8601Parsing.h"
 static unsigned read_segment(const unsigned char *str, const unsigned char **next, unsigned *out_num_digits) {
 	unsigned num_digits = 0U;
 	unsigned value = 0U;
  * //Day only of implied week
  *  -W-d
-+ (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict getRange:(out NSRange *)outRange {
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict timeSeparator:(unichar)timeSep getRange:(out NSRange *)outRange {
 	NSCalendarDate *now = [NSCalendarDate calendarDate];
 	} dateSpecification = monthAndDate;
+	if(strict) timeSep = DEFAULT_TIME_SEPARATOR;
 	BOOL isValidDate = ([str length] > 0U);
 	NSTimeZone *timeZone = nil;
 	NSCalendarDate *date = nil;
 			if(isdigit(*ch)) {
 				hour = read_segment_2digits(ch, &ch);
-				if(*ch == ':') {
+				if(*ch == timeSep) {
 					minute = read_double(ch, &ch);
 					second = modf(minute, &minute);
 					if(second > DBL_EPSILON)
 						second *= 60.0; //Convert fraction (e.g. .5) into seconds (e.g. 30).
-					else if(*ch == ':') {
+					else if(*ch == timeSep) {
 						second = read_double(ch, &ch);
 							if(negative) tz_hour = -tz_hour;
 							//Optional separator.
-							if(*ch == ':') ++ch;
+							if(*ch == timeSep) ++ch;
 							if(isdigit(*ch)) {
 								//Read minute offset.
 + (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict {
 	return [self calendarDateWithString:str strictly:strict getRange:NULL];
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str strictly:(BOOL)strict getRange:(out NSRange *)outRange {
+	return [self calendarDateWithString:str strictly:strict timeSeparator:DEFAULT_TIME_SEPARATOR getRange:NULL];
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str timeSeparator:(unichar)timeSep getRange:(out NSRange *)outRange {
+	return [self calendarDateWithString:str strictly:NO timeSeparator:timeSep getRange:outRange];
++ (NSCalendarDate *)calendarDateWithString:(NSString *)str timeSeparator:(unichar)timeSep {
+	return [self calendarDateWithString:str strictly:NO timeSeparator:timeSep getRange:NULL];
 + (NSCalendarDate *)calendarDateWithString:(NSString *)str getRange:(out NSRange *)outRange {
-	return [self calendarDateWithString:str strictly:NO getRange:outRange];
+	return [self calendarDateWithString:str strictly:NO timeSeparator:DEFAULT_TIME_SEPARATOR getRange:outRange];
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.