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/PSAlarmSetController.m

    r606 r608  
    165165{
    166166    // NSLog(@"updateDateDisplay: %@", sender);
    167     if ([alarm isValid]) {
    168         [self setStatus: [NSString stringWithFormat: @"Alarm will be set for %@\non %@.", [alarm timeString], [alarm dateString]]];
    169         [setButton setEnabled: YES];
    170         if (updateTimer == nil || ![updateTimer isValid]) {
    171             // XXX this logic (and the timer) should really go into PSAlarm, to send notifications for status updates instead.  Timer starts when people are watching, stops when people aren't.
    172             // NSLog(@"setting timer");
    173             if (isInterval) {
    174                 updateTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: YES];
    175             } else {
    176                 updateTimer = [NSTimer scheduledTimerWithTimeInterval: [alarm interval] target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: NO];
    177             }
    178             [updateTimer retain];
    179         }
    180     } else {
    181         [setButton setEnabled: NO];
    182         [self setStatus: [alarm invalidMessage]];
    183         [self _stopUpdateTimer];
     167    if (![alarm isValid]) {
     168        [setButton setEnabled: NO];
     169        [self setStatus: [alarm invalidMessage]];
     170        [self _stopUpdateTimer];
     171        return;
     172    }
     173   
     174    const int day = 60 * 60 * 24;
     175    int daysUntilAlarm = [alarm daysFromToday];
     176    NSString *onString;
     177    switch (daysUntilAlarm) {
     178        case 0: onString = @"today,"; break;
     179        case 1: onString = @"tomorrow,"; break;
     180        default: onString = @"on";
     181    }
     182   
     183    [self setStatus: [NSString stringWithFormat: @"Alarm will be set for %@\n%@ %@.", [alarm timeString], onString, [alarm dateString]]];
     184    [setButton setEnabled: YES];
     185    if (updateTimer == nil || ![updateTimer isValid]) {
     186        // XXX this logic (and the timer) should really go into PSAlarm, to send notifications for status updates instead.  Timer starts when people are watching, stops when people aren't.
     187        // NSLog(@"setting timer");
     188        if (isInterval) {
     189            updateTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: YES];
     190        } else {
     191            // XXX time/time zone change
     192            NSTimeInterval interval = [alarm interval];
     193            if (daysUntilAlarm < 2 && interval > day)
     194                interval = [[alarm midnightOnDate] timeIntervalSinceNow];
     195            updateTimer = [NSTimer scheduledTimerWithTimeInterval: interval target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: NO];
     196        }
     197        [updateTimer retain];
    184198    }
    185199}
Note: See TracChangeset for help on using the changeset viewer.