-
Notifications
You must be signed in to change notification settings - Fork 0
/
EJ+CPString.j
45 lines (33 loc) · 995 Bytes
/
EJ+CPString.j
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
@import <Foundation/CPString.j>
var timeRegEx = new RegExp("t:(\\d+)h(\\d+)m", "gi");
@implementation CPString (EJ)
- (CPNumber)findTime
{
var time = 0;
var matches = timeRegEx.exec(self);
if (matches) {
time = 60 * parseInt(matches[1]) + parseInt(matches[2]);
}
return time;
}
- (CPString)removeTime
{
return self.replace(timeRegEx, "");
}
- (CPString)removeOccurencesOfString:(CPString)removeString
{
return [self stringByReplacingOccurrencesOfString:removeString withString:""];
}
- (CPDate)convertFromGitHubDateToCPDate
{
var dayThenTime = [self componentsSeparatedByString:@"T"];
if (dayThenTime) {
var date = [dayThenTime[0] componentsSeparatedByString:@"-"];
var time = [dayThenTime[1] componentsSeparatedByString:@":"];
if (date && time) {
return new Date(date[0], date[1] - 1, date[2], time[0], time[1], time[2].substring(0, 2));
}
}
return 0;
}
@end