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); ...@@ -48,6 +48,7 @@ unsigned int CocoaKeyToVLC(unichar i_key);
- (NSString *)localizedString:(const char *)psz; - (NSString *)localizedString:(const char *)psz;
- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int)i_width; - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int)i_width;
- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative; - (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative;
- (NSString *)stringForTime:(long long int)time;
- (NSString *)OSXStringKeyToString:(NSString *)theString; - (NSString *)OSXStringKeyToString:(NSString *)theString;
- (NSString *)VLCKeyToString:(NSString *)theString; - (NSString *)VLCKeyToString:(NSString *)theString;
......
...@@ -117,12 +117,12 @@ static VLCStringUtility *_o_sharedInstance = nil; ...@@ -117,12 +117,12 @@ static VLCStringUtility *_o_sharedInstance = nil;
- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative - (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative
{ {
assert(p_input != nil); assert(p_input != nil);
vlc_value_t time; vlc_value_t time;
char psz_time[MSTRTIME_MAX_SIZE]; char psz_time[MSTRTIME_MAX_SIZE];
var_Get(p_input, "time", &time); var_Get(p_input, "time", &time);
mtime_t dur = input_item_GetDuration(input_GetItem(p_input)); mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
if (b_negative && dur > 0) { if (b_negative && dur > 0) {
mtime_t remaining = 0; mtime_t remaining = 0;
...@@ -133,6 +133,27 @@ static VLCStringUtility *_o_sharedInstance = nil; ...@@ -133,6 +133,27 @@ static VLCStringUtility *_o_sharedInstance = nil;
return [NSString stringWithUTF8String:secstotimestr(psz_time, (time.i_time / 1000000))]; 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 -
#pragma mark Key Shortcuts #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