* MYTask: Added -commandLine, overhauled logging.
* MYDirectoryWatcher: Overhauled logging.
* MYErrorUtils: Disabled use of Security API (so it'll build without linking against Security.framework.)
2 // TimeIntervalFormatter.m
5 // Copyright 2008 Jens Alfke. All rights reserved.
8 #import "TimeIntervalFormatter.h"
11 @implementation TimeIntervalFormatter
28 - (void) setShowsMinutes: (BOOL)show {_showsMinutes = show;}
29 - (void) setShowsFractionalSeconds: (BOOL)show {_showsFractionalSeconds = show;}
31 + (NSString*) formatTimeInterval: (NSTimeInterval)interval
33 TimeIntervalFormatter *fmt = [[self alloc] init];
34 NSString *result = [fmt stringForObjectValue: [NSNumber numberWithDouble: interval]];
40 - (NSString*) stringForObjectValue: (id)object
42 if (![object isKindOfClass:[NSNumber class]])
44 NSTimeInterval time = [object doubleValue];
48 else if( time < 0.0 ) {
53 if( ! _showsFractionalSeconds )
55 int minutes = (int)floor(time / 60.0);
56 if( _showsMinutes || minutes>0 ) {
57 double seconds = time - 60.0*minutes;
58 return [NSString stringWithFormat: (_showsFractionalSeconds ?@"%@%d:%06.3lf" :@"%@%d:%02.0lf"),
59 sign,minutes,seconds];
61 return [NSString stringWithFormat: (_showsFractionalSeconds ?@"%@%.3lf" :@"%@%.0lf"),
67 - (BOOL)getObjectValue:(id *)anObject
68 forString:(NSString *)string
69 errorDescription:(NSString **)error
71 NSScanner *scanner = [NSScanner scannerWithString: string];
72 [scanner setCharactersToBeSkipped: [NSCharacterSet whitespaceCharacterSet]];
74 if( [scanner isAtEnd] ) {
77 if( ! [scanner scanDouble: &seconds] || seconds<0.0 ) goto error;
78 if( [scanner scanString: @":" intoString: NULL] ) {
79 double minutes = seconds;
80 if( ! [scanner scanDouble: &seconds] || seconds<0.0 ) goto error;
81 seconds += 60*minutes;
83 if( ! [scanner isAtEnd] ) goto error;
85 *anObject = [NSNumber numberWithDouble: seconds];
91 *error = @"Not a valid time interval";
96 - (BOOL)isPartialStringValid:(NSString **)partialStringPtr
97 proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
98 originalString:(NSString *)origString
99 originalSelectedRange:(NSRange)origSelRange
100 errorDescription:(NSString **)error
102 static NSCharacterSet *sIllegalChars;
103 if( ! sIllegalChars )
104 sIllegalChars = [[[NSCharacterSet characterSetWithCharactersInString: @"0123456789.:"]
105 invertedSet] retain];
106 return [*partialStringPtr rangeOfCharacterFromSet: sIllegalChars].length == 0;
114 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
116 Redistribution and use in source and binary forms, with or without modification, are permitted
117 provided that the following conditions are met:
119 * Redistributions of source code must retain the above copyright notice, this list of conditions
120 and the following disclaimer.
121 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
122 and the following disclaimer in the documentation and/or other materials provided with the
125 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
126 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
127 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
128 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
129 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
130 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
131 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
132 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.