|
1
|
1 //
|
|
|
2 // fooTimeFormatter.m
|
|
|
3 // foo_abx
|
|
|
4 //
|
|
|
5 // Created by P on 06/09/2023.
|
|
|
6 //
|
|
|
7
|
|
|
8 #import "stdafx.h"
|
|
|
9 #import "fooTimeFormatter.h"
|
|
|
10
|
|
|
11 @implementation fooTimeFormatter
|
|
|
12
|
|
|
13 - (NSString *)stringForObjectValue:(id)obj {
|
|
|
14 double v = 0;
|
|
|
15 if ( [obj respondsToSelector: @selector(doubleValue)]) v = [obj doubleValue];
|
|
|
16 else if ( [obj respondsToSelector: @selector(longValue)]) v = [obj longValue];
|
|
|
17 else if ( [obj respondsToSelector: @selector(intValue)]) v = [obj intValue];
|
|
|
18
|
|
|
19 unsigned digits = 3;
|
|
|
20 if ( _digits ) digits = _digits.unsignedIntValue;
|
|
|
21 return [NSString stringWithUTF8String: pfc::format_time_ex(v, digits)];
|
|
|
22 }
|
|
|
23
|
|
|
24 - (NSString *)editingStringForObjectValue:(id)obj {
|
|
|
25 return [self stringForObjectValue: obj];
|
|
|
26 }
|
|
|
27 - (BOOL)getObjectValue:(out id _Nullable __autoreleasing *)obj forString:(NSString *)string errorDescription:(out NSString * _Nullable __autoreleasing *)error {
|
|
|
28 if ( string == nil ) return NO;
|
|
|
29 try {
|
|
|
30 double v = pfc::parse_timecode( string.UTF8String );
|
|
|
31 *obj = [NSNumber numberWithDouble: v];
|
|
|
32 return YES;
|
|
|
33 } catch(...) {
|
|
|
34 return NO;
|
|
|
35 }
|
|
|
36 }
|
|
|
37 @end
|