'From Squeak3.10.2 of ''5 June 2008'' [latest update: #7179] on 25 June 2009 at 10:24:09 pm'!
"Change Set:		DateAndTime-fromSeconds-dtl
Date:			25 June 2009
Author:			David T. Lewis

Allow #fromSeconds: to accept non-integer arguments, and update Time>>printString to display fractional seconds for better compatibility with the original Squeak implementation. The expressions 'DateAndTime fromSeconds: 0.5' and 'Time fromSeconds: 0.5' now behave as expected.

This change set fixes a limitation of #fromSeconds: that was introduced in Mantis 4669: [ENH] TimeForSpeed. It changes the corresponding #fromSeconds: and #printString for class Time to match DateAndTime and to be more compatible with the original Squeak implementation."!


!DateAndTime class methodsFor: 'smalltalk-80' stamp: 'dtl 6/21/2009 23:37'!
fromSeconds: seconds 
	"Answer a DateAndTime since the Squeak epoch: 1 January 1901"

	| integerSeconds nanos |
	integerSeconds := seconds truncated.
	integerSeconds = seconds
		ifTrue: [nanos := 0]
		ifFalse: [nanos := (seconds - integerSeconds * NanosInSecond) asInteger].
	^ self basicNew
		ticks: (Array
				with: SqueakEpoch
				with: integerSeconds
				with: nanos)
		offset: self localOffset! !


!Time methodsFor: 'printing' stamp: 'dtl 6/25/2009 19:24'!
print24: hr24 showSeconds: showSeconds on: aStream 
	"Format is 'hh:mm:ss' or 'h:mm:ss am'  or, if showSeconds is false, 'hh:mm' or 'h:mm am'"

	| h m s |
	h := self hour. m := self minute. s := self second.
	hr24
		ifTrue: 
			[ h < 10 ifTrue: [ aStream nextPutAll: '0' ].
			h printOn: aStream ]
		ifFalse:
			[ h > 12
				ifTrue: [h - 12 printOn: aStream]
				ifFalse: 
					[h < 1
						ifTrue: [ 12 printOn: aStream ]
						ifFalse: [ h printOn: aStream ]]].

	aStream nextPutAll: (m < 10 ifTrue: [':0'] ifFalse: [':']).
	m printOn: aStream.

	showSeconds ifTrue:
		[ aStream nextPutAll: (s < 10 ifTrue: [':0'] ifFalse: [':']).
		self nanoSecond == 0
			ifTrue: [s asInteger printOn: aStream]
			ifFalse: [(s + (self nanoSecond / NanosInSecond) asFloat) printOn: aStream]].

	hr24 ifFalse:
		[ aStream nextPutAll: (h < 12 ifTrue: [' am'] ifFalse: [' pm']) ].
! !

!Time methodsFor: 'printing' stamp: 'dtl 6/25/2009 19:13'!
printOn: aStream 

	self print24: false
		showSeconds: (self seconds ~= 0
				or: [self nanoSecond ~= 0])
		on: aStream! !


!Time class methodsFor: 'smalltalk-80' stamp: 'dtl 6/25/2009 07:43'!
fromSeconds: secondCount 
	"Answer an instance of me that is secondCount number of seconds since midnight."

	| integerSeconds nanos |
	integerSeconds := secondCount truncated.
	integerSeconds = secondCount
		ifTrue: [nanos := 0]
		ifFalse: [nanos := (secondCount - integerSeconds * NanosInSecond) asInteger].
	^ self seconds: integerSeconds nanoSeconds: nanos
! !

