Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added TimesSquare/Resources/CalendarPreviousMonth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/CalendarRow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/CalendarRowBottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/CalendarSelectedDate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/CalendarTodaysDate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TimesSquare/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion TimesSquare/TSQCalendarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (NSUInteger)daysInWeek;
{
static NSUInteger daysInWeek = 0;
if (daysInWeek == 0) {
daysInWeek = [self.calendar maximumRangeOfUnit:NSWeekdayCalendarUnit].length;
daysInWeek = [self.calendar maximumRangeOfUnit:NSCalendarUnitWeekday].length;
}
return daysInWeek;
}
Expand Down
10 changes: 5 additions & 5 deletions TimesSquare/TSQCalendarRowCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ - (void)setBeginningDate:(NSDate *)date;
[self.notThisMonthButtons[index] setTitle:title forState:UIControlStateDisabled];
[self.notThisMonthButtons[index] setAccessibilityLabel:accessibilityLabel];

NSDateComponents *thisDateComponents = [self.calendar components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:date];
NSDateComponents *thisDateComponents = [self.calendar components:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear fromDate:date];

[self.dayButtons[index] setHidden:YES];
[self.notThisMonthButtons[index] setHidden:YES];
Expand Down Expand Up @@ -232,9 +232,9 @@ - (void)selectColumnForDate:(NSDate *)date;

NSInteger newIndexOfSelectedButton = -1;
if (date) {
NSInteger thisDayMonth = [self.calendar components:NSMonthCalendarUnit fromDate:date].month;
NSInteger thisDayMonth = [self.calendar components:NSCalendarUnitMonth fromDate:date].month;
if (self.monthOfBeginningDate == thisDayMonth) {
newIndexOfSelectedButton = [self.calendar components:NSDayCalendarUnit fromDate:self.beginningDate toDate:date options:0].day;
newIndexOfSelectedButton = [self.calendar components:NSCalendarUnitDay fromDate:self.beginningDate toDate:date options:0].day;
if (newIndexOfSelectedButton >= (NSInteger)self.daysInWeek) {
newIndexOfSelectedButton = -1;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ - (NSDateFormatter *)accessibilityFormatter;
- (NSInteger)monthOfBeginningDate;
{
if (!_monthOfBeginningDate) {
_monthOfBeginningDate = [self.calendar components:NSMonthCalendarUnit fromDate:self.firstOfMonth].month;
_monthOfBeginningDate = [self.calendar components:NSCalendarUnitMonth fromDate:self.firstOfMonth].month;
}
return _monthOfBeginningDate;
}
Expand All @@ -293,7 +293,7 @@ - (void)setFirstOfMonth:(NSDate *)firstOfMonth;
- (NSDateComponents *)todayDateComponents;
{
if (!_todayDateComponents) {
self.todayDateComponents = [self.calendar components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:[NSDate date]];
self.todayDateComponents = [self.calendar components:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear fromDate:[NSDate date]];
}
return _todayDateComponents;
}
Expand Down
20 changes: 10 additions & 10 deletions TimesSquare/TSQCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ - (void)setPinsHeaderToTop:(BOOL)pinsHeaderToTop;
- (void)setFirstDate:(NSDate *)firstDate;
{
// clamp to the beginning of its month
_firstDate = [self clampDate:firstDate toComponents:NSMonthCalendarUnit|NSYearCalendarUnit];
_firstDate = [self clampDate:firstDate toComponents:NSCalendarUnitMonth|NSCalendarUnitYear];
}

- (void)setLastDate:(NSDate *)lastDate;
{
// clamp to the end of its month
NSDate *firstOfMonth = [self clampDate:lastDate toComponents:NSMonthCalendarUnit|NSYearCalendarUnit];
NSDate *firstOfMonth = [self clampDate:lastDate toComponents:NSCalendarUnitMonth|NSCalendarUnitYear];

NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
offsetComponents.month = 1;
Expand All @@ -126,7 +126,7 @@ - (void)setLastDate:(NSDate *)lastDate;
- (void)setSelectedDate:(NSDate *)newSelectedDate;
{
// clamp to beginning of its day
NSDate *startOfDay = [self clampDate:newSelectedDate toComponents:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit];
NSDate *startOfDay = [self clampDate:newSelectedDate toComponents:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear];

if ([self.delegate respondsToSelector:@selector(calendarView:shouldSelectDate:)] && ![self.delegate calendarView:self shouldSelectDate:startOfDay]) {
return;
Expand Down Expand Up @@ -186,7 +186,7 @@ - (TSQCalendarRowCell *)cellForRowAtDate:(NSDate *)date;

- (NSInteger)sectionForDate:(NSDate *)date;
{
return [self.calendar components:NSMonthCalendarUnit fromDate:self.firstDate toDate:date options:0].month;
return [self.calendar components:NSCalendarUnitMonth fromDate:self.firstDate toDate:date options:0].month;
}

- (NSIndexPath *)indexPathForRowAtDate:(NSDate *)date;
Expand All @@ -198,8 +198,8 @@ - (NSIndexPath *)indexPathForRowAtDate:(NSDate *)date;
NSInteger section = [self sectionForDate:date];
NSDate *firstOfMonth = [self firstOfMonthForSection:section];

NSInteger firstWeek = [self.calendar components:NSWeekOfMonthCalendarUnit fromDate:firstOfMonth].weekOfMonth;
NSInteger targetWeek = [self.calendar components:NSWeekOfMonthCalendarUnit fromDate:date].weekOfMonth;
NSInteger firstWeek = [self.calendar components:NSCalendarUnitWeekOfMonth fromDate:firstOfMonth].weekOfMonth;
NSInteger targetWeek = [self.calendar components:NSCalendarUnitWeekOfMonth fromDate:date].weekOfMonth;

return [NSIndexPath indexPathForRow:(self.pinsHeaderToTop ? 0 : 1) + targetWeek - firstWeek inSection:section];
}
Expand Down Expand Up @@ -237,13 +237,13 @@ - (void)layoutSubviews;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
return 1 + [self.calendar components:NSMonthCalendarUnit fromDate:self.firstDate toDate:self.lastDate options:0].month;
return 1 + [self.calendar components:NSCalendarUnitMonth fromDate:self.firstDate toDate:self.lastDate options:0].month;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
NSDate *firstOfMonth = [self firstOfMonthForSection:section];
NSRange rangeOfWeeks = [self.calendar rangeOfUnit:NSWeekCalendarUnit inUnit:NSMonthCalendarUnit forDate:firstOfMonth];
NSRange rangeOfWeeks = [self.calendar rangeOfUnit:NSCalendarUnitWeekOfMonth inUnit:NSCalendarUnitMonth forDate:firstOfMonth];
return (self.pinsHeaderToTop ? 0 : 1) + rangeOfWeeks.length;
}

Expand Down Expand Up @@ -276,10 +276,10 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce
NSDate *firstOfMonth = [self firstOfMonthForSection:indexPath.section];
[(TSQCalendarCell *)cell setFirstOfMonth:firstOfMonth];
if (indexPath.row > 0 || self.pinsHeaderToTop) {
NSInteger ordinalityOfFirstDay = [self.calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:firstOfMonth];
NSInteger ordinalityOfFirstDay = [self.calendar ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitWeekOfMonth forDate:firstOfMonth];
NSDateComponents *dateComponents = [NSDateComponents new];
dateComponents.day = 1 - ordinalityOfFirstDay;
dateComponents.week = indexPath.row - (self.pinsHeaderToTop ? 0 : 1);
dateComponents.weekOfMonth = indexPath.row - (self.pinsHeaderToTop ? 0 : 1);
[(TSQCalendarRowCell *)cell setBeginningDate:[self.calendar dateByAddingComponents:dateComponents toDate:firstOfMonth options:0]];
[(TSQCalendarRowCell *)cell selectColumnForDate:self.selectedDate];

Expand Down
14 changes: 14 additions & 0 deletions TimesSquare/TSQTACalendarRowCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TSQTACalendarRowCell.h
// TimesSquare
//
// Created by Jim Puls on 12/5/12.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import "TimesSquare.h"

@interface TSQTACalendarRowCell : TSQCalendarRowCell

@end
42 changes: 42 additions & 0 deletions TimesSquare/TSQTACalendarRowCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// TSQTACalendarRowCell.m
// TimesSquare
//
// Created by Jim Puls on 12/5/12.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import "TSQTACalendarRowCell.h"

@implementation TSQTACalendarRowCell

- (void)layoutViewsForColumnAtIndex:(NSUInteger)index inRect:(CGRect)rect;
{
// Move down for the row at the top
rect.origin.y += self.columnSpacing;
rect.size.height -= (self.bottomRow ? 2.0f : 1.0f) * self.columnSpacing;
[super layoutViewsForColumnAtIndex:index inRect:rect];
}

- (UIImage *)todayBackgroundImage;
{
return [[UIImage imageNamed:@"CalendarTodaysDate.png"] stretchableImageWithLeftCapWidth:4 topCapHeight:4];
}

- (UIImage *)selectedBackgroundImage;
{
return [[UIImage imageNamed:@"CalendarSelectedDate.png"] stretchableImageWithLeftCapWidth:4 topCapHeight:4];
}

- (UIImage *)notThisMonthBackgroundImage;
{
return [[UIImage imageNamed:@"CalendarPreviousMonth.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
}

- (UIImage *)backgroundImage;
{
return [UIImage imageNamed:[NSString stringWithFormat:@"CalendarRow%@.png", self.bottomRow ? @"Bottom" : @""]];
}

@end
16 changes: 16 additions & 0 deletions TimesSquare/TSQTAViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TSQTAViewController.h
// TimesSquare
//
// Created by Jim Puls on 12/5/12.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import <UIKit/UIKit.h>

@interface TSQTAViewController : UIViewController

@property (nonatomic, strong) NSCalendar *calendar;

@end
86 changes: 86 additions & 0 deletions TimesSquare/TSQTAViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// TSQTAViewController.m
// TimesSquare
//
// Created by Jim Puls on 12/5/12.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import "TSQTAViewController.h"
#import "TSQTACalendarRowCell.h"
#import "TimesSquare.h"


@interface TSQTAViewController ()

@property (nonatomic, retain) NSTimer *timer;

@end


@interface TSQCalendarView (AccessingPrivateStuff)

@property (nonatomic, readonly) UITableView *tableView;

@end


@implementation TSQTAViewController

- (void)loadView;
{
TSQCalendarView *calendarView = [[TSQCalendarView alloc] init];
calendarView.calendar = self.calendar;
calendarView.rowCellClass = [TSQTACalendarRowCell class];
//calendarView.firstDate = [NSDate dateWithTimeIntervalSinceNow:-60 * 60 * 24 * 365 * 1];
calendarView.firstDate = [[NSDate alloc]init];
calendarView.lastDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * 365 * 1];
//calendarView.lastDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * 365 * 5];
calendarView.backgroundColor = [UIColor colorWithRed:0.84f green:0.85f blue:0.86f alpha:1.0f];
calendarView.pagingEnabled = YES;
CGFloat onePixel = 1.0f / [UIScreen mainScreen].scale;
calendarView.contentInset = UIEdgeInsetsMake(0.0f, onePixel, 0.0f, onePixel);

self.view = calendarView;
}

- (void)setCalendar:(NSCalendar *)calendar;
{
_calendar = calendar;

self.navigationItem.title = calendar.calendarIdentifier;
self.tabBarItem.title = calendar.calendarIdentifier;
}

- (void)viewDidLayoutSubviews;
{
// Set the calendar view to show today date on start
[(TSQCalendarView *)self.view scrollToDate:[NSDate date] animated:NO];
}

- (void)viewDidAppear:(BOOL)animated;
{
[super viewDidAppear:animated];

// Uncomment this to test scrolling performance of your custom drawing
// self.timer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(scroll) userInfo:nil repeats:YES];
}

- (void)viewWillDisappear:(BOOL)animated;
{
[self.timer invalidate];
self.timer = nil;
}

- (void)scroll;
{
static BOOL atTop = YES;
TSQCalendarView *calendarView = (TSQCalendarView *)self.view;
UITableView *tableView = calendarView.tableView;

[tableView setContentOffset:CGPointMake(0.f, atTop ? 10000.f : 0.f) animated:YES];
atTop = !atTop;
}

@end
6 changes: 3 additions & 3 deletions TimesSquare/TimesSquare.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

#import <TimesSquare/TSQCalendarMonthHeaderCell.h>
#import <TimesSquare/TSQCalendarRowCell.h>
#import <TimesSquare/TSQCalendarView.h>
#import "TSQCalendarMonthHeaderCell.h"
#import "TSQCalendarRowCell.h"
#import "TSQCalendarView.h"