1 /*****************************************************************************
2 * VLCTime.h: VLC.framework VLCTime implementation
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 @implementation VLCTime
30 static VLCTime * nullTime = nil;
32 nullTime = [[VLCTime timeWithNumber:nil] retain];
36 + (VLCTime *)timeWithNumber:(NSNumber *)aNumber
38 return [[[VLCTime alloc] initWithNumber:aNumber] autorelease];
41 // TODO: Implement [VLCTime timeWithString]
42 //+ (VLCTime *)timeWithString:(NSString *)aString
44 // return [[[VLCTime alloc] initWithString:aString] autorelease];
47 - (id)initWithNumber:(NSNumber *)aNumber
49 if (self = [super init])
52 value = [[aNumber copy] retain];
59 // TODO: Implement [VLCTime initWithString]
60 //- (id)initWithString:(NSString *)aString
62 // // Sounds like a good idea but I really don't think there is any value added
63 // if (self = [super init])
76 - (NSNumber *)numberValue
78 return value ? [[value copy] autorelease] : nil;
81 - (NSString *)stringValue
85 long long duration = [value longLongValue] / 1000000;
86 return [NSString stringWithFormat:@"%02d:%02d:%02d",
87 (long) (duration / 3600),
88 (long)((duration / 60) % 60),
89 (long) (duration % 60)];
93 // Return a string that represents an undefined time.
98 - (NSComparisonResult)compare:(VLCTime *)aTime
100 if (!aTime && !value)
101 return NSOrderedSame;
103 return NSOrderedDescending;
105 return [value compare:aTime.numberValue];
108 - (NSString *)description
110 return self.stringValue;