-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPIUtil.m
More file actions
94 lines (79 loc) · 2.36 KB
/
APIUtil.m
File metadata and controls
94 lines (79 loc) · 2.36 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// APIUtil.m
// TwentyFirstCenturyTag
//
// Created by Christopher Ballinger on 7/5/11.
// Copyright 2011. All rights reserved.
//
#import "APIUtil.h"
@implementation APIUtil
+(NSString*)host
{
//return @"http://192.168.1.33:8888/api/v2";
//return @"http://192.168.2.104:8888/api/v2";
//return @"http://21tag.com:8689";
//return @"http://96.126.124.169:8420/api/v2"; //remote
return @"http://21tag.com:8420/api/v2";
}
+(NSString*)stringWithTimeDifferenceBetweenThen:(NSString *)then
{
NSTimeInterval time;
time = [self timeIntervalFromThen:then];
return [self stringwithFormatFrom:time];
}
+(NSString*)stringwithFormatFrom:(NSTimeInterval)time
{
//NSLog(@"Time interval from util: %f",time);
int hour, minute, second, day;
hour = time / 3600;
minute = (time - hour * 3600) / 60;
second = (time - hour * 3600 - minute * 60);
NSString *timeString;
if(hour >= 24)
{
day = hour / 24;
hour = hour - (day * 24);
if (day == 1) {
timeString = [NSString stringWithFormat:@"%d day %d hours", day, hour];
}
else
timeString = [NSString stringWithFormat:@"%d days %d hours", day, hour];
}
else if(hour == 0)
{
if (minute <1)
timeString = @"Less than a minute";
else if (minute == 1)
timeString = [NSString stringWithFormat:@"%d minute", minute];
else
timeString = [NSString stringWithFormat:@"%d minutes", minute];
}
else
timeString = [NSString stringWithFormat:@"%d hours %d minutes", hour, minute];
return timeString;
}
+(NSTimeInterval) timeIntervalFromThen:(NSString *)then
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSLocale *enUS = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormat setLocale:enUS];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
NSDate *date = [dateFormat dateFromString:then];
NSTimeInterval time = [date timeIntervalSinceNow];
time = ABS(time);
return time;
}
+(NSString*) StringWithTimeSince:(NSDate *)then
{
NSTimeInterval time = ABS([then timeIntervalSinceNow]);
return [self stringwithFormatFrom:time];
}
+(CLLocationDistance)minDistanceMeters
{
return [[self class] minDistanceFeet] * 0.3048;
}
+(int)minDistanceFeet
{
return 400;
}
@end