-
Notifications
You must be signed in to change notification settings - Fork 0
/
SWMonthSelectTable.m
96 lines (76 loc) · 2.62 KB
/
SWMonthSelectTable.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// SWMonthSelectTable.m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Administrator on 4/11/07.
// Copyright 2007 Samuel Williams. All rights reserved.
//
#import "SWMonthSelectTable.h"
@implementation SWMonthSelectTable
- (NSString*) monthNameForNumber: (int)index {
switch(index) {
case 1: return @"January";
case 2: return @"Febuary";
case 3: return @"March";
case 4: return @"April";
case 5: return @"May";
case 6: return @"June";
case 7: return @"July";
case 8: return @"August";
case 9: return @"September";
case 10: return @"October";
case 11: return @"November";
case 12: return @"December";
}
return [NSString stringWithFormat:@"Unknown Month: %d", index];
}
- (BOOL)tableView:(NSTableView *)aTableView
shouldEditTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
return NO;
}
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex
{
if (dateToUpdate != nil) {
NSDate * cur = dateToUpdate.dateValue;
NSDateComponents * cmp = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:cur];
cmp.month = rowIndex + 1;
NSDate * next = [[NSCalendar currentCalendar] dateFromComponents:cmp];
dateToUpdate.dateValue = next;
}
return YES;
}
- (IBAction) plusWeek: (id) sender {
if (dateToUpdate != nil) {
NSDate * cur = dateToUpdate.dateValue;
NSDateComponents * cmp = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday fromDate:cur];
cmp.weekOfYear = cmp.weekOfYear + 1;
NSDate * next = [[NSCalendar currentCalendar] dateFromComponents:cmp];
dateToUpdate.dateValue = next;
}
}
- (IBAction) minusWeek: (id) sender {
if (dateToUpdate != nil) {
NSDate * cur = dateToUpdate.dateValue;
NSDateComponents * cmp = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday fromDate:cur];
cmp.weekOfYear = cmp.weekOfYear - 1;
NSDate * next = [[NSCalendar currentCalendar] dateFromComponents:cmp];
dateToUpdate.dateValue = next;
}
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
if ([aTableColumn.identifier isEqualTo:@"Number"]) {
return [NSString stringWithFormat:@"%d", rowIndex + 1];
} else if ([aTableColumn.identifier isEqualTo:@"Month"]) {
return [self monthNameForNumber: rowIndex + 1];
}
return nil;
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return 12;
}
@end