-
Notifications
You must be signed in to change notification settings - Fork 0
/
SvnDateTransformer.m
88 lines (62 loc) · 1.96 KB
/
SvnDateTransformer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// SvnDateTransformer.m
// svnX
//
// Created by Dominique PERETTI on Mon Jul 12 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
#import "SvnDateTransformer.h"
#import "CommonUtils.h"
static NSDateFormatter* gDateFormatter = nil;
@implementation SvnDateTransformer
+ (Class)transformedValueClass
{
return [NSString class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
//----------------------------------------------------------------------------------------
+ (NSDateFormatter*) formatter
{
return gDateFormatter;
}
//----------------------------------------------------------------------------------------
- (id) init
{
self = [super init];
if (gDateFormatter == nil)
{
[[NSUserDefaultsController sharedUserDefaultsController]
addObserver: self
forKeyPath: @"values.dateformat"
options: NSKeyValueObservingOptionNew
context: NULL];
gDateFormatter = [[NSDateFormatter alloc]
initWithDateFormat: GetPreference(@"dateformat")
allowNaturalLanguage: NO];
}
return self;
}
//----------------------------------------------------------------------------------------
- (void) observeValueForKeyPath: (NSString*) keyPath
ofObject: (id) object
change: (NSDictionary*) change
context: (void*) context
{
#pragma unused(keyPath, object, change, context)
[gDateFormatter release];
gDateFormatter = [[NSDateFormatter alloc]
initWithDateFormat: GetPreference(@"dateformat")
allowNaturalLanguage: NO];
}
//----------------------------------------------------------------------------------------
- (id) transformedValue: (id) aString
{
NSString* dateString = [NSString stringWithFormat: @"%@ %@ +0000",
[aString substringToIndex: 10],
[aString substringWithRange: NSMakeRange(11, 8)]];
return [gDateFormatter stringFromDate: [NSDate dateWithString: dateString]];
}
@end