-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSDate-Extended.m
81 lines (72 loc) · 2.02 KB
/
NSDate-Extended.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// NSDate-Extended.m
// Sambaworks
//
// Created by Shaun on Wednesday, March 9 2011.
// Copyright 2011 Sambaworks. All rights reserved.
//
#import "NSDate-Extended.h"
#import "Definitions.h"
const int zenithDate = 21;
const int march = 3;
const int june = 6;
const int september = 9;
const int december = 12;
@implementation NSDate (NSDate_Season)
+(NSString *) whatSeasonIsThisDateIn:(NSDate *)date{
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *comps = [cal components:unitFlags fromDate:date];
int day = [comps day];
int month = [comps month];
int year = [comps year];
NSString *retVal;
NSLog(@"%d, %d %d",day, month, year);
if (month <= march OR month == december) {
NSLog(@"%@, %@",month,day);
if (month == march AND day < zenithDate) {
retVal = @"Winter";
}
else if (month == december AND day > zenithDate) {
retVal = @"Winter";
}
else{
retVal = @"Winter";
}
}
else if(month >= march AND month <= june){
if (month == march AND day > zenithDate) {
retVal = @"Spring";
}
if (month == june AND day < zenithDate) {
retVal = @"Spring";
}
else{
retVal = @"Spring";
}
}
else if(month >= june AND month <= september){
if (month == june AND day > zenithDate) {
retVal = @"Summer";
}
else if (month == september AND day < zenithDate){
retVal = @"Summer";
}
else {
retVal = @"Summer";
}
}
else if (month >= september AND month <= december){
if (month == september AND day > zenithDate) {
retVal = @"Autumn";
}
else if (month == december AND day < zenithDate){
retVal = @"Autumn";
}
else{
retVal = @"Autumn";
}
}
return retVal;
}
@end