This repository has been archived by the owner on Oct 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSString+OVSSTimeAdditions.m
67 lines (61 loc) · 1.92 KB
/
NSString+OVSSTimeAdditions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// NSString+OVSSTimeAdditions.m
// Core Data RunLog
//
// Created by John's MacBook on 3/22/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "NSString+OVSSTimeAdditions.h"
@implementation NSString (NSString_OVSSTimeAdditions)
+(NSString *)OVSSStringWithHours:(int)hours Minutes:(int)minutes Seconds:(int)seconds{
NSString *hourstring;
NSString *minutestring;
NSString *secondstring;
NSString *final;
if (hours<0 | minutes<0 | seconds<0) {
return @"error: invalid time value entered.";
}
if (hours==0 & minutes==0 & seconds==0) {
return @"";
}
if (hours==0) {
hourstring=[NSString stringWithFormat:@""];
}
if (hours>0) {
hourstring=[NSString stringWithFormat:@"%d:",hours];
}
if (minutes==0) {
minutestring=[NSString stringWithFormat:@""];
}
if (minutes>0 & hours==0) {
minutestring=[NSString stringWithFormat:@"%d:",minutes];
}
if (minutes>0 & hours>0) {
minutestring=[NSString stringWithFormat:@"0%d:",minutes];
}
if (minutes>10) {
minutestring=[NSString stringWithFormat:@"%d:",minutes];
}
if (seconds<10) {
secondstring=[NSString stringWithFormat:@"0%d",seconds];
}
if (seconds>=10) {
secondstring=[NSString stringWithFormat:@"%d",seconds];
}
if (hours==0 & minutes==0 & seconds!=0) {
return [NSString stringWithFormat:@"00:%@",secondstring];
}
if (hours==0) {
final=[NSString stringWithFormat:@"%@%@",minutestring,secondstring];
return final;
}
if (hours!=0 & seconds!=0 & minutes==0) {
return [NSString stringWithFormat:@"%@00:%@",hourstring,secondstring];
}
if (minutes==0 & seconds==0) {
return [NSString stringWithFormat:@"%@00:00",hourstring];
}
final=[NSString stringWithFormat:@"%@%@%@",hourstring,minutestring,secondstring];
return final;
}
@end