I am making an app for my school. We are on a 7 day rotation schedule…so today is a G day, tomorrow will be an A day, Thursday B, Friday C, and Monday back to D. I want to put a UILabel on the homepage of my app that will output which “day” it is according to our schools A-G notation…can anyone think of a way to do this (that will be understood by a beginner)?
the problem with that is that Monday is not always an “A” day, because we go on a 7 day cycle but only go to school 5 days a week. Any ways around this?
I currently use NSDateFormatter hooked up to a string then to a UILabel to display the current day of the week, if that helps. code for that is below.
- (void)viewDidAppear:(BOOL)animated
{
//get the date today
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"cccc, MMMM dd"];
NSString *dateToday = [dateformatter stringFromDate:[NSDate date]];
[currentdate setText:dateToday];
//get the time today
NSDateFormatter *timeformatter = [[NSDateFormatter alloc] init];
[timeformatter setDateFormat:@"hh:mm a"];
NSString *timeToday = [timeformatter stringFromDate:[NSDate date]];
[currenttime setText:timeToday];
question:
would I use “setText:” to output it to the label? I declared an outlet called *letterday in my .h, and now am trying to send the letter to it, and then this in my .m:
[NSDate JL_currentRotationDayWithSchoolYearBeginningOnDateString:@"2011-09-12"];
[letterday setText:
does that look right? sorry im so behind on this…
You can view the source code for the entire category here with comments: https://gist.github.com/1590955
#import "NSDate+RotationScheduleFormatter.h"in every implementation file in which you would like to use the category. Then use the following method call to get the current rotation day:[NSDate JL_currentRotationDayWithSchoolYearBeginningOnDateString:@"2011-08-01"];where the date is in the formatYYYY-MM-DD.This will return a enum of type
RotationDay, one ofkRotationDay[A-G].In order for holiday breaks and other weekdays off of school to work you need to go into the .m file and edit the method called
+ (int)numberOfWeekdayBreakDaysBetweenSchoolYearBeginningDate:(NSDate *)beginningDate andEndDate:(NSDate *)endDate1In it you will see an array called
weekdayBreakArraywith a few values (in the formatYYYY-MM-DD). Remove these test values and add in every day of every break that lands on a weekday. Do not add dates that are on weekends.Implementation:
Assuming there exists a
UILabelcalledrotationLetter, you can do the following:and so on with more
else ifstatements until you reachkRotationDayG.Notes:
Remember to enclose your call to this method in an if statement that checks if you’re on a holiday break or on the weekend since the result will be incorrect otherwise. Also note that I did not optimize this class for memory management using manual retain/release because I wasn’t sure if you’re using ARC. Furthermore, the entire system fails if you have a snow day or some other unexpected break and you cannot update the app in time. Therefore I highly advise that you download the array of dates from a server every time you open the app in case you need to make a change on the fly.