26 @global CPLocaleLanguageCode
27 @global CPLocaleCountryCode
29 CPDateFormatterNoStyle = 0;
30 CPDateFormatterShortStyle = 1;
31 CPDateFormatterMediumStyle = 2;
32 CPDateFormatterLongStyle = 3;
33 CPDateFormatterFullStyle = 4;
35 CPDateFormatterBehaviorDefault = 0;
36 CPDateFormatterBehavior10_0 = 1000;
37 CPDateFormatterBehavior10_4 = 1040;
39 var defaultDateFormatterBehavior = CPDateFormatterBehavior10_4,
40 relativeDateFormating,
53 BOOL _allowNaturalLanguage;
54 BOOL _doesRelativeDateFormatting;
57 CPDateFormatterBehavior _formatterBehavior;
58 CPDateFormatterStyle _dateStyle;
59 CPDateFormatterStyle _timeStyle;
75 relativeDateFormating = @{
76 @"fr" : [@"demain", 1440, @"apr" + String.fromCharCode(233) + @"s-demain", 2880, @"apr" + String.fromCharCode(233) + @"s-apr" + String.fromCharCode(233) + @"s-demain", 4320, @"hier", -1440, @"avant-hier", -2880, @"avant-avant-hier", -4320],
77 @"en" : [@"tomorrow", 1440, @"yesterday", -1440],
82 patternStringTokens = [@"QQQ", @"qqq", @"QQQQ", @"qqqq", @"MMM", @"MMMM", @"LLL", @"LLLL", @"E", @"EE", @"EEE", @"eee", @"eeee", @"eeeee", @"a", @"z", @"zz", @"zzz", @"zzzz", @"Z", @"ZZ", @"ZZZ", @"ZZZZ", @"ZZZZZ", @"v", @"vv", @"vvv", @"vvvv", @"V", @"VV", @"VVV", @"VVVV"];
91 + (
CPString)localizedStringFromDate:(
CPDate)date dateStyle:(CPDateFormatterStyle)dateStyle timeStyle:(CPDateFormatterStyle)timeStyle
95 [formatter setFormatterBehavior:CPDateFormatterBehavior10_4];
96 [formatter setDateStyle:dateStyle];
97 [formatter setTimeStyle:timeStyle];
99 return [formatter stringForObjectValue:date];
117 + (CPDateFormatterBehavior)defaultFormatterBehavior
119 return defaultDateFormatterBehavior;
125 + (void)setDefaultFormatterBehavior:(CPDateFormatterBehavior)behavior
127 defaultDateFormatterBehavior = behavior;
135 if (
self = [super init])
151 - (id)initWithDateFormat:(
CPString)format allowNaturalLanguage:(BOOL)flag
153 if (
self = [
self init])
155 _dateFormat = format;
156 _allowNaturalLanguage = flag;
166 var AMSymbol = [
CPString stringWithFormat:@"%s", @"AM"],
167 PMSymbol = [
CPString stringWithFormat:@"%s", @"PM"],
168 weekdaySymbols = [CPArray arrayWithObjects:@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday"],
169 shortWeekdaySymbols = [CPArray arrayWithObjects:@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat"],
170 veryShortWeekdaySymbols = [CPArray arrayWithObjects:@"S", @"M", @"T", @"W", @"T", @"F", @"S"],
171 standaloneWeekdaySymbols = [CPArray arrayWithObjects:@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday"],
172 shortStandaloneWeekdaySymbols = [CPArray arrayWithObjects:@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat"],
173 veryShortStandaloneWeekdaySymbols = [CPArray arrayWithObjects:@"S", @"M", @"T", @"W", @"T", @"F", @"S"],
174 monthSymbols = [CPArray arrayWithObjects:@"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September", @"October", @"November", @"December"],
175 shortMonthSymbols = [CPArray arrayWithObjects:@"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun", @"Jul", @"Aug", @"Sep", @"Oct", @"Nov", @"Dec"],
176 veryShortMonthSymbols = [CPArray arrayWithObjects:@"J", @"F", @"M", @"A", @"M", @"J", @"J", @"A", @"S", @"O", @"N", @"D"],
177 standaloneMonthSymbols = [CPArray arrayWithObjects:@"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September", @"October", @"November", @"December"],
178 shortStandaloneMonthSymbols = [CPArray arrayWithObjects:@"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun", @"Jul", @"Aug", @"Sep", @"Oct", @"Nov", @"Dec"],
179 veryShortStandaloneMonthSymbols = [CPArray arrayWithObjects:@"J", @"F", @"M", @"A", @"M", @"J", @"J", @"A", @"S", @"O", @"N", @"D"],
180 quarterSymbols = [CPArray arrayWithObjects:@"1st quarter", @"2nd quarter", @"3rd quarter", @"4th quarter"],
181 shortQuarterSymbols = [CPArray arrayWithObjects:@"Q1", @"Q2", @"Q3", @"Q4"],
182 standaloneQuarterSymbols = [CPArray arrayWithObjects:@"1st quarter", @"2nd quarter", @"3rd quarter", @"4th quarter"],
183 shortStandaloneQuarterSymbols = [CPArray arrayWithObjects:@"Q1", @"Q2", @"Q3", @"Q4"];
187 @"AMSymbol" : AMSymbol,
188 @"PMSymbol" : PMSymbol,
189 @"weekdaySymbols" : weekdaySymbols,
190 @"shortWeekdaySymbols" : shortWeekdaySymbols,
191 @"veryShortWeekdaySymbols" : veryShortWeekdaySymbols,
192 @"standaloneWeekdaySymbols" : standaloneWeekdaySymbols,
193 @"shortStandaloneWeekdaySymbols" : shortStandaloneWeekdaySymbols,
194 @"veryShortStandaloneWeekdaySymbols" : veryShortStandaloneWeekdaySymbols,
195 @"monthSymbols" : monthSymbols,
196 @"shortMonthSymbols" : shortMonthSymbols,
197 @"veryShortMonthSymbols" : veryShortMonthSymbols,
198 @"standaloneMonthSymbols" : standaloneMonthSymbols,
199 @"shortStandaloneMonthSymbols" : shortStandaloneMonthSymbols,
200 @"veryShortStandaloneMonthSymbols" : veryShortStandaloneMonthSymbols,
201 @"quarterSymbols" : quarterSymbols,
202 @"shortQuarterSymbols" : shortQuarterSymbols,
203 @"standaloneQuarterSymbols" : standaloneQuarterSymbols,
204 @"shortStandaloneQuarterSymbols" : shortStandaloneQuarterSymbols
212 _twoDigitStartDate = [[
CPDate alloc] initWithString:@"1950-01-01 00:00:00 +0000"];
218 #pragma mark Setter Getter
224 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"AMSymbol"];
229 - (void)setAMSymbol:(
CPString)aValue
231 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"AMSymbol"];
238 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"PMSymbol"];
243 - (void)setPMSymbol:(
CPString)aValue
245 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"PMSymbol"];
250 - (CPArray)weekdaySymbols
252 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"weekdaySymbols"];
257 - (void)setWeekdaySymbols:(CPArray)aValue
259 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"weekdaySymbols"];
264 - (CPArray)shortWeekdaySymbols
266 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"shortWeekdaySymbols"];
271 - (void)setShortWeekdaySymbols:(CPArray)aValue
273 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"shortWeekdaySymbols"];
278 - (CPArray)veryShortWeekdaySymbols
280 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"veryShortWeekdaySymbols"];
285 - (void)setVeryShortWeekdaySymbols:(CPArray)aValue
287 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"veryShortWeekdaySymbols"];
292 - (CPArray)standaloneWeekdaySymbols
294 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"standaloneWeekdaySymbols"];
299 - (void)setStandaloneWeekdaySymbols:(CPArray)aValue
301 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"standaloneWeekdaySymbols"];
306 - (CPArray)shortStandaloneWeekdaySymbols
308 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"shortStandaloneWeekdaySymbols"];
313 - (void)setShortStandaloneWeekdaySymbols:(CPArray)aValue
315 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"shortStandaloneWeekdaySymbols"];
320 - (CPArray)veryShortStandaloneWeekdaySymbols
322 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"veryShortStandaloneWeekdaySymbols"];
327 - (void)setVeryShortStandaloneWeekdaySymbols:(CPArray)aValue
329 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"veryShortStandaloneWeekdaySymbols"];
334 - (CPArray)monthSymbols
336 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"monthSymbols"];
341 - (void)setMonthSymbols:(CPArray)aValue
343 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"monthSymbols"];
348 - (CPArray)shortMonthSymbols
350 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"shortMonthSymbols"];
355 - (void)setShortMonthSymbols:(CPArray)aValue
357 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"shortMonthSymbols"];
362 - (CPArray)veryShortMonthSymbols
364 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"veryShortMonthSymbols"];
369 - (void)setVeryShortMonthSymbols:(CPArray)aValue
371 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"veryShortMonthSymbols"];
376 - (CPArray)standaloneMonthSymbols
378 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"standaloneMonthSymbols"];
383 - (void)setStandaloneMonthSymbols:(CPArray)aValue
385 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"standaloneMonthSymbols"];
390 - (CPArray)shortStandaloneMonthSymbols
392 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"shortStandaloneMonthSymbols"];
397 - (void)setShortStandaloneMonthSymbols:(CPArray)aValue
399 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"shortStandaloneMonthSymbols"];
404 - (CPArray)veryShortStandaloneMonthSymbols
406 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"veryShortStandaloneMonthSymbols"];
411 - (void)setVeryShortStandaloneMonthSymbols:(CPArray)aValue
413 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"veryShortStandaloneMonthSymbols"];
418 - (CPArray)quarterSymbols
420 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"quarterSymbols"];
425 - (void)setQuarterSymbols:(CPArray)aValue
427 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"quarterSymbols"];
432 - (CPArray)shortQuarterSymbols
434 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"shortQuarterSymbols"];
439 - (void)setShortQuarterSymbols:(CPArray)aValue
441 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"shortQuarterSymbols"];
446 - (CPArray)standaloneQuarterSymbols
448 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"standaloneQuarterSymbols"];
453 - (void)setStandaloneQuarterSymbols:(CPArray)aValue
455 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"standaloneQuarterSymbols"];
460 - (CPArray)shortStandaloneQuarterSymbols
462 return [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] valueForKey:@"shortStandaloneQuarterSymbols"];
467 - (void)setShortStandaloneQuarterSymbols:(CPArray)aValue
469 [[_symbols valueForKey:[_locale objectForKey:CPLocaleLanguageCode]] setValue:aValue forKey:@"shortStandaloneQuarterSymbols"];
474 #pragma mark StringFromDate methods
490 aDate = [aDate
copy];
491 [aDate _dateWithTimeZone:_timeZone];
494 return [
self _stringFromDate:aDate format:_dateFormat];
498 case CPDateFormatterNoStyle:
502 case CPDateFormatterShortStyle:
503 if ([
self _isAmericanFormat])
506 format =
@"dd/MM/yy";
510 case CPDateFormatterMediumStyle:
511 if ([
self _isAmericanFormat])
512 format =
@"MMM d, Y";
518 case CPDateFormatterLongStyle:
519 if ([
self _isAmericanFormat])
520 format =
@"MMMM d, Y";
522 format =
@"d MMMM Y";
526 case CPDateFormatterFullStyle:
527 if ([
self _isAmericanFormat])
528 format =
@"EEEE, MMMM d, Y";
530 format =
@"EEEE d MMMM Y";
539 if ([
self doesRelativeDateFormatting])
541 var language = [_locale objectForKey:CPLocaleLanguageCode],
542 relativeWords = [relativeDateFormating valueForKey:language];
544 for (var i = 1; i < [relativeWords count]; i = i + 2)
547 [date _dateWithTimeZone:_timeZone];
549 date.setHours(aDate.getHours());
550 date.setMinutes(aDate.getMinutes());
551 date.setSeconds(aDate.getSeconds());
553 date.setMinutes([relativeWords objectAtIndex:i]);
555 if (date.getDate() == aDate.getDate() && date.getMonth() && aDate.getMonth() && date.getFullYear() == aDate.getFullYear())
557 relativeWord = [relativeWords objectAtIndex:(i - 1)];
564 if ((relativeWord || format.length) && _timeStyle != CPDateFormatterNoStyle)
569 case CPDateFormatterNoStyle:
573 case CPDateFormatterShortStyle:
574 if ([
self _isEnglishFormat])
581 case CPDateFormatterMediumStyle:
582 if ([
self _isEnglishFormat])
583 format +=
@"h:mm:ss a";
589 case CPDateFormatterLongStyle:
590 if ([
self _isEnglishFormat])
591 format +=
@"h:mm:ss a z";
593 format +=
@"H:mm:ss z";
597 case CPDateFormatterFullStyle:
598 if ([
self _isEnglishFormat])
599 format +=
@"h:mm:ss a zzzz";
601 format +=
@"h:mm:ss zzzz";
609 result = [
self _stringFromDate:aDate format:format];
612 result = relativeWord + result;
622 - (
CPString)stringForObjectValue:(
id)anObject
624 if ([anObject isKindOfClass:[
CPDate class]])
625 return [
self stringFromDate:anObject];
635 - (
CPString)editingStringForObjectValue:(
id)anObject
637 return [
self stringForObjectValue:anObject];
647 var length = [aFormat length],
652 for (var i = 0; i < length; i++)
654 var character = [aFormat characterAtIndex:i];
658 if ([character isEqualToString:
@"'"])
661 result += currentToken;
666 currentToken += character;
672 if ([character isEqualToString:
@"'"])
677 result += currentToken;
684 if ([character isEqualToString:
@","] || [character isEqualToString:
@":"] || [character isEqualToString:
@"/"] || [character isEqualToString:
@"-"] || [character isEqualToString:
@" "])
686 result += [self _stringFromToken:currentToken date:aDate];
692 if ([currentToken length] && ![[currentToken characterAtIndex:0] isEqualToString:character])
694 result += [self _stringFromToken:currentToken date:aDate];
698 currentToken += character;
700 if (i == (length - 1))
701 result += [self _stringFromToken:currentToken date:aDate];
715 if (![aToken length])
718 var character = [aToken characterAtIndex:0],
719 length = [aToken length],
720 timeZone = _timeZone;
726 CPLog.warn(
@"Token not yet implemented " + aToken);
730 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getFullYear()] length];
732 return [
self _stringValueForValue:aDate.getFullYear() length:(length == 2)?length:currentLength];
735 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getFullYear()] length];
737 return [
self _stringValueForValue:aDate.getFullYear() length:(length == 2)?length:currentLength];
741 CPLog.warn(
@"Token not yet implemented " + aToken);
746 CPLog.warn(
@"Token not yet implemented " + aToken);
752 if (aDate.getMonth() < 6 && aDate.getMonth() > 2)
755 if (aDate.getMonth() > 5 && aDate.getMonth() < 9)
758 if (aDate.getMonth() >= 9)
762 return [
self _stringValueForValue:quarter length:MIN(2,length)];
765 return [[
self shortQuarterSymbols] objectAtIndex:(quarter - 1)];
768 return [[
self quarterSymbols] objectAtIndex:(quarter - 1)];
773 if (aDate.getMonth() < 6 && aDate.getMonth() > 2)
776 if (aDate.getMonth() > 5 && aDate.getMonth() < 9)
779 if (aDate.getMonth() >= 9)
783 return [
self _stringValueForValue:quarter length:MIN(2,length)];
786 return [[
self shortStandaloneQuarterSymbols] objectAtIndex:(quarter - 1)];
789 return [[
self standaloneQuarterSymbols] objectAtIndex:(quarter - 1)];
792 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getMonth() + 1] length];
795 return [
self _stringValueForValue:(aDate.getMonth() + 1) length:MAX(currentLength,length)];
798 return [[
self shortMonthSymbols] objectAtIndex:aDate.getMonth()];
801 return [[
self monthSymbols] objectAtIndex:aDate.getMonth()];
804 return [[
self veryShortMonthSymbols] objectAtIndex:aDate.getMonth()];
807 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getMonth() + 1] length];
810 return [
self _stringValueForValue:(aDate.getMonth() + 1) length:MAX(currentLength,length)];
813 return [[
self shortStandaloneMonthSymbols] objectAtIndex:aDate.getMonth()];
816 return [[
self standaloneMonthSymbols] objectAtIndex:aDate.getMonth()];
819 return [[
self veryShortStandaloneMonthSymbols] objectAtIndex:aDate.getMonth()];
823 CPLog.warn(
@"Depreacted - Token not yet implemented " + aToken);
827 var d = [aDate
copy];
830 d.setDate(d.getDate() + 4 - (d.getDay() || 7));
832 var yearStart =
new Date(d.getFullYear(), 0, 1),
833 weekOfYear = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
835 return [
self _stringValueForValue:(weekOfYear + 1) length:MAX(2, length)];
838 var firstDay =
new Date(aDate.getFullYear(), aDate.getMonth(), 1).getDay(),
839 weekOfMonth = Math.ceil((aDate.getDate() + firstDay) / 7);
841 return [
self _stringValueForValue:weekOfMonth length:1];
844 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getDate()] length];
846 return [
self _stringValueForValue:aDate.getDate() length:MAX(length, currentLength)];
849 var oneJan =
new Date(aDate.getFullYear(), 0, 1),
850 dayOfYear = Math.ceil((aDate - oneJan) / 86400000),
851 currentLength = [[
CPString stringWithFormat:@"%i", dayOfYear] length];
853 return [
self _stringValueForValue:dayOfYear length:MAX(currentLength, MIN(3, length))];
857 day = aDate.getDate();
859 if (day > 7 && day < 15)
862 if (day > 14 && day < 22)
865 if (day > 21 && day < 29)
871 return [
self _stringValueForValue:dayOfWeek length:1];
874 CPLog.warn(
@"Token not yet implemented " + aToken);
878 var day = aDate.getDay();
881 return [[
self shortWeekdaySymbols] objectAtIndex:day];
884 return [[
self weekdaySymbols] objectAtIndex:day];
887 return [[
self veryShortWeekdaySymbols] objectAtIndex:day];
890 var day = aDate.getDay();
893 return [
self _stringValueForValue:(day + 1) length:MIN(2, length)];
896 return [[
self shortWeekdaySymbols] objectAtIndex:day];
899 return [[
self weekdaySymbols] objectAtIndex:day];
902 return [[
self veryShortWeekdaySymbols] objectAtIndex:day];
905 var day = aDate.getDay();
908 return [
self _stringValueForValue:(day + 1) length:aDate.getDay().toString().length];
911 return [[
self shortStandaloneWeekdaySymbols] objectAtIndex:day];
914 return [[
self standaloneWeekdaySymbols] objectAtIndex:day];
917 return [[
self veryShortStandaloneWeekdaySymbols] objectAtIndex:day];
921 if (aDate.getHours() > 11)
922 return [
self PMSymbol];
924 return [
self AMSymbol];
927 var hours = aDate.getHours();
929 if ([
self _isAmericanFormat] || [
self _isEnglishFormat])
937 var currentLength = [[
CPString stringWithFormat:@"%i", hours] length];
939 return [
self _stringValueForValue:hours length:MAX(currentLength, MIN(2, length))];
942 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getHours()] length];
944 return [
self _stringValueForValue:aDate.getHours() length:MAX(currentLength, MIN(2, length))];
947 var hours = aDate.getHours();
952 var currentLength = [[
CPString stringWithFormat:@"%i", hours] length];
954 return [
self _stringValueForValue:hours length:MAX(currentLength, MIN(2, length))];
957 var hours = aDate.getHours();
959 if (aDate.getHours() == 0)
962 var currentLength = [[
CPString stringWithFormat:@"%i", hours] length];
964 return [
self _stringValueForValue:hours length:MAX(currentLength, MIN(2, length))];
967 CPLog.warn(
@"Token not yet implemented " + aToken);
971 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getMinutes()] length];
973 return [
self _stringValueForValue:aDate.getMinutes() length:MAX(currentLength, MIN(2, length))];
976 var currentLength = [[
CPString stringWithFormat:@"%i", aDate.getMinutes()] length];
978 return [
self _stringValueForValue:aDate.getSeconds() length:MIN(2, length)];
981 return [
self _stringValueForValue:aDate.getMilliseconds() length:length];
984 var value = aDate.getHours() * 60 * 60 * 1000 + aDate.getMinutes() * 60 * 1000 + aDate.getSeconds() * 1000 + aDate.getMilliseconds();
986 return [
self _stringValueForValue:value length:value.toString().length];
990 return [timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale];
992 return [timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale];
995 var seconds = [timeZone secondsFromGMT],
996 minutes = seconds / 60,
997 hours = minutes / 60,
999 diffMinutes = (hours - parseInt(hours)) * 100 * 60 / 100;
1003 result = diffMinutes.toString();
1005 while ([result length] < 2)
1006 result =
@"0" + result;
1008 result = ABS(parseInt(hours)) + result;
1010 while ([result length] < 4)
1011 result =
@"0" + result;
1014 result =
@"+" + result;
1016 result =
@"-" + result;
1020 else if (length == 4)
1022 result = diffMinutes.toString();
1024 while ([result length] < 2)
1025 result =
@"0" + result;
1027 result =
@":" + result;
1028 result = ABS(parseInt(hours)) + result;
1030 while ([result length] < 5)
1031 result =
@"0" + result;
1034 result =
@"+" + result;
1036 result =
@"-" + result;
1038 return @"GMT" + result;
1042 result = diffMinutes.toString();
1044 while ([result length] < 2)
1045 result =
@"0" + result;
1047 result =
@":" + result;
1048 result = ABS(parseInt(hours)) + result;
1050 while ([result length] < 5)
1051 result =
@"0" + result;
1054 result =
@"+" + result;
1056 result =
@"-" + result;
1063 return [timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale];
1064 else if (length == 4)
1065 return [timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale];
1072 return [timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale];
1074 else if (length == 4)
1076 CPLog.warn(
@"No pattern found for " + aToken);
1083 CPLog.warn(
@"No pattern found for " + aToken);
1092 #pragma mark datefromString
1106 if (_dateFormat != nil)
1107 return [
self _dateFromString:aString format:_dateFormat];
1111 case CPDateFormatterNoStyle:
1115 case CPDateFormatterShortStyle:
1116 if ([
self _isAmericanFormat])
1119 format =
@"dd/MM/yy";
1123 case CPDateFormatterMediumStyle:
1124 if ([
self _isAmericanFormat])
1125 format =
@"MMM d, Y";
1127 format =
@"d MMM Y";
1131 case CPDateFormatterLongStyle:
1132 if ([
self _isAmericanFormat])
1133 format =
@"MMMM d, Y";
1135 format =
@"d MMMM Y";
1139 case CPDateFormatterFullStyle:
1140 if ([
self _isAmericanFormat])
1141 format =
@"EEEE, MMMM d, Y";
1143 format =
@"EEEE d MMMM Y";
1153 case CPDateFormatterNoStyle:
1157 case CPDateFormatterShortStyle:
1158 if ([
self _isEnglishFormat])
1159 format +=
@" h:mm a";
1164 case CPDateFormatterMediumStyle:
1165 if ([
self _isEnglishFormat])
1166 format +=
@" h:mm:ss a";
1168 format +=
@" H:mm:ss"
1171 case CPDateFormatterLongStyle:
1172 if ([
self _isEnglishFormat])
1173 format +=
@" h:mm:ss a z";
1175 format +=
@" H:mm:ss z";
1178 case CPDateFormatterFullStyle:
1179 if ([
self _isEnglishFormat])
1180 format +=
@" h:mm:ss a zzzz";
1182 format +=
@" h:mm:ss zzzz";
1189 return [
self _dateFromString:aString format:format];
1198 - (BOOL)getObjectValue:(idRef)anObject forString:(
CPString)aString errorDescription:(CPStringRef)anError
1200 var value = [
self dateFromString:aString];
1201 @deref(anObject) = value;
1205 @deref(anError) =
@"The value \"" + aString + "\
" is invalid.";
1219 if (aString == nil || aFormat == nil)
1224 tokens = [CPArray array],
1225 dateComponents = [CPArray array],
1226 patternTokens = [CPArray array];
1228 for (var i = 0; i < [aFormat length]; i++)
1230 var character = [aFormat characterAtIndex:i];
1234 if ([character isEqualToString:
@"'"])
1240 if ([character isEqualToString:
@"'"])
1248 if ([character isEqualToString:
@","] || [character isEqualToString:
@":"] || [character isEqualToString:
@"/"] || [character isEqualToString:
@"-"] || [character isEqualToString:
@" "])
1250 [tokens addObject:currentToken];
1252 if ([patternStringTokens containsObject:currentToken])
1253 [patternTokens addObject:[tokens count] - 1];
1259 if ([currentToken length] && ![[currentToken characterAtIndex:0] isEqualToString:character])
1261 [tokens addObject:currentToken];
1263 if ([patternStringTokens containsObject:currentToken])
1264 [patternTokens addObject:[tokens count] - 1];
1269 currentToken += character;
1271 if (i == ([aFormat length] - 1))
1273 [tokens addObject:currentToken];
1275 if ([patternStringTokens containsObject:currentToken])
1276 [patternTokens addObject:[tokens count] - 1];
1284 var currentIndexSpecialPattern = 0;
1286 if ([patternTokens count] == 0)
1289 for (var i = 0; i < [aString length]; i++)
1291 var character = [aString characterAtIndex:i];
1295 if ([character isEqualToString:
@"'"])
1301 if ([character isEqualToString:
@"'"])
1310 if ([dateComponents count] == [patternTokens objectAtIndex:currentIndexSpecialPattern])
1312 var j = [
self _lastIndexMatchedString:aString token:[tokens objectAtIndex:[dateComponents count]] index:i];
1317 currentIndexSpecialPattern++;
1318 [dateComponents addObject:[aString substringWithRange:CPMakeRange(i, (j - i))]];
1324 if ([character isEqualToString:
@","] || [character isEqualToString:
@":"] || [character isEqualToString:
@"/"] || [character isEqualToString:
@"-"] || [character isEqualToString:
@" "])
1326 [dateComponents addObject:currentToken];
1331 currentToken += character;
1333 if (i == ([aString length] - 1))
1334 [dateComponents addObject:currentToken];
1338 if ([dateComponents count] != [tokens count])
1341 return [
self _dateFromTokens:tokens dateComponents:dateComponents];
1344 - (
CPDate)_dateFromTokens:(CPArray)tokens dateComponents:(CPArray)dateComponents
1346 var timeZoneseconds = [_timeZone secondsFromGMT],
1347 dateArray = [2000, 01, 01, 00, 00, 00, @"+0000"],
1354 for (var i = 0; i < [tokens count]; i++)
1356 var token = [tokens objectAtIndex:i],
1357 dateComponent = [dateComponents objectAtIndex:i],
1358 character = [token characterAtIndex:0],
1359 length = [token length];
1365 CPLog.warn(
@"Token not yet implemented " + token);
1369 var u = _twoDigitStartDate.getFullYear() % 10,
1370 d = parseInt(_twoDigitStartDate.getFullYear() / 10) % 10,
1371 c = parseInt(_twoDigitStartDate.getFullYear() / 100) % 10,
1372 m = parseInt(_twoDigitStartDate.getFullYear() / 1000) % 10;
1374 if (length == 2 && dateComponent.length == 2)
1376 if ((u + d * 10) >= parseInt(dateComponent))
1377 dateArray[0] = (c + 1) * 100 + m * 1000 + parseInt(dateComponent);
1379 dateArray[0] = c * 100 + m * 1000 + parseInt(dateComponent);
1383 dateArray[0] = parseInt(dateComponent);
1389 var u = _twoDigitStartDate.getFullYear() % 10,
1390 d = parseInt(_twoDigitStartDate.getFullYear() / 10) % 10,
1391 c = parseInt(_twoDigitStartDate.getFullYear() / 100) % 10,
1392 m = parseInt(_twoDigitStartDate.getFullYear() / 1000) % 10;
1394 if (length == 2 && dateComponent.length == 2)
1396 if ((u + d * 10) >= parseInt(dateComponent))
1397 dateArray[0] = (c + 1) * 100 + m * 1000 + parseInt(dateComponent);
1399 dateArray[0] = c * 100 + m * 1000 + parseInt(dateComponent);
1403 dateArray[0] = parseInt(dateComponent);
1410 CPLog.warn(
@"Token not yet implemented " + token);
1415 CPLog.warn(
@"Token not yet implemented " + token);
1422 month = (parseInt(dateComponent) - 1) * 3;
1426 if (![[
self shortQuarterSymbols] containsObject:dateComponent])
1429 month = [[
self shortQuarterSymbols] indexOfObject:dateComponent] * 3;
1434 if (![[
self quarterSymbols] containsObject:dateComponent])
1437 month = [[
self quarterSymbols] indexOfObject:dateComponent] * 3;
1443 dateArray[1] = month + 1;
1450 month = (parseInt(dateComponent) - 1) * 3;
1454 if (![[
self shortQuarterSymbols] containsObject:dateComponent])
1457 month = [[
self shortQuarterSymbols] indexOfObject:dateComponent] * 3;
1462 if (![[
self quarterSymbols] containsObject:dateComponent])
1465 month = [[
self quarterSymbols] indexOfObject:dateComponent] * 3;
1471 dateArray[1] = month + 1;
1478 month = parseInt(dateComponent)
1482 if (![[
self shortMonthSymbols] containsObject:dateComponent])
1485 month = [[
self shortMonthSymbols] indexOfObject:dateComponent] + 1;
1490 if (![[
self monthSymbols] containsObject:dateComponent])
1493 month = [[
self monthSymbols] indexOfObject:dateComponent] + 1;
1496 if (month > 11 || length >= 5)
1499 dateArray[1] = month;
1506 month = parseInt(dateComponent);
1510 if (![[
self shortStandaloneMonthSymbols] containsObject:dateComponent])
1513 month = [[
self shortStandaloneMonthSymbols] indexOfObject:dateComponent] + 1;
1518 if (![[
self standaloneMonthSymbols] containsObject:dateComponent])
1521 month = [[
self standaloneMonthSymbols] indexOfObject:dateComponent] + 1;
1524 if (month > 11 || length >= 5)
1527 dateArray[1] = month;
1532 CPLog.warn(
@"Depreacted - Token not yet implemented " + token);
1536 if (dateComponent > 52)
1539 weekOfYear = dateComponent;
1543 if (dateComponent > 52)
1546 weekOfMonth = dateComponent;
1550 dateArray[2] = parseInt(dateComponent);
1554 if (isNaN(parseInt(dateComponent)) || parseInt(dateComponent) > 345)
1557 dayOfYear = parseInt(dateComponent);
1561 if (isNaN(parseInt(dateComponent)) || parseInt(dateComponent) > 5 || parseInt(dateComponent) == 0)
1564 if (parseInt(dateComponent) == 1)
1567 if (parseInt(dateComponent) == 2)
1570 if (parseInt(dateComponent) == 3)
1573 if (parseInt(dateComponent) == 4)
1576 if (parseInt(dateComponent) == 5)
1582 CPLog.warn(
@"Token not yet implemented " + token);
1587 dayIndexInWeek = [[
self shortWeekdaySymbols] indexOfObject:dateComponent];
1590 dayIndexInWeek = [[
self weekdaySymbols] indexOfObject:dateComponent];
1592 if (dayIndexInWeek ==
CPNotFound || length >= 5)
1598 if (length <= 2 && isNaN(parseInt(dateComponent)))
1602 dayIndexInWeek = parseInt(dateComponent);
1605 dayIndexInWeek = [[
self shortWeekdaySymbols] indexOfObject:dateComponent];
1608 dayIndexInWeek = [[
self weekdaySymbols] indexOfObject:dateComponent];
1610 if (dayIndexInWeek ==
CPNotFound || length >= 5)
1616 if (length <= 2 && isNaN(parseInt(dateComponent)))
1620 dayIndexInWeek = dateComponent;
1623 dayIndexInWeek = [[
self shortStandaloneWeekdaySymbols] indexOfObject:dateComponent];
1626 dayIndexInWeek = [[
self standaloneWeekdaySymbols] indexOfObject:dateComponent];
1629 dayIndexInWeek = [[
self veryShortStandaloneWeekdaySymbols] indexOfObject:dateComponent];
1631 if (dayIndexInWeek ==
CPNotFound || length >= 5)
1637 if (![dateComponent isEqualToString:[
self PMSymbol]] && ![dateComponent isEqualToString:[
self AMSymbol]])
1640 if ([dateComponent isEqualToString:[
self PMSymbol]])
1646 if (parseInt(dateComponent) < 0 || parseInt(dateComponent) > 12)
1649 dateArray[3] = parseInt(dateComponent);
1653 if (parseInt(dateComponent) < 0 || parseInt(dateComponent) > 23)
1656 dateArray[3] = parseInt(dateComponent);
1660 if (parseInt(dateComponent) < 0 || parseInt(dateComponent) > 11)
1663 dateArray[3] = parseInt(dateComponent);
1667 if (parseInt(dateComponent) < 0 || parseInt(dateComponent) > 12)
1670 dateArray[3] = parseInt(dateComponent);
1674 CPLog.warn(
@"Token not yet implemented " + token);
1678 var minutes = parseInt(dateComponent);
1683 dateArray[4] = minutes;
1687 var seconds = parseInt(dateComponent);
1692 dateArray[5] = seconds;
1696 if (isNaN(parseInt(dateComponent)))
1702 if (isNaN(parseInt(dateComponent)))
1705 var millisecondsInDay = parseInt(dateComponent),
1706 tmpDate =
new Date();
1708 tmpDate.setHours(0);
1709 tmpDate.setMinutes(0);
1710 tmpDate.setSeconds(0);
1711 tmpDate.setMilliseconds(0);
1713 tmpDate.setMilliseconds(millisecondsInDay);
1715 dateArray[3] = tmpDate.getHours();
1716 dateArray[4] = tmpDate.getMinutes();
1717 dateArray[5] = tmpDate.getSeconds();
1722 timeZoneseconds = [
self _secondsFromTimeZoneString:dateComponent style:CPTimeZoneNameStyleShortDaylightSaving];
1724 timeZoneseconds = [
self _secondsFromTimeZoneString:dateComponent style:CPTimeZoneNameStyleDaylightSaving];
1726 if (!timeZoneseconds)
1727 timeZoneseconds = [
self _secondsFromTimeZoneDefaultFormatString:dateComponent];
1729 if (!timeZoneseconds)
1732 timeZoneseconds = timeZoneseconds + 60 * 60;
1737 timeZoneseconds = [
self _secondsFromTimeZoneDefaultFormatString:dateComponent];
1739 if (!timeZoneseconds)
1742 timeZoneseconds = timeZoneseconds + 60 * 60;
1748 timeZoneseconds = [
self _secondsFromTimeZoneString:dateComponent style:CPTimeZoneNameStyleShortGeneric];
1750 timeZoneseconds = [
self _secondsFromTimeZoneString:dateComponent style:CPTimeZoneNameStyleGeneric];
1752 if (!timeZoneseconds && length == 4)
1753 timeZoneseconds = [
self _secondsFromTimeZoneDefaultFormatString:dateComponent];
1755 if (!timeZoneseconds)
1758 timeZoneseconds = timeZoneseconds + 60 * 60;
1764 timeZoneseconds = [
self _secondsFromTimeZoneString:dateComponent style:CPTimeZoneNameStyleShortStandard];
1766 timeZoneseconds = [
self _secondsFromTimeZoneString:dateComponent style:CPTimeZoneNameStyleStandard];
1768 if (!timeZoneseconds)
1769 timeZoneseconds = [
self _secondsFromTimeZoneDefaultFormatString:dateComponent];
1771 if (!timeZoneseconds)
1774 timeZoneseconds = timeZoneseconds + 60 * 60;
1779 CPLog.warn(
@"No pattern found for " + token);
1787 var tmpDate =
new Date();
1788 tmpDate.setFullYear(dateArray[0]);
1789 tmpDate.setMonth(0);
1791 tmpDate.setDate(dayOfYear)
1793 dateArray[1] = tmpDate.getMonth() + 1;
1794 dateArray[2] = tmpDate.getDate();
1798 dateArray[2] = (weekOfMonth - 1) * 7 + 1;
1802 var tmpDate =
new Date();
1803 tmpDate.setFullYear(dateArray[0]);
1804 tmpDate.setMonth(0);
1807 while (tmpDate.getDay() != 0)
1808 tmpDate.setDate(tmpDate.getDate() + 1);
1810 tmpDate.setDate(tmpDate.getDate() + (weekOfYear - 1) * 7);
1812 dateArray[1] = tmpDate.getMonth() + 1;
1813 dateArray[2] = tmpDate.getDate() - 1;
1817 var tmpDate =
new Date();
1818 tmpDate.setMonth(dateArray[1] - 1);
1819 tmpDate.setFullYear(dateArray[0]);
1821 if (dateArray[2] <= 0 || dateArray[2] > [tmpDate _daysInMonth])
1828 if (isNaN(parseInt(dateArray[0])) || isNaN(parseInt(dateArray[1])) || isNaN(parseInt(dateArray[2])) || isNaN(parseInt(dateArray[3])) || isNaN(parseInt(dateArray[4])) || isNaN(parseInt(dateArray[5])) || isNaN(parseInt(dateArray[6])))
1831 var dateResult = [[
CPDate alloc] initWithString:[
CPString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d %s", dateArray[0], dateArray[1], dateArray[2], dateArray[3], dateArray[4], dateArray[5], dateArray[6]]];
1832 dateResult.setSeconds(dateResult.getSeconds() - timeZoneseconds + 60 * 60);
1841 - (
CPString)_stringValueForValue:(
id)aValue length:(
int)length
1843 var
string = [
CPString stringWithFormat:@"%i", aValue];
1845 if ([
string length] == length)
1848 if ([
string length] > length)
1849 return [string substringFromIndex:([string length] - length)];
1851 while ([
string length] < length)
1852 string = [
CPString stringWithFormat:@"0%s", string];
1859 - (BOOL)_isAmericanFormat
1861 return [[_locale objectForKey:CPLocaleCountryCode] isEqualToString:@"US"];
1866 - (BOOL)_isEnglishFormat
1868 return [[_locale objectForKey:CPLocaleLanguageCode] isEqualToString:@"en"];
1873 - (int)_secondsFromTimeZoneDefaultFormatString:(
CPString)aTimeZoneFormatString
1875 var format = /\w*([HPG-GMT])?([+-])(\d{1,2})([:])?(\d{2})\w*/,
1876 result = aTimeZoneFormatString.match(
new RegExp(format)),
1882 seconds = result[3] * 60 * 60 + result[5] * 60;
1884 if ([result[2] isEqualToString:
@"-"])
1892 - (int)_secondsFromTimeZoneString:(
CPString)aTimeZoneString style:(NSTimeZoneNameStyle)aStyle
1894 var timeZone = [
CPTimeZone _timeZoneFromString:aTimeZoneString style:aStyle locale:_locale];
1899 return [timeZone secondsFromGMT];
1908 - (int)_lastIndexMatchedString:(
CPString)aString token:(
CPString)aToken index:anIndex
1910 var character = [aToken characterAtIndex:0],
1911 length = [aToken length],
1913 format = /\w*([HPG-GMT])?([+-])(\d{1,2})([:])?(\d{2})\w*/,
1914 result = aString.match(
new RegExp(format));
1920 targetedArray = [
self shortQuarterSymbols];
1923 targetedArray = [
self quarterSymbols];
1929 targetedArray = [
self shortStandaloneQuarterSymbols];
1932 targetedArray = [
self standaloneQuarterSymbols];
1938 targetedArray = [
self shortMonthSymbols];
1941 targetedArray = [
self monthSymbols];
1944 targetedArray = [
self veryShortMonthSymbols];
1950 targetedArray = [
self shortStandaloneMonthSymbols];
1953 targetedArray = [
self standaloneMonthSymbols];
1956 targetedArray = [
self veryShortStandaloneMonthSymbols];
1962 targetedArray = [
self shortWeekdaySymbols];
1965 targetedArray = [
self weekdaySymbols];
1968 targetedArray = [
self veryShortWeekdaySymbols];
1974 targetedArray = [
self shortWeekdaySymbols];
1977 targetedArray = [
self weekdaySymbols];
1980 targetedArray = [
self veryShortWeekdaySymbols];
1986 targetedArray = [
self shortStandaloneWeekdaySymbols];
1989 targetedArray = [
self standaloneWeekdaySymbols];
1992 targetedArray = [
self veryShortStandaloneWeekdaySymbols];
1997 targetedArray = [[
self PMSymbol], [
self AMSymbol]];
2002 targetedArray = [
CPTimeZone _namesForStyle:CPTimeZoneNameStyleShortDaylightSaving locale:_locale];
2004 targetedArray = [
CPTimeZone _namesForStyle:CPTimeZoneNameStyleDaylightSaving locale:_locale];
2007 return anIndex + [result objectAtIndex:0].length;
2013 return anIndex + [result objectAtIndex:0].length;
2019 targetedArray = [
CPTimeZone _namesForStyle:CPTimeZoneNameStyleShortGeneric locale:_locale];
2020 else if (length == 4)
2021 targetedArray = [
CPTimeZone _namesForStyle:CPTimeZoneNameStyleGeneric locale:_locale];
2024 return anIndex + [result objectAtIndex:0].length;
2030 targetedArray = [
CPTimeZone _namesForStyle:CPTimeZoneNameStyleShortStandard locale:_locale];
2033 return anIndex + [result objectAtIndex:0].length;
2038 CPLog.warn(
@"No pattern found for " + aToken);
2042 for (var i = 0; i < [targetedArray count]; i++)
2044 var currentObject = [targetedArray objectAtIndex:i],
2045 range = [aString rangeOfString:currentObject];
2047 if (range.length == 0)
2050 character = [aString characterAtIndex:(anIndex + range.length)];
2052 if ([character isEqualToString:
@"'"] || [character isEqualToString:
@","] || [character isEqualToString:
@":"] || [character isEqualToString:
@"/"] || [character isEqualToString:
@"-"] || [character isEqualToString:
@" "] || [character isEqualToString:
@""])
2053 return anIndex + range.length;
2061 var CPDateFormatterDateStyleKey =
@"CPDateFormatterDateStyle",
2062 CPDateFormatterTimeStyleKey =
@"CPDateFormatterTimeStyleKey",
2063 CPDateFormatterFormatterBehaviorKey =
@"CPDateFormatterFormatterBehaviorKey",
2064 CPDateFormatterDoseRelativeDateFormattingKey =
@"CPDateFormatterDoseRelativeDateFormattingKey",
2065 CPDateFormatterDateFormatKey =
@"CPDateFormatterDateFormatKey",
2066 CPDateFormatterAllowNaturalLanguageKey =
@"CPDateFormatterAllowNaturalLanguageKey",
2067 CPDateFormatterLocaleKey =
@"CPDateFormatterLocaleKey";
2069 @implementation CPDateFormatter (CPCoding)
2071 - (id)initWithCoder:(
CPCoder)aCoder
2073 self = [
super initWithCoder:aCoder];
2077 _allowNaturalLanguage = [aCoder decodeBoolForKey:CPDateFormatterAllowNaturalLanguageKey];
2078 _dateFormat = [aCoder decodeObjectForKey:CPDateFormatterDateFormatKey];
2079 _dateStyle = [aCoder decodeIntForKey:CPDateFormatterDateStyleKey];
2080 _doesRelativeDateFormatting = [aCoder decodeBoolForKey:CPDateFormatterDoseRelativeDateFormattingKey];
2081 _formatterBehavior = [aCoder decodeIntForKey:CPDateFormatterFormatterBehaviorKey];
2082 _locale = [aCoder decodeObjectForKey:CPDateFormatterLocaleKey];
2083 _timeStyle = [aCoder decodeIntForKey:CPDateFormatterTimeStyleKey];
2091 - (void)encodeWithCoder:(
CPCoder)aCoder
2093 [
super encodeWithCoder:aCoder];
2095 [aCoder encodeBool:_allowNaturalLanguage forKey:CPDateFormatterAllowNaturalLanguageKey];
2096 [aCoder encodeInt:_dateStyle forKey:CPDateFormatterDateStyleKey];
2097 [aCoder encodeObject:_dateFormat forKey:CPDateFormatterDateFormatKey];
2098 [aCoder encodeBool:_doesRelativeDateFormatting forKey:CPDateFormatterDoseRelativeDateFormattingKey];
2099 [aCoder encodeInt:_formatterBehavior forKey:CPDateFormatterFormatterBehaviorKey];
2100 [aCoder encodeInt:_locale forKey:CPDateFormatterLocaleKey];
2101 [aCoder encodeInt:_timeStyle forKey:CPDateFormatterTimeStyleKey];
2107 @implementation CPDate (CPTimeZone)
2111 - (void)_dateWithTimeZone:(
CPTimeZone)aTimeZone
2113 self.setSeconds(
self.getSeconds() - [aTimeZone secondsFromGMTForDate:
self]);
2114 self.setSeconds(
self.getSeconds() + [aTimeZone secondsFromGMT]);
2119 @implementation CPDateFormatter (CPSynthesizedAccessors)
2124 - (BOOL)allowNaturalLanguage
2126 return _allowNaturalLanguage;
2132 - (BOOL)doesRelativeDateFormatting
2134 return _doesRelativeDateFormatting;
2140 - (void)setDoesRelativeDateFormatting:(BOOL)aValue
2142 _doesRelativeDateFormatting = aValue;
2150 return _defaultDate;
2156 - (void)setDefaultDate:(
CPDate)aValue
2158 _defaultDate = aValue;
2164 - (
CPDate)twoDigitStartDate
2166 return _twoDigitStartDate;
2172 - (void)setTwoDigitStartDate:(
CPDate)aValue
2174 _twoDigitStartDate = aValue;
2180 - (CPDateFormatterBehavior)formatterBehavior
2182 return _formatterBehavior;
2188 - (void)setFormatterBehavior:(CPDateFormatterBehavior)aValue
2190 _formatterBehavior = aValue;
2196 - (CPDateFormatterStyle)dateStyle
2204 - (void)setDateStyle:(CPDateFormatterStyle)aValue
2206 _dateStyle = aValue;
2212 - (CPDateFormatterStyle)timeStyle
2220 - (void)setTimeStyle:(CPDateFormatterStyle)aValue
2222 _timeStyle = aValue;
2252 - (void)setAMSymbol:(
CPString)aValue
2268 - (void)setDateFormat:(
CPString)aValue
2270 _dateFormat = aValue;
2284 - (void)setPMSymbol:(
CPString)aValue