[squeak-dev] The Trunk: Kernel-cmm.669.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Feb 3 23:56:23 UTC 2012


Chris Muller uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-cmm.669.mcz

==================== Summary ====================

Name: Kernel-cmm.669
Author: cmm
Time: 3 February 2012, 5:55:11.175 pm
UUID: 5ddec343-01ad-4e76-b32c-299fac68ec09
Ancestors: Kernel-eem.668

Introduced Timespan class>>defaultOffset.  This is the offset that will be used for creation of all Timespans when an offset is not specified.  When an offset is specified or involved in construction or calculation, the result is now produced in terms of the source offset.
	For example, Date today now produces a globalized date by default.  However, "Date starting: (DateAndTime year: 2004 month: 2 day: 29 hour: 13 minute: 33 second: 0 offset: 2 hours)" produces a Date.whose start is expressed in terms of UTC+2.
	The default defaultOffset is Duration zero so that Squeak will have fast, globalized Dates out of the box.  Globalized Dates are common for applications.
	Legacy localized Dates can be obtained by evaluating "Date localize" so that, when an offset is not specified or otherwise involved in the input, the local offset will be used.

=============== Diff against Kernel-eem.668 ===============

Item was changed:
  Timespan subclass: #Date
  	instanceVariableNames: ''
  	classVariableNames: ''
  	poolDictionaries: 'ChronologyConstants'
  	category: 'Kernel-Chronology'!
  
+ !Date commentStamp: 'cmm 2/3/2012 17:30' prior: 0!
- !Date commentStamp: '<historical>' prior: 0!
  Instances of Date are Timespans with duration of 1 day.
+ 
+ Their default creation assumes a start of midnight of UTC to provide the fast, globalized Dates out of the box.  The legacy behavior that creates Timezone-sensitive Dates can be used by sending #localizedDates.
+ !
- Their default creation assumes a start of midnight in the local time zone.!

Item was changed:
  ----- Method: Date class>>julianDayNumber: (in category 'squeak protocol') -----
+ julianDayNumber: aJulianDayNumber 
+ 	^ self starting:
+ 		(DateAndTime
+ 			julianDayNumber: aJulianDayNumber
+ 			offset: self defaultOffset)!
- julianDayNumber: aJulianDayNumber
- 
- 	^ self starting: (DateAndTime julianDayNumber: aJulianDayNumber)!

Item was changed:
  ----- Method: Date class>>starting: (in category 'squeak protocol') -----
  starting: aDateAndTime 
+ 	^ self
- 	^ super
  		starting: aDateAndTime midnight
  		duration: Duration oneDay!

Item was changed:
  ----- Method: Date class>>year:day: (in category 'squeak protocol') -----
+ year: year day: dayOfYear 
+ 	^ self starting:
+ 		(DateAndTime
+ 			year: year
+ 			day: dayOfYear
+ 			hour: 0
+ 			minute: 0
+ 			second: 0
+ 			offset: self defaultOffset)!
- year: year day: dayOfYear
- 
- 	^ self starting: (DateAndTime year: year day: dayOfYear)
- !

Item was changed:
  ----- Method: Date class>>year:month:day: (in category 'squeak protocol') -----
+ year: year month: month day: day 
+ 	^ self starting:
+ 		(DateAndTime
+ 			year: year
+ 			month: month
+ 			day: day
+ 			hour: 0
+ 			minute: 0
+ 			second: 0
+ 			offset: self defaultOffset)!
- year: year month: month day: day
- 
- 	^ self starting: (DateAndTime year: year month: month day: day)!

Item was changed:
  ----- Method: DateAndTime class>>julianDayNumber: (in category 'squeak protocol') -----
+ julianDayNumber: anInteger 
+ 	^ self
+ 		julianDayNumber: anInteger
+ 		offset: self localOffset!
- julianDayNumber: aJulianDayNumber
- 
- 	^ self basicNew
- 		ticks: aJulianDayNumber days ticks offset: self localOffset;
- 		yourself!

Item was added:
+ ----- Method: DateAndTime class>>julianDayNumber:offset: (in category 'squeak protocol') -----
+ julianDayNumber: anInteger offset: aDuration 
+ 	^ self basicNew
+ 		ticks: anInteger days ticks
+ 		offset: aDuration ;
+ 		 yourself!

Item was changed:
  ----- Method: DateAndTime class>>now (in category 'ansi protocol') -----
  now 
+ 	^ self nowWithOffset: self localOffset!
- 	| nanoTicks msm |
- 
- 	nanoTicks := (msm := self milliSecondsSinceMidnight) * 1000000.
- 
- 	(LastTick < nanoTicks) ifTrue: [
- 		LastTick := nanoTicks.
- 		^ self todayAtMilliSeconds: msm].
- 
- 	LastTickSemaphore critical: [
- 		LastTick :=  LastTick + 1.
- 		^ self todayAtNanoSeconds: LastTick]
- 
- " 
- [ 10000 timesRepeat: [ self now. ] ] timeToRun / 10000.0 . 
- 
- If calls to DateAndTime-c-#now are within a single millisecond the semaphore code 
- to ensure that (self now <= self now) slows things down considerably by a factor of about 20.
- 
- The actual speed of a single call to DateAndTime-now in milliseconds is 
- demonstrated by the unguarded method below.
- 
- [ 100000 timesRepeat: [ self todayAtMilliSeconds: (self milliSecondsSinceMidnight) ] ] timeToRun / 100000.0 .  0.00494 0.00481 0.00492 0.00495
-   
- "!

Item was added:
+ ----- Method: DateAndTime class>>nowWithOffset: (in category 'squeak protocol') -----
+ nowWithOffset: aDuration
+ 	| nanoTicks msm |
+ 
+ 	nanoTicks := (msm := self milliSecondsSinceMidnight) * 1000000.
+ 
+ 	(LastTick < nanoTicks) ifTrue: [
+ 		LastTick := nanoTicks.
+ 		^ self todayAtMilliSeconds: msm offset: aDuration].
+ 
+ 	LastTickSemaphore critical: [
+ 		LastTick :=  LastTick + 1.
+ 		^ self todayAtNanoSeconds: LastTick offset: aDuration]
+ 
+ " 
+ [ 10000 timesRepeat: [ self now. ] ] timeToRun / 10000.0 . 
+ 
+ If calls to DateAndTime-c-#now are within a single millisecond the semaphore code 
+ to ensure that (self now <= self now) slows things down considerably by a factor of about 20.
+ 
+ The actual speed of a single call to DateAndTime-now in milliseconds is 
+ demonstrated by the unguarded method below.
+ 
+ [ 100000 timesRepeat: [ self todayAtMilliSeconds: (self milliSecondsSinceMidnight) ] ] timeToRun / 100000.0 .  0.00494 0.00481 0.00492 0.00495
+   
+ "!

Item was changed:
  ----- Method: DateAndTime class>>todayAtMilliSeconds: (in category 'squeak protocol') -----
+ todayAtMilliSeconds: milliSecondsSinceMidnight 
+ self deprecated: 'Use todayAtMilliSeconds:offset:.'.
+ 	^ self
+ 		todayAtMilliSeconds: milliSecondsSinceMidnight
+ 		offset: self localOffset!
- todayAtMilliSeconds: milliSecondsSinceMidnight
- 
- 	"This is usually only during system startup..."
- 	self waitForOffsets.
- 
- 	 ^ self basicNew
- 			setJdn: DaysSinceEpoch 
- 			seconds: (milliSecondsSinceMidnight // 1000) 
- 			nano: (milliSecondsSinceMidnight  \\ 1000 * 1000000  ) 
- 			offset: self localOffset
- 	 
- " 
- [ 100000 timesRepeat: [ self fromMilliSeconds: self milliSecondsSinceMidnight. ] ] timeToRun.
- "!

Item was added:
+ ----- Method: DateAndTime class>>todayAtMilliSeconds:offset: (in category 'squeak protocol') -----
+ todayAtMilliSeconds: milliSecondsSinceMidnight offset: aDuration
+ 
+ 	"This is usually only during system startup..."
+ 	self waitForOffsets.
+ 
+ 	 ^ self basicNew
+ 			setJdn: DaysSinceEpoch 
+ 			seconds: (milliSecondsSinceMidnight // 1000) 
+ 			nano: (milliSecondsSinceMidnight  \\ 1000 * 1000000  ) 
+ 			offset: aDuration
+ 	 
+ " 
+ [ 100000 timesRepeat: [ self fromMilliSeconds: self milliSecondsSinceMidnight. ] ] timeToRun.
+ "!

Item was changed:
  ----- Method: DateAndTime class>>todayAtNanoSeconds: (in category 'squeak protocol') -----
+ todayAtNanoSeconds: nanoSecondsSinceMidnight 
+ self deprecated: 'Use todayAtNanoSeconds:offset:.'.
+ 	self
+ 		todayAtNanoSeconds: nanoSecondsSinceMidnight
+ 		offset: self localOffset!
- todayAtNanoSeconds: nanoSecondsSinceMidnight
- 
- 	"This is usually only during system startup..."
- 	self waitForOffsets.
- 
- 	^ self basicNew
- 			setJdn: DaysSinceEpoch 
- 			seconds: (nanoSecondsSinceMidnight // 1000000000) 
- 			nano: (nanoSecondsSinceMidnight  \\ 1000000000  ) 
- 			offset: self localOffset
-  !

Item was added:
+ ----- Method: DateAndTime class>>todayAtNanoSeconds:offset: (in category 'squeak protocol') -----
+ todayAtNanoSeconds: nanoSecondsSinceMidnight offset: aDuration
+ 
+ 	"This is usually only during system startup..."
+ 	self waitForOffsets.
+ 
+ 	^ self basicNew
+ 			setJdn: DaysSinceEpoch 
+ 			seconds: (nanoSecondsSinceMidnight // 1000000000) 
+ 			nano: (nanoSecondsSinceMidnight  \\ 1000000000  ) 
+ 			offset: self localOffset
+  !

Item was changed:
  ----- Method: DateAndTime>>asSeconds (in category 'smalltalk-80') -----
  asSeconds
  	"Return the number of seconds since the Squeak epoch"
+ 	^ (self - (self class epoch offset: offset)) asSeconds!
- 
- 	^ (self - (self class epoch)) asSeconds!

Item was changed:
  ----- Method: DateAndTime>>makeUTC (in category 'squeak protocol') -----
  makeUTC
+ 	"Make the receiver's timezone UTC."
- 	"Change the receiver's timezone to UTC. Like #asUTC, but modifies the receiver and is much faster."
  	self primOffset: Duration zero!

Item was changed:
  ----- Method: DateAndTime>>midnight (in category 'squeak protocol') -----
  midnight
+ 	"Answer a DateAndTime starting at midnight of the same timezone offset as the receiver."
+ 	^ self class basicNew
- 	"Answer a DateAndTime starting at midnight local time"
- 
- 	^self class basicNew
  		setJdn: jdn
  		seconds: 0
  		nano: 0
+ 		offset: offset!
- 		offset: self class localOffset
- !

Item was changed:
  ----- Method: Month class>>month:year: (in category 'squeak protocol') -----
+ month: month year: year 
- month: month year: year
  	"Create a Month for the given <year> and <month>.
  	<month> may be a number or a String with the
  	name of the month. <year> should be with 4 digits."
+ 	^ self starting:
+ 		(DateAndTime
+ 			year: year
+ 			month: month
+ 			day: 1
+ 			hour: 0
+ 			minute: 0
+ 			second: 0
+ 			offset: self defaultOffset)!
- 
- 	^ self starting: (DateAndTime year: year month: month day: 1)
- !

Item was changed:
  ----- Method: Month class>>starting:duration: (in category 'squeak protocol') -----
  starting: aDateAndTime duration: aDuration 
  	"Override - a each month has a defined duration"
  	| start adjusted days |
  	start := aDateAndTime asDateAndTime.
  	adjusted := DateAndTime
+ 		year: start year
+ 		month: start month
+ 		day: 1
+ 		hour: 0
+ 		minute: 0
+ 		second: 0
+ 		offset: start offset.
+ 	days := self
+ 		daysInMonth: adjusted month
+ 		forYear: adjusted year.
- 				year: start year
- 				month: start month
- 				day: 1.
- 	days := self daysInMonth: adjusted month forYear: adjusted year.
  	^ super
  		starting: adjusted
+ 		duration: (Duration days: days)!
- 		duration: (Duration days: days)
- !

Item was changed:
  Magnitude subclass: #Timespan
  	instanceVariableNames: 'start duration'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Kernel-Chronology'!
+ Timespan class
+ 	instanceVariableNames: 'defaultOffset'!
  
  !Timespan commentStamp: 'dtl 7/11/2009 16:35' prior: 0!
  I represent a duration starting on a specific DateAndTime.!
+ Timespan class
+ 	instanceVariableNames: 'defaultOffset'!

Item was changed:
  ----- Method: Timespan class>>current (in category 'squeak protocol') -----
  current
+ 	^ self starting: (DateAndTime nowWithOffset: self defaultOffset)!
- 
- 
- 	^ self starting: DateAndTime now!

Item was added:
+ ----- Method: Timespan class>>defaultOffset (in category 'configuring') -----
+ defaultOffset
+ 	^ defaultOffset!

Item was added:
+ ----- Method: Timespan class>>globalize (in category 'configuring') -----
+ globalize
+ 	"By default, Timespans will be created with a local timezone's offset."
+ 	defaultOffset := Duration zero!

Item was added:
+ ----- Method: Timespan class>>initialize (in category 'initialize-release') -----
+ initialize
+ 	self globalize!

Item was added:
+ ----- Method: Timespan class>>localize (in category 'configuring') -----
+ localize
+ 	"By default, Timespans will be created with a local timezone's offset."
+ 	defaultOffset := DateAndTime localOffset!

Item was changed:
  ----- Method: Timespan class>>new (in category 'squeak protocol') -----
  new
  	"Answer a Timespan starting on the Squeak epoch: 1 January 1901"
+ 	^ self starting: (DateAndTime new offset: self defaultOffset)!
- 
- 	^ self starting: DateAndTime new
- !

Item was changed:
  ----- Method: Year class>>year: (in category 'squeak protocol') -----
+ year: aYear 
+ 	^ self starting:
+ 		(DateAndTime
+ 			year: aYear
+ 			month: 1
+ 			day: 1
+ 			hour: 0
+ 			minute: 0
+ 			second: 0
+ 			offset: self defaultOffset)!
- year: aYear
- 
- 	^ self starting: (DateAndTime year: aYear month: 1 day: 1).!



More information about the Squeak-dev mailing list