-
Notifications
You must be signed in to change notification settings - Fork 3
/
CPDate+Additions.j
90 lines (74 loc) · 1.85 KB
/
CPDate+Additions.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
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
@implementation CPDate (parts)
- (CPString)monthByName
{
//returns the month by it's actual name
var month = self.getMonth();
switch(month){
case 0: month = @"January";
break;
case 1: month = @"February";
break;
case 2: month = @"March";
break;
case 3: month = @"April";
break;
case 4: month = @"May";
break;
case 5: month = @"June";
break;
case 6: month = @"July";
break;
case 7: month = @"August";
break;
case 8: month = @"September";
break;
case 9: month = @"October";
break;
case 10:month = @"November";
break;
case 11:month = @"December";
break;
}
return month;
}
- (CPString)longStringDate
{
return [self monthByName] + " " + [self enlongatedDay] + ", " + self.getFullYear();
}
- (CPString)enlongatedDay
{
var day = String(self.getDate());
if (day.length === 2 && day[1] === "1")
return day + "st";
// if the last character is ...
if (day[day.length] === "1")
return day + "st";
else if (day[day.length] === "2")
return day + "nd";
else if (day[day.length] === "3")
return day + "rd";
else
return day + "th";
/*
-1st
-2nd
-3rd
4th
5th
6th
7th
8th
9th
10th
11th
13th
20th
-21st
-22nd
-23rd
24th
30th
-31st
*/
}
@end