Added Time formatting :)
authorJoseph Spiros <joseph.spiros@ithinksw.com>
Wed, 1 Oct 2003 12:20:31 +0000 (12:20 +0000)
committerJoseph Spiros <joseph.spiros@ithinksw.com>
Wed, 1 Oct 2003 12:20:31 +0000 (12:20 +0000)
iTunesRemote.m

index 5c63183..f197b97 100755 (executable)
                         sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
                         
     final = duration - current;
-    if (final > 60) {
-        if (final > 3600) {
-            if (final > 216000) {
-                finalString = [NSString stringWithFormat:@"%i:%i:%i:%i",(final / 216000),((final % 216000) / 3600),(((final / 216000) % 3600) / 60),(((final / 216000) % 3600) % 60)];
-            } else {
-                finalString = [NSString stringWithFormat:@"%i:%i:%i",(final / 3600),((final % 3600) / 60),((final % 3600) % 60)];
-            }
-        } else {
-            finalString = [NSString stringWithFormat:@"%i:%i",(final / 60),(final % 60)];
-        }
-    } else {
-        finalString = [[NSNumber numberWithLong:final] stringValue];
-    }
+    finalString = [self formatTimeInSeconds:final];
     
     ITDebugLog(@"Getting current song remaining time done.");
     
     final = [[ITAppleEventCenter sharedCenter]
                         sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
                         
-    if (final > 60) {
-        if (final > 3600) {
-            if (final > 216000) {
-                finalString = [NSString stringWithFormat:@"%i:%i:%i:%i",(final / 216000),((final % 216000) / 3600),(((final / 216000) % 3600) / 60),(((final / 216000) % 3600) % 60)];
-            } else {
-                finalString = [NSString stringWithFormat:@"%i:%i:%i",(final / 3600),((final % 3600) / 60),((final % 3600) % 60)];
-            }
-        } else {
-            finalString = [NSString stringWithFormat:@"%i:%i",(final / 60),(final % 60)];
-        }
-    } else {
-        finalString = [[NSNumber numberWithLong:final] stringValue];
-    }
+    finalString = [self formatTimeInSeconds:final];
     ITDebugLog(@"Getting current song elapsed time done.");
     return finalString;
 }
     return number;
 }
 
+- (NSString*)formatTimeInSeconds:(long)seconds {
+    long final = seconds;
+    NSString *finalString;
+    if (final > 60) {
+        if (final > 3600) {
+            finalString = [NSString stringWithFormat:@"%i:%@:%@",(final / 3600),[self zeroSixty:(int)((final % 3600) / 60)],[self zeroSixty:(int)((final % 3600) % 60)]];
+        } else {
+            finalString = [NSString stringWithFormat:@"%i:%@",(final / 60),[self zeroSixty:(int)(final % 60)]];
+        }
+    } else {
+        finalString = [NSString stringWithFormat:@"0:%@",[self zeroSixty:(int)final]];
+    }
+    return finalString;
+}
+- (NSString*)zeroSixty:(int)seconds {
+    if ( (seconds < 10) && (seconds > 0) ) {
+        return [NSString stringWithFormat:@"0%i",seconds];
+    } else if ( (seconds == 0) ) {
+        return [NSString stringWithFormat:@"00"];
+    } else {
+        return [NSString stringWithFormat:@"%i",seconds];
+    }
+}
+
 @end