class: Timestamp
authorStefan Vogel <sv@exept.de>
Fri, 12 Sep 2014 17:17:16 +0200
changeset 16836 62f28e466c23
parent 16835 08f60ee0a4ed
child 16837 9b2a9bcf1af5
class: Timestamp TimstampBuilderAbstract>>#dateFromDayNumber:
Timestamp.st
--- a/Timestamp.st	Fri Sep 12 17:16:00 2014 +0200
+++ b/Timestamp.st	Fri Sep 12 17:17:16 2014 +0200
@@ -354,6 +354,7 @@
     "Modified: / 13.7.1999 / 12:30:26 / stefan"
 ! !
 
+
 !Timestamp class methodsFor:'private'!
 
 basicReadFrom:aStream
@@ -1482,6 +1483,7 @@
     "
 ! !
 
+
 !Timestamp methodsFor:'accessing'!
 
 day
@@ -2356,6 +2358,8 @@
     "
 ! !
 
+
+
 !Timestamp methodsFor:'testing'!
 
 isTimestamp
@@ -2435,18 +2439,19 @@
     "Modified: / 16-06-2005 / 15:04:45 / masca"
 !
 
-dateFromDayNumber: anInteger
+dateFromDayNumber: dayInYear
     "Set month and day from an absolute number of the day in the year. 1.1. is day number one."
 
-    | leap |
-    leap := self isLeapYear: year.
-
-    (anInteger between: 1 and: 365) ifFalse: [
-        (leap and: [anInteger = 366])
-            ifFalse: [self malformed: 'Bad day number: ' , anInteger printString]
+    |monthAndDay|
+
+    (dayInYear between: 1 and: 365) ifFalse: [
+        (dayInYear = 366 and:[self leapYear: year])
+            ifFalse: [self malformed: 'Bad day number: ' , dayInYear printString]
     ].
 
-    self shouldImplement
+    monthAndDay := Date monthAndDayFromDayInYear:dayInYear forYear:year.
+    month := monthAndDay at:1.
+    day := monthAndDay at:2
 
     "Created: / 15-06-2005 / 11:27:35 / masca"
     "Modified: / 16-06-2005 / 12:31:37 / masca"
@@ -2485,13 +2490,19 @@
 lastDayInMonth: anInteger
     "Answer the number of the last day of the given month in the current year."
 
-    ^anInteger = 2
-        ifTrue: [(self isLeapYear: year) ifTrue: [29] ifFalse: [28]]
+    ^ anInteger = 2
+        ifTrue: [(self leapYear: year) ifTrue: [29] ifFalse: [28]]
         ifFalse: [#(31 28 31 30 31 30 31 31 30 31 30 31) at: month]
 
     "Created: / 15-06-2005 / 17:12:31 / masca"
 !
 
+leapYear: anInteger
+    ^ Date leapYear:anInteger.
+
+    "Created: / 15-06-2005 / 16:16:31 / masca"
+!
+
 timestampWithClass:timestampClass
     "Answer the timestamp as it has been parsed."
     "Notes:
@@ -3146,11 +3157,11 @@
 !Timestamp class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.154 2014-07-09 16:20:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.155 2014-09-12 15:17:16 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.154 2014-07-09 16:20:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.155 2014-09-12 15:17:16 stefan Exp $'
 ! !