Permalink
Browse files

Added +registeredTransformer, to conveniently return an SORelativeDat…

…eTransformer instance globally cached by NSValueTransformer.
  • Loading branch information...
1 parent 1f58aba commit 18a7833a0f36fbc710d2172b50ff17c7da0141cb @billgarrison committed Jun 22, 2013
View
25 SORelativeDateTransformer/SORelativeDateTransformer.h
@@ -1,15 +1,14 @@
/*
Created by William Garrison on 12/6/10.
- Copyright 2010-2012 Standard Orbit Software, LLC. All rights reserved.
+ Copyright Standard Orbit Software, LLC. All rights reserved.
Derived in part from digdog's MIT-licensed NSDate-RelativeDate category method <https://github.com/digdog/NSDate-RelativeDate>
- This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License <http://creativecommons.org/licenses/by-sa/3.0/">
- Use it, hack it, but give me some love.
+ This code is MIT-licensed. Use it, hack it, but give me some love.
*/
/**
-SORelativeDateTransformer is a value transformer that generates a human-readable phrase expressing the relative difference between a given date and the current date.
+ SORelativeDateTransformer is a value transformer that generates a human-readable phrase expressing the relative difference between a given date and the current date.
For example, when the current date-time is 2010-12-05 11:30, then
...the date 2010-12-04 11:00 is transformed to "30 minutes ago"
@@ -20,7 +19,7 @@ SORelativeDateTransformer is a value transformer that generates a human-readable
Localization:
The accompanying SORelativeDateTransformer.strings file provides English localizations for the date component names and their plural forms.
- The strings file also contains a localized string format template to use for relative past and future dates.
+ The strings file also contains a localized string format template to use for relative past and future dates.
For past dates, the template for the English phrase is "%d %@ ago". For future dates, the template is "in %d %@".
Copy and modify the SORelativeDateTransformer.strings file with your own localizations.
@@ -36,10 +35,18 @@ SORelativeDateTransformer is a value transformer that generates a human-readable
}
/**
-\brief Transform an NSDate into a phrase expressing the relative difference between that date and now.
-\param value An NSDate to be compared to the current date.
-\return An NSString with the generated and localized phrase.
-*/
+ @brief The cached instance of the value transformer registered with NSValueTransformer's global cache.
+ @return An instance of the value transformer registered in the NSValueTransfomer global cache.
+
+ NSValueTransformer can provide a cached instance of a given transformer by name. This method is a simple convenience cover over -[NSValueTransformer valueTransformerWithName:].
+ */
++ (NSValueTransformer *) registeredTransformer;
+
+/**
+ @brief Transform an NSDate into a phrase expressing the relative difference between that date and now.
+ @param value An NSDate to be compared to the current date.
+ @return An NSString with the generated and localized phrase.
+ */
- (id) transformedValue:(id)value;
@end
View
17 SORelativeDateTransformer/SORelativeDateTransformer.m
@@ -1,20 +1,20 @@
/*
Created by William Garrison on 12/6/10.
- Copyright 2010-2012 Standard Orbit Software, LLC. All rights reserved.
+ Copyright Standard Orbit Software, LLC. All rights reserved.
Derived in part from digdog's MIT-licensed NSDate-RelativeDate category method <https://github.com/digdog/NSDate-RelativeDate>
- This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License <http://creativecommons.org/licenses/by-sa/3.0/">
- Use it, hack it, but give me some love.
+ This code is MIT-licensed. Use it, hack it, but give me some love.
*/
#import "SORelativeDateTransformer.h"
-#ifndef __has_feature
-#define __has_feature(x) 0
-#endif
-
@implementation SORelativeDateTransformer
++ (NSValueTransformer *) registeredTransformer
+{
+ return [NSValueTransformer valueTransformerForName:NSStringFromClass(self)];
+}
+
+ (NSBundle *)bundle {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
@@ -55,8 +55,7 @@ - (void) dealloc
}
#endif
-#pragma mark -
-#pragma mark NSValueTransformer Overrides
+#pragma mark - NSValueTransformer Overrides
+ (Class) transformedValueClass
{

0 comments on commit 18a7833

Please sign in to comment.