'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 13 April 2006 at 10:26:16 am'!
"Change Set:		fasterDayOfYear-brp
Date:			29 January 2005
Author:			Brent Pinkney

This enhancement was contributed by Dan Ingalls.

It replaces the implementation of DateAndTime>>dayOfYear to speed it up by a factor of 80.

All 394 test cases in the Kernel-Chronology Tests category succeed in a 3.9a-6531 image.

	now := DateAndTime now.
	[ 10000 timesRepeat: [ now dayOfYear] ] timeToRun 

	Results:		2694 milliseconds with old code, 33 milliseconds with new code.


The following was also added, on the suggestion of Avi Bryant

	Duration >> isZero
	DateAndTime >> asUTC

It should be imcluded in 3.9 soonest.
"!


!DateAndTime methodsFor: 'ansi protocol' stamp: 'brp 4/13/2006 10:21'!
asUTC

	^ offset isZero
		ifTrue: [self]
		ifFalse: [self utcOffset: 0]
! !

!DateAndTime methodsFor: 'ansi protocol' stamp: 'brp 1/29/2005 10:27'!
dayOfYear
	"This code was contributed by Dan Ingalls. It is equivalent to the terser
		^ jdn - (Year year: self year) start julianDayNumber + 1 but much quicker."

	| monthStart |
	^ self dayMonthYearDo:
		[ :d :m :y |
			monthStart _ #(1 32 60 91 121 152 182 213 244 274 305 335) at: m.
			(m > 2 and: [ Year isLeapYear: y ])
				ifTrue: [ monthStart + d ]
				ifFalse: [ monthStart + d - 1 ]]! !


!Duration methodsFor: 'squeak protocol' stamp: 'brp 4/13/2006 10:20'!
isZero

	^ seconds = 0 and: [ nanos = 0 ]
! !

