Ignore:
Timestamp:
12/21/09 22:13:21 (15 years ago)
Author:
Nicholas Riley
Message:

Display "today" or "tomorrow" when setting an alarm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSAlarm.m

    r602 r608  
    2929
    3030static NSDateFormatter *dateFormatter, *shortDateFormatter, *timeFormatter;
     31
     32static NSCalendar *gregorianCalendar;
     33
     34static NSDate *midnightOnDate(NSDate *date) {
     35    return [gregorianCalendar dateFromComponents:
     36            [gregorianCalendar components: NSMonthCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit fromDate: date]];
     37}
    3138
    3239@implementation PSAlarm
     
    4653    [timeFormatter setTimeStyle: NSDateFormatterMediumStyle];
    4754    [timeFormatter setDateStyle: NSDateFormatterNoStyle];
     55    gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
    4856}
    4957
     
    246254}
    247255
     256- (NSDate *)midnightOnDate;
     257{
     258    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
     259   
     260    return midnightOnDate(alarmDate);
     261}
     262
    248263- (NSDate *)time;
    249264{
     
    251266    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
    252267
    253     NSCalendar *calendar = [NSCalendar currentCalendar];
    254 
    255     return [calendar dateFromComponents:
    256             [calendar components: NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate: alarmDate]];
     268    return [gregorianCalendar dateFromComponents:
     269            [gregorianCalendar components: NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate: alarmDate]];
     270}
     271
     272- (int)daysFromToday;
     273{
     274    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
     275   
     276    return [[gregorianCalendar components: NSDayCalendarUnit fromDate: midnightOnDate([NSDate date]) toDate: alarmDate options: 0] day];
    257277}
    258278
Note: See TracChangeset for help on using the changeset viewer.