[vlc-commits] macosx/StringUtility: add helper to format time strings

Felix Paul Kühne git at videolan.org
Sat Apr 26 19:01:57 CEST 2014


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Apr 26 18:40:11 2014 +0200| [f1ee099e712820bdde221ed8745db40d9ea815ac] | committer: Felix Paul Kühne

macosx/StringUtility: add helper to format time strings

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f1ee099e712820bdde221ed8745db40d9ea815ac
---

 modules/gui/macosx/StringUtility.h |    1 +
 modules/gui/macosx/StringUtility.m |   27 ++++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/modules/gui/macosx/StringUtility.h b/modules/gui/macosx/StringUtility.h
index 1e34d4a..f941ffb 100644
--- a/modules/gui/macosx/StringUtility.h
+++ b/modules/gui/macosx/StringUtility.h
@@ -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;
diff --git a/modules/gui/macosx/StringUtility.m b/modules/gui/macosx/StringUtility.m
index 301b3fa..529dee1 100644
--- a/modules/gui/macosx/StringUtility.m
+++ b/modules/gui/macosx/StringUtility.m
@@ -117,12 +117,12 @@ static VLCStringUtility *_o_sharedInstance = nil;
 - (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative
 {
     assert(p_input != nil);
-    
+
     vlc_value_t time;
     char psz_time[MSTRTIME_MAX_SIZE];
-    
+
     var_Get(p_input, "time", &time);
-    
+
     mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
     if (b_negative && dur > 0) {
         mtime_t remaining = 0;
@@ -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
 



More information about the vlc-commits mailing list