Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GCAge/GCDate: formatters, displaystrings

  • Loading branch information...
commit 37de2a2fd42b0222da7d6f0f1bc12218526c185c 1 parent 9b86142
@mikkelee authored
View
36 Gedcom/GCAge.m
@@ -61,7 +61,7 @@ - (NSString *)gedcomString
{
NSString *months = @"";
if ([[self ageComponents] month] >= 1) {
- months = [NSString stringWithFormat:@" %@", [[self ageComponents] month]];
+ months = [NSString stringWithFormat:@" %@m", [[self ageComponents] month]];
}
NSString *days = @"";
@@ -72,6 +72,21 @@ - (NSString *)gedcomString
return [NSString stringWithFormat:@"%dy%@%@", [[self ageComponents] year], months, days];
}
+- (NSString *)displayString
+{
+ NSString *months = @"";
+ if ([[self ageComponents] month] >= 1) {
+ months = [NSString stringWithFormat:@", %@ months", [[self ageComponents] month]];
+ }
+
+ NSString *days = @"";
+ if ([[self ageComponents] day] >= 1) {
+ days = [NSString stringWithFormat:@", %d days", [[self ageComponents] day]];
+ }
+
+ return [NSString stringWithFormat:@"%d years%@%@", [[self ageComponents] year], months, days];
+}
+
- (GCSimpleAge *)refAge
{
return self;
@@ -123,6 +138,11 @@ - (NSString *)gedcomString
return [NSString stringWithFormat:@"%@ %@", GCAgeQualifier_toString[[self qualifier]], [self age]];
}
+- (NSString *)displayString
+{
+ return [self gedcomString];
+}
+
- (GCSimpleAge *)refAge
{
return [[self age] refAge];
@@ -143,16 +163,21 @@ @interface GCAgeKeyword : GCAge
@implementation GCAgeKeyword
--(NSString *)description
+- (NSString *)description
{
return [NSString stringWithFormat:@"[GCAgeKeyword '%@']", [self keyword]];
}
--(NSString *)gedcomString
+- (NSString *)gedcomString
{
return [self keyword];
}
+- (NSString *)displayString
+{
+ return [[self keyword] capitalizedString];
+}
+
/*
CHILD = age < 8 years
INFANT = age < 1 year
@@ -205,6 +230,11 @@ -(NSString *)gedcomString
return [self string];
}
+- (NSString *)displayString
+{
+ return [self gedcomString];
+}
+
- (GCSimpleAge *)refAge
{
GCSimpleAge *m = [[GCSimpleAge alloc] init];
View
4 Gedcom/GCAgeFormatter.m
@@ -17,7 +17,7 @@ - (NSString *)editingStringForObjectValue:(id)anObject
return nil;
}
- return [self stringForObjectValue:anObject];
+ return [anObject gedcomString];
}
- (NSString *)stringForObjectValue:(id)anObject;
@@ -26,7 +26,7 @@ - (NSString *)stringForObjectValue:(id)anObject;
return nil;
}
- return [anObject gedcomString];
+ return [anObject displayString];
}
- (BOOL)getObjectValue:(id *)outVal forString:(NSString *)string errorDescription:(NSString **)error
View
73 Gedcom/GCDate.m
@@ -93,6 +93,11 @@ - (NSString *)gedcomString
return [NSString stringWithFormat:@"%@%@%04d", day, month, [[self dateComponents] year]];
}
+- (NSString *)displayString
+{
+ return [self gedcomString]; //TODO format according to user settings...
+}
+
- (NSDate *)minDate
{
return [[self calendar] dateFromComponents:[self dateComponents]];
@@ -124,16 +129,21 @@ @interface GCDatePhrase : GCDate
@implementation GCDatePhrase
--(NSString *)description
+- (NSString *)description
{
return [NSString stringWithFormat:@"[GCDatePhrase '%@']", [self phrase]];
}
--(NSString *)gedcomString
+- (NSString *)gedcomString
{
return [NSString stringWithFormat:@"(%@)", [self phrase]];
}
+- (NSString *)displayString
+{
+ return [self gedcomString];
+}
+
- (NSCalendar *)calendar
{
return nil;
@@ -203,16 +213,21 @@ @interface GCApproximateDate : GCAttributedDate
@implementation GCApproximateDate
--(NSString *)description
+- (NSString *)description
{
return [NSString stringWithFormat:@"[GCApproximateDate '%@' %@]", [self dateType], [self simpleDate]];
}
--(NSString *)gedcomString
+- (NSString *)gedcomString
{
return [NSString stringWithFormat:@"%@ %@", [self dateType], [[self simpleDate] gedcomString]];
}
+- (NSString *)displayString
+{
+ return [NSString stringWithFormat:@"~ %@", [[self simpleDate] displayString]];
+}
+
@synthesize dateType;
@end
@@ -227,16 +242,21 @@ @interface GCInterpretedDate : GCAttributedDate
@implementation GCInterpretedDate
--(NSString *)description
+- (NSString *)description
{
return [NSString stringWithFormat:@"[GCInterpretedDate %@ %@]", [self simpleDate], [self datePhrase]];
}
--(NSString *)gedcomString
+- (NSString *)gedcomString
{
return [NSString stringWithFormat:@"INT %@ (%@)]", [[self simpleDate] gedcomString], [[self datePhrase] gedcomString]];
}
+- (NSString *)displayString
+{
+ return [NSString stringWithFormat:@"\"%@\" (%@)]", [[self simpleDate] displayString], [[self datePhrase] displayString]];
+}
+
@synthesize datePhrase;
@end
@@ -283,24 +303,24 @@ - (NSCalendar *)calendar
}
}
--(GCSimpleDate *)dateA
+- (GCSimpleDate *)dateA
{
return _dateA;
}
--(void)setDateA:(GCSimpleDate *)dateA
+- (void)setDateA:(GCSimpleDate *)dateA
{
NSParameterAssert(dateA == nil || _dateB == nil || [[dateA calendar] isEqual:[_dateB calendar]]);
_dateA = dateA;
}
--(GCSimpleDate *)dateB
+- (GCSimpleDate *)dateB
{
return _dateB;
}
--(void)setDateB:(GCSimpleDate *)dateB
+- (void)setDateB:(GCSimpleDate *)dateB
{
NSParameterAssert(dateB == nil || _dateA == nil || [[_dateA calendar] isEqual:[dateB calendar]]);
@@ -345,7 +365,18 @@ - (NSString *)gedcomString
} else if ([self dateB] == nil) {
return [NSString stringWithFormat:@"FROM %@", [[self dateA] gedcomString]];
} else {
- return [NSString stringWithFormat:@"FROM %@ TO %@", [self dateA], [self dateB]];
+ return [NSString stringWithFormat:@"FROM %@ TO %@", [[self dateA] gedcomString], [[self dateB] gedcomString]];
+ }
+}
+
+- (NSString *)displayString
+{
+ if ([self dateA] == nil) {
+ return [NSString stringWithFormat:@"? – %@", [[self dateB] displayString]];
+ } else if ([self dateB] == nil) {
+ return [NSString stringWithFormat:@"%@ – ?", [[self dateA] displayString]];
+ } else {
+ return [NSString stringWithFormat:@"%@%@", [[self dateA] displayString], [[self dateB] displayString]];
}
}
@@ -381,6 +412,17 @@ - (NSString *)gedcomString
}
}
+- (NSString *)displayString
+{
+ if ([self dateA] == nil) {
+ return [NSString stringWithFormat:@"< %@", [[self dateB] displayString]];
+ } else if ([self dateB] == nil) {
+ return [NSString stringWithFormat:@"> %@", [[self dateA] displayString]];
+ } else {
+ return [NSString stringWithFormat:@"%@%@", [[self dateA] displayString], [[self dateB] displayString]];
+ }
+}
+
@end
#pragma mark GCInvalidDate
@@ -394,16 +436,21 @@ @interface GCInvalidDate : GCDate
@implementation GCInvalidDate
--(NSString *)description
+- (NSString *)description
{
return [NSString stringWithFormat:@"[GCInvalidDate '%@']", [self string]];
}
--(NSString *)gedcomString
+- (NSString *)gedcomString
{
return [self string];
}
+- (NSString *)displayString
+{
+ return [self gedcomString];
+}
+
- (GCSimpleDate *)refDate
{
return nil;
View
16 Gedcom/GCDateFormatter.m
@@ -13,7 +13,12 @@ @implementation GCDateFormatter
- (NSString *)editingStringForObjectValue:(id)date
{
- return [self stringForObjectValue:date];
+ if (![date isKindOfClass:[GCDate class]]) {
+ NSLog(@"date was wrong class: %@", [date className]);
+ return nil;
+ }
+
+ return [date gedcomString];
}
- (NSString *)stringForObjectValue:(id)date;
@@ -23,14 +28,9 @@ - (NSString *)stringForObjectValue:(id)date;
return nil;
}
- return [date gedcomString]; //TODO '<' instead of 'BEF' etc?
+ return [date displayString];
}
-/*
-- (NSAttributedString *)attributedStringForObjectValue:(id)date withDefaultAttributes:(NSDictionary *)attributes
-{
- return [[NSAttributedString alloc] initWithString:[self editingStringForObjectValue:date]]; //TODO
-}
-*/
+
- (BOOL)getObjectValue:(id *)outVal forString:(NSString *)string errorDescription:(NSString **)error
{
BOOL result = NO;
Please sign in to comment.
Something went wrong with that request. Please try again.