summaryrefslogtreecommitdiffstats
path: root/Plugins/BuiltInFunctions/NaturalDateFormatter.m
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-04-14 21:45:08 -0400
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-04-14 21:45:08 -0400
commit17349a5e426dc7acf1216a3767a22f69974cbca0 (patch)
tree20029d02f07ab6257cccec36d34fb312f796e1d1 /Plugins/BuiltInFunctions/NaturalDateFormatter.m
downloadliaison-17349a5e426dc7acf1216a3767a22f69974cbca0.tar.gz
liaison-17349a5e426dc7acf1216a3767a22f69974cbca0.zip
Initial commit.
Diffstat (limited to 'Plugins/BuiltInFunctions/NaturalDateFormatter.m')
-rw-r--r--Plugins/BuiltInFunctions/NaturalDateFormatter.m58
1 files changed, 58 insertions, 0 deletions
diff --git a/Plugins/BuiltInFunctions/NaturalDateFormatter.m b/Plugins/BuiltInFunctions/NaturalDateFormatter.m
new file mode 100644
index 0000000..da83ee6
--- /dev/null
+++ b/Plugins/BuiltInFunctions/NaturalDateFormatter.m
@@ -0,0 +1,58 @@
+//
+// NaturalDateFormatter.m
+// BuiltInFunctions
+//
+// Created by Brian Cully on Sun Aug 31 2003.
+// Copyright (c) 2003 Brian Cully. All rights reserved.
+//
+
+#import "NaturalDateFormatter.h"
+
+#import "LiBuiltInFunctions.h"
+
+static NSString *
+myLocalizedString(NSString *aString)
+{
+ return NSLocalizedStringFromTableInBundle(aString, @"BuiltInFunctions",
+ [LiBuiltInFunctions bundle], @"");
+}
+
+@implementation NaturalDateFormatter
+- (id)initWithNaturalLanguage: (BOOL)flag
+{
+ NSString *format;
+
+ format = [[NSUserDefaults standardUserDefaults] objectForKey: NSShortDateFormatString];
+
+ self = [super initWithDateFormat: format allowNaturalLanguage: flag];
+ return self;
+}
+
+- (NSString *)stringForObjectValue: (id)anObject
+{
+ NSString *stringValue;
+
+ if ([anObject isKindOfClass: [NSDate class]]) {
+ NSCalendarDate *testDate;
+ int todayNum, myNum;
+
+ testDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:
+ [(NSDate *)anObject timeIntervalSinceReferenceDate]];
+ myNum = [[NSCalendarDate calendarDate] dayOfCommonEra];
+ todayNum = [testDate dayOfCommonEra];
+ if (myNum == todayNum)
+ stringValue = myLocalizedString(@"Today");
+ else if (todayNum == (myNum - 1))
+ stringValue = myLocalizedString(@"Yesterday");
+ else if (todayNum == (myNum + 1))
+ stringValue = myLocalizedString(@"Tomorrow");
+ else {
+ stringValue = [testDate descriptionWithCalendarFormat:
+ [self dateFormat]];
+ }
+ } else
+ stringValue = [super stringForObjectValue: anObject];
+
+ return stringValue;
+}
+@end