Date.st
changeset 11664 01d637e51e0b
parent 11652 0799a4f46825
child 11665 352825372305
--- a/Date.st	Tue Apr 07 11:15:16 2009 +0200
+++ b/Date.st	Thu Apr 09 16:43:36 2009 +0200
@@ -685,6 +685,7 @@
     "
 ! !
 
+
 !Date class methodsFor:'change & update'!
 
 update:something with:aParameter from:changedObject
@@ -1481,16 +1482,45 @@
 
 !Date methodsFor:'Compatibility-ST80'!
 
+next:dayName 
+    "Return the next date whose weekday name is dayName.
+     Caveat; dayName is expected to be in the current language"
+
+    |ti ni|
+
+    ti := self weekdayIndex.
+    ni := (self class dayOfWeek:dayName).
+    ^ self addDays:(ni > ti ifTrue:[ ni-ti ] ifFalse:[ 7+ni-ti ])
+
+    "
+     Date today              
+     Date today next:#Friday
+     Date today next:#Sunday 
+     Date today next:#Monday 
+     Date today next:#Thursday
+     Date today next:#WednesDay
+    "
+!
+
 previous:dayName 
     "Return the previous date whose weekday name is dayName.
      Caveat; dayName is expected to be in the current language"
 
-    ^ self subtractDays:(self weekdayIndex - (self class dayOfWeek:dayName) - 1 \\ 7 + 1)
+    |ti pi|
+
+    ti := self weekdayIndex.
+    pi := (self class dayOfWeek:dayName).
+    ^ self subtractDays:(((ti - pi - 1) \\ 7) + 1)
 
     "
-     Date today                 
+     Date today                    
      Date today previous:#Monday 
-     Date today previous:#Friday 
+     Date today previous:#Friday  
+     Date today previous:#Sunday  
+     Date today previous:#Monday  
+     Date today previous:#Thursday  
+     Date today previous:#WednesDay 
+     Date today previous:#TuesDay  
     "
 !
 
@@ -2666,7 +2696,7 @@
 !Date class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.116 2009-03-23 07:20:42 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.117 2009-04-09 14:43:36 cg Exp $'
 ! !
 
 Date initialize!