Index: trunk/Cocoa/Pester/Source/PSAlarm.m
===================================================================
--- trunk/Cocoa/Pester/Source/PSAlarm.m	(revision 43)
+++ trunk/Cocoa/Pester/Source/PSAlarm.m	(revision 51)
@@ -20,4 +20,6 @@
 
 @implementation PSAlarm
+
+#pragma mark initialize-release
 
 + (void)initialize; // XXX change on locale modification, subscribe to NSNotifications
@@ -41,4 +43,6 @@
 }
 
+#pragma mark private
+
 - (void)_setAlarmDate:(NSCalendarDate *)aDate;
 {
@@ -50,5 +54,5 @@
 }
 
-- (void)_invalidate:(NSString *)aMessage;
+- (void)_beInvalid:(NSString *)aMessage;
 {
     alarmType = PSAlarmInvalid;
@@ -62,5 +66,5 @@
 }
 
-- (void)_validateForType:(PSAlarmType)type;
+- (void)_beValidWithType:(PSAlarmType)type;
 {
     if (alarmType == PSAlarmSet) return; // already valid
@@ -75,6 +79,35 @@
     alarmDate = [NSCalendarDate dateWithTimeIntervalSinceNow: alarmInterval];
     [alarmDate retain];
-    [self _validateForType: PSAlarmInterval];
-}
+    [self _beValidWithType: PSAlarmInterval];
+}
+
+- (void)_setIntervalFromDate;
+{
+    alarmInterval = [alarmDate timeIntervalSinceNow] + 1;
+    if (alarmInterval <= 0) {
+        [self _beInvalid: @"Please specify an alarm time in the future."];
+        return;
+    }
+    [self _beValidWithType: PSAlarmDate];
+}
+
+- (NSString *)_alarmTypeString;
+{
+    switch (alarmType) {
+        case PSAlarmDate: return @"PSAlarmDate";
+        case PSAlarmInterval: return @"PSAlarmInterval";
+        case PSAlarmSet: return @"PSAlarmSet";
+        case PSAlarmInvalid: return @"PSAlarmInvalid";
+        default: return [NSString stringWithFormat: @"<unknown: %u>", alarmType];
+    }
+}
+
+- (void)_timerExpired:(NSTimer *)aTimer;
+{
+    [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self];
+    [timer release]; timer = nil;
+}
+
+#pragma mark alarm setting
 
 - (void)setInterval:(NSTimeInterval)anInterval;
@@ -82,17 +115,7 @@
     alarmInterval = anInterval;
     if (alarmInterval <= 0) {
-        [self _invalidate: @"Please specify an alarm interval."]; return;
+        [self _beInvalid: @"Please specify an alarm interval."]; return;
     }
     [self _setDateFromInterval];
-}
-
-- (void)_setIntervalFromDate;
-{
-    alarmInterval = [alarmDate timeIntervalSinceNow] + 1;
-    if (alarmInterval <= 0) {
-        [self _invalidate: @"Please specify an alarm time in the future."];
-        return;
-    }
-    [self _validateForType: PSAlarmDate];
 }
 
@@ -107,11 +130,11 @@
     NSCalendarDate *calTime, *calDate;
     if (time == nil && date == nil) {
-        [self _invalidate: @"Please specify an alarm date and time."]; return;
+        [self _beInvalid: @"Please specify an alarm date and time."]; return;
     }
     if (time == nil) {
-        [self _invalidate: @"Please specify an alarm time."]; return;
+        [self _beInvalid: @"Please specify an alarm time."]; return;
     }
     if (date == nil) {
-        [self _invalidate: @"Please specify an alarm date."]; return;
+        [self _beInvalid: @"Please specify an alarm date."]; return;
     }
     // XXX if calTime's date is different from the default date, complain
@@ -119,5 +142,5 @@
     calDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate: [date timeIntervalSinceReferenceDate]];
     if (calTime == nil || calDate == nil) {
-        [self _invalidate: @"Please specify a reasonable date and time."];
+        [self _beInvalid: @"Please specify a reasonable date and time."];
     }
     [self setForDateAtTime:
@@ -131,8 +154,11 @@
 }
 
-- (BOOL)isValid;
-{
-    if (alarmType == PSAlarmDate) [self _setIntervalFromDate];
-    return (alarmType != PSAlarmInvalid);
+#pragma mark accessing
+
+- (NSString *)message;
+{
+    if (alarmMessage == nil || [alarmMessage isEqualToString: @""])
+        return @"Alarm!";
+    return alarmMessage;
 }
 
@@ -146,9 +172,8 @@
 }
 
-- (NSString *)message;
-{
-    if (alarmMessage == nil || [alarmMessage isEqualToString: @""])
-        return @"Alarm!";
-    return alarmMessage;    
+- (BOOL)isValid;
+{
+    if (alarmType == PSAlarmDate) [self _setIntervalFromDate];
+    return (alarmType != PSAlarmInvalid);
 }
 
@@ -163,4 +188,38 @@
     if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
     return alarmDate;
+}
+
+- (NSCalendarDate *)time;
+{
+    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
+    return [[NSCalendarDate alloc] initWithYear: 0
+                                          month: 1
+                                            day: 1
+                                           hour: [alarmDate hourOfDay]
+                                         minute: [alarmDate minuteOfHour]
+                                         second: [alarmDate secondOfMinute]
+                                       timeZone: nil];
+}
+
+- (NSTimeInterval)interval;
+{
+    if (alarmType == PSAlarmSet || alarmType == PSAlarmDate) [self _setIntervalFromDate];
+    return alarmInterval;
+}
+
+- (void)addAlert:(PSAlert *)alert;
+{
+    if (alerts == nil) alerts = [[NSMutableArray alloc] initWithCapacity: 4];
+    [alerts addObject: alert];
+}
+
+- (void)removeAlerts;
+{
+    [alerts removeAllObjects];
+}
+
+- (NSArray *)alerts;
+{
+    return [[alerts copy] autorelease];
 }
 
@@ -193,9 +252,5 @@
 }
 
-- (NSTimeInterval)interval;
-{
-    if (alarmType == PSAlarmSet || alarmType == PSAlarmDate) [self _setIntervalFromDate];
-    return alarmInterval;
-}
+#pragma mark actions
 
 - (BOOL)setTimer;
@@ -204,9 +259,5 @@
         case PSAlarmDate: if (![self isValid]) return NO;
         case PSAlarmInterval:
-            timer = [NSTimer scheduledTimerWithTimeInterval: alarmInterval
-                                                     target: self
-                                                   selector: @selector(_timerExpired:)
-                                                   userInfo: nil
-                                                    repeats: NO];
+            timer = [NSTimer scheduledTimerWithTimeInterval: alarmInterval target: self selector: @selector(_timerExpired:) userInfo: nil repeats: NO];
             if (timer != nil) {
                 [timer retain];
@@ -220,46 +271,22 @@
 }
 
-- (void)cancel;
+- (void)cancelTimer;
 {
     [timer invalidate]; [timer release]; timer = nil;
 }
 
-- (void)_timerExpired:(NSTimer *)aTimer;
-{
-    [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self];
-    [timer release]; timer = nil;
-}
-
-- (NSString *)_alarmTypeString;
-{
-    switch (alarmType) {
-        case PSAlarmDate: return @"PSAlarmDate";
-        case PSAlarmInterval: return @"PSAlarmInterval";
-        case PSAlarmSet: return @"PSAlarmSet";
-        case PSAlarmInvalid: return @"PSAlarmInvalid";
-        default: return [NSString stringWithFormat: @"<unknown: %u>", alarmType];
-    }
-}
-
-- (NSComparisonResult)compare:(PSAlarm *)otherAlarm;
+#pragma mark comparing
+
+- (NSComparisonResult)compareDate:(PSAlarm *)otherAlarm;
 {
     return [[self date] compare: [otherAlarm date]];
 }
 
-- (void)addAlert:(PSAlert *)alert;
-{
-    if (alerts == nil) alerts = [[NSMutableArray alloc] initWithCapacity: 4];
-    [alerts addObject: alert];
-}
-
-- (void)removeAlerts;
-{
-    [alerts removeAllObjects];
-}
-
-- (NSArray *)alerts;
-{
-    return [[alerts copy] autorelease];
-}
+- (NSComparisonResult)compareMessage:(PSAlarm *)otherAlarm;
+{
+    return [[self message] caseInsensitiveCompare: [otherAlarm message]];
+}
+
+#pragma mark printing
 
 - (NSString *)description;
@@ -272,4 +299,6 @@
            [NSString stringWithFormat: @"\ntimer: %@", timer] : @""))];
 }
+
+#pragma mark archiving
 
 - (void)encodeWithCoder:(NSCoder *)coder;
