Explorar el Código

VLCTime: Refactor verboseStringValue

Mike JS. Choi hace 7 años
padre
commit
45eff029ac
Se han modificado 3 ficheros con 11 adiciones y 16 borrados
  1. 1 1
      Headers/Public/VLCTime.h
  2. 1 0
      NEWS
  3. 9 15
      Sources/VLCTime.m

+ 1 - 1
Headers/Public/VLCTime.h

@@ -79,7 +79,7 @@
  */
 @property (readonly) NSString * stringValue;
 /**
- * the current time value as verbose string value localized for the current environment
+ * the current time value as verbose localized string by spelling out the units of time, but not the quantities
  * \return the NSString object
  */
 @property (readonly) NSString * verboseStringValue;

+ 1 - 0
NEWS

@@ -5,6 +5,7 @@ Version 3.1.0:
 - Expose yaw, pitch, roll and fov for viewpoint
 - Include protobuf, sout, output_http and stream_out modules for Chromecast
 - Rename buildMobileVLCKit to compileAndBuildVLCKit
+- Use NSDateComponents API for VLCTime.verboseStringValue
 
 Version 3.0.2:
 --------------

+ 9 - 15
Sources/VLCTime.m

@@ -114,21 +114,15 @@
     long mins = (long)((positiveDuration / 60) % 60);
     long seconds = (long)(positiveDuration % 60);
     BOOL remaining = duration < 0;
-    NSString *format;
-    if (hours > 0) {
-        format = remaining ? NSLocalizedString(@"%ld hours %ld minutes remaining", nil) : NSLocalizedString(@"%ld hours %ld minutes", nil);
-        return [NSString stringWithFormat:format, hours, mins, remaining];
-    }
-    if (mins > 5) {
-        format = remaining ? NSLocalizedString(@"%ld minutes remaining", nil) : NSLocalizedString(@"%ld minutes", nil);
-        return [NSString stringWithFormat:format, mins, remaining];
-    }
-    if (mins > 0) {
-        format = remaining ? NSLocalizedString(@"%ld minutes %ld seconds remaining", nil) : NSLocalizedString(@"%ld minutes %ld seconds", nil);
-        return [NSString stringWithFormat:format, mins, seconds, remaining];
-    }
-    format = remaining ? NSLocalizedString(@"%ld seconds remaining", nil) : NSLocalizedString(@"%ld seconds", nil);
-    return [NSString stringWithFormat:format, seconds, remaining];
+   
+    NSDateComponents *components = [[NSDateComponents alloc] init];
+    [components setHour:hours];
+    [components setMinute:mins];
+    [components setSecond:seconds];
+
+    NSString *verboseString = [NSDateComponentsFormatter localizedStringFromDateComponents:components unitsStyle:NSDateComponentsFormatterUnitsStyleFull];
+    verboseString = remaining ? [NSString stringWithFormat:@"%@ remaining", verboseString] : verboseString;
+    return [verboseString stringByReplacingOccurrencesOfString:@"," withString:@""];
 }
 
 - (NSString *)minuteStringValue