Date.st
changeset 18357 05ec4f009e76
parent 18271 c64f4a0c035d
child 18366 a6e62e167c32
child 18443 314b1142aefa
--- a/Date.st	Sat May 16 11:59:50 2015 +0200
+++ b/Date.st	Sun May 17 22:49:07 2015 +0200
@@ -260,15 +260,17 @@
      Notice, that this is not able to represent dates before 1901!!.
      Added for GNU/ST-80 compatibility"
 
-    |year rest d yearIncrement|
+    |year rest d yearIncrement yearAsDays|
 
     "approx. year"
     year := (dayCount // 366) + 1901.
+    yearAsDays := (self yearAsDays:year).
+
     dayCount < 0 ifTrue:[
-        rest := dayCount negated - (self yearAsDays:year) + 1. "+1 for ST-80 compatibility"
+        rest := dayCount negated - yearAsDays + 1. "+1 for ST-80 compatibility"
         yearIncrement := -1.
     ] ifFalse:[
-        rest := dayCount - (self yearAsDays:year) + 1. "+1 for ST-80 compatibility"
+        rest := dayCount - yearAsDays + 1. "+1 for ST-80 compatibility"
         yearIncrement := 1.
     ].
     rest > 365 ifTrue:[
@@ -298,15 +300,17 @@
      Date asDaysSince0 is the reverse operation.
      Notice, that this is a private interface"
 
-    |year rest d yearIncrement|
+    |year rest d yearIncrement yearAsDaysFrom0|
 
     "approx. year"
     year := (dayCount // 366).
+    yearAsDaysFrom0 := (self yearAsDaysFrom0:year).
+
     dayCount < 0 ifTrue:[
-        rest := dayCount negated - (self yearAsDaysFrom0:year) + 1. "+1 for ST-80 compatibility"
+        rest := dayCount negated - yearAsDaysFrom0 + 1. "+1 for ST-80 compatibility"
         yearIncrement := -1.
     ] ifFalse:[
-        rest := dayCount - (self yearAsDaysFrom0:year) + 1. "+1 for ST-80 compatibility"
+        rest := dayCount - yearAsDaysFrom0 + 1. "+1 for ST-80 compatibility"
         yearIncrement := 1.
     ].
     rest > 365 ifTrue:[
@@ -320,8 +324,8 @@
     ^ self newDay:rest year:year
 
     "
-     Date fromDaysSince0:0     -> 1 jan 0
-     Date fromDaysSince0:366   -> 1 jan 1
+     Date fromDaysFrom0:0     -> 1 jan 0
+     Date fromDaysFrom0:366   -> 1 jan 1
     "
 !
 
@@ -882,7 +886,6 @@
     ^ self newDay:day month:mon year:yr
 ! !
 
-
 !Date class methodsFor:'change & update'!
 
 update:something with:aParameter from:changedObject
@@ -1697,7 +1700,6 @@
     ^ self leapYear:yearInteger
 ! !
 
-
 !Date class methodsFor:'private'!
 
 dayAbbrevsForLanguage:languageOrNilForDefault
@@ -1871,7 +1873,6 @@
     "
 ! !
 
-
 !Date methodsFor:'Compatibility-ANSI'!
 
 dayOfWeek
@@ -2869,26 +2870,27 @@
     "Return the first day of a previous month (0=this month).
      CG: there are two such methods - which one is obsolete? (see firstDayInPreviousMonth:)"
 
-    |month year|
+    |month year monthNegated|
 
     month := self month.
     year := self year.
     month := month - nMonths.
     month < 1 ifTrue:[
-        year := year - 1 - (month negated // 12).
-        month := (12 - (month negated \\ 12)).
+        monthNegated := month negated.
+        year := year - 1 - (monthNegated // 12).
+        month := (12 - (monthNegated \\ 12)).
     ].
 
     ^ Date newDay:1 month:month year:year.
 
     "
      (Date newDay:3 month:6 year:2009) firstDayInMonth     
-     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0    
+     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:0  
      (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:5    
      (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:6    
      (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:7    
      (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:17    
-     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18    
+     (Date newDay:3 month:6 year:2009) firstDayOfPreviousMonth:18  
     "
 !
 
@@ -3028,7 +3030,6 @@
 ! !
 
 
-
 !Date methodsFor:'obsolete'!
 
 asAbsoluteTime
@@ -3099,7 +3100,6 @@
     ^ self addDays:days
 ! !
 
-
 !Date methodsFor:'printing & storing'!
 
 addPrintBindingsTo:aDictionary
@@ -3475,11 +3475,11 @@
 !Date class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.169 2015-04-22 17:50:37 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.170 2015-05-17 20:49:07 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.169 2015-04-22 17:50:37 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Date.st,v 1.170 2015-05-17 20:49:07 cg Exp $'
 ! !