- (id)initWithLocale:(NSDictionary *)_locale {
if ((self = [super init])) {
self->locale = [_locale retain];
- if ([[self->locale objectForKey:@"NSLocaleCode"] isEqualToString:@"fr"]) {
+
+ if ([[self->locale objectForKey:@"NSLocaleCode"] isEqualToString:@"fr"])
[self setFrenchDateFormat];
- }
- else {
+ else
[self setISODateFormat];
- }
}
return self;
}
/* Private API */
- (NSString *)isoDateFormatForDate:(NSCalendarDate *)_date {
- return [NSString stringWithFormat:@"%04d-%02d-%02d",
- [_date yearOfCommonEra],
- [_date monthOfYear],
- [_date dayOfMonth]];
+ char buf[16];
+
+ if (_date == nil) return nil;
+ snprintf(buf, sizeof(buf),
+ "%04d-%02d-%02d",
+ [_date yearOfCommonEra], [_date monthOfYear], [_date dayOfMonth]);
+ return [NSString stringWithCString:buf];
}
- (NSString *)frenchDateFormatForDate:(NSCalendarDate *)_date {
- return [NSString stringWithFormat:@"%02d/%02d/%04d",
- [_date dayOfMonth],
- [_date monthOfYear],
- [_date yearOfCommonEra]];
+ char buf[16];
+
+ if (_date == nil) return nil;
+ snprintf(buf, sizeof(buf),
+ "%02d/%02d/%04d",
+ [_date dayOfMonth], [_date monthOfYear], [_date yearOfCommonEra]);
+ return [NSString stringWithCString:buf];
}
- (NSString *)fullWeekdayNameAndDetailsForDate:(NSCalendarDate *)_date {
NSMutableString *desc;
+ if (_date == nil) return nil;
+
desc = [NSMutableString stringWithCapacity:24];
[desc appendString:[self fullDayOfWeek:[_date dayOfWeek]]];
[desc appendString:@", "];