Commit f1ee099e authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/StringUtility: add helper to format time strings

parent 407acf38
......@@ -48,6 +48,7 @@ unsigned int CocoaKeyToVLC(unichar i_key);
- (NSString *)localizedString:(const char *)psz;
- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int)i_width;
- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative;
- (NSString *)stringForTime:(long long int)time;
- (NSString *)OSXStringKeyToString:(NSString *)theString;
- (NSString *)VLCKeyToString:(NSString *)theString;
......
......@@ -133,6 +133,27 @@ static VLCStringUtility *_o_sharedInstance = nil;
return [NSString stringWithUTF8String:secstotimestr(psz_time, (time.i_time / 1000000))];
}
- (NSString *)stringForTime:(long long int)time
{
if (time > 0) {
long long positiveDuration = llabs(time);
if (positiveDuration > 3600)
return [NSString stringWithFormat:@"%s%01ld:%02ld:%02ld",
time < 0 ? "-" : "",
(long) (positiveDuration / 3600),
(long)((positiveDuration / 60) % 60),
(long) (positiveDuration % 60)];
else
return [NSString stringWithFormat:@"%s%02ld:%02ld",
time < 0 ? "-" : "",
(long)((positiveDuration / 60) % 60),
(long) (positiveDuration % 60)];
} else {
// Return a string that represents an undefined time.
return @"--:--";
}
}
#pragma mark -
#pragma mark Key Shortcuts
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment