The Inbox: Kernel-cbc.870.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Kernel-cbc.870.mcz

commits-2
A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-cbc.870.mcz

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

Name: Kernel-cbc.870
Author: cbc
Time: 13 September 2014, 10:08:06.608 pm
UUID: 046ea585-0bc2-0f4b-82e1-d1e2f465b71e
Ancestors: Kernel-eem.869

Changes to support adding months and years to a DateAndTime, such as:
DateAndTime now + 2 months
and
DateAndTimeNow - 5 years

This requires retro-fitting the + and - in DateAndTime to a double dispatch system, and requires changes in Collections as well (to support + and - with String representations).

=============== Diff against Kernel-eem.869 ===============

Item was changed:
  ----- Method: DateAndTime>>+ (in category 'ansi protocol') -----
  + operand
+ "operand conforms to protocol Duration, or a Generic Month/Year"
+ ^operand addToDateTime: self
- "operand conforms to protocol Duration"
-
- | ticks |
-   ticks := self ticks + (operand asDuration ticks) .
-
- ^ self class basicNew
- ticks: ticks
- offset: self offset;
- yourself
  !

Item was added:
+ ----- Method: DateAndTime>>addToDateTime: (in category 'ansi protocol') -----
+ addToDateTime: aDateAndTime
+ ^self asDuration addToDateTime: aDateAndTime
+ !

Item was added:
+ ----- Method: Duration>>addToDateTime: (in category 'ansi protocol') -----
+ addToDateTime: aDateAndTime
+ | ticks |
+   ticks := self ticks + (aDateAndTime ticks) .
+ ^ aDateAndTime class basicNew
+ ticks: ticks
+ offset: aDateAndTime offset;
+ yourself
+ !

Item was added:
+ Object subclass: #GenericMonth
+ instanceVariableNames: 'number'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Kernel-Chronology'!

Item was added:
+ ----- Method: GenericMonth class>>months: (in category 'as yet unclassified') -----
+ months: aNumber
+ ^self new number: aNumber!

Item was added:
+ ----- Method: GenericMonth>>addNegativeToDateTime: (in category 'ansiProtocol') -----
+ addNegativeToDateTime: aDateAndTime
+ | next |
+ next := (1 to: number abs) inject: aDateAndTime into: [:end :mnth|
+ end - end dayOfMonth days.
+ ].
+ ^next - (next dayOfMonth - aDateAndTime dayOfMonth max: 0) days!

Item was added:
+ ----- Method: GenericMonth>>addToDateTime: (in category 'ansiProtocol') -----
+ addToDateTime: aDateAndTime
+ | next |
+ number < 0 ifTrue: [^self addNegativeToDateTime: aDateAndTime].
+ next := (1 to: number) inject: aDateAndTime into: [:end :mnth|
+ next := end + end daysInMonth days.
+ next dayOfMonth < end dayOfMonth
+ ifTrue: [next := next - next dayOfMonth days].
+ next
+ ].
+ ^next + ((next daysInMonth min: aDateAndTime dayOfMonth) - next dayOfMonth) days!

Item was added:
+ ----- Method: GenericMonth>>negated (in category 'accessing') -----
+ negated
+ number := number negated!

Item was added:
+ ----- Method: GenericMonth>>number (in category 'accessing') -----
+ number
+
+ ^ number!

Item was added:
+ ----- Method: GenericMonth>>number: (in category 'accessing') -----
+ number: anObject
+
+ number := anObject!

Item was added:
+ Object subclass: #GenericYear
+ instanceVariableNames: 'number'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Kernel-Chronology'!

Item was added:
+ ----- Method: GenericYear class>>years: (in category 'as yet unclassified') -----
+ years: aNumber
+ ^self new number: aNumber!

Item was added:
+ ----- Method: GenericYear>>addNegativeToDateTime: (in category 'ansiProtocol') -----
+ addNegativeToDateTime: aDateAndTime
+ | next |
+ next := (1 to: number abs) inject: aDateAndTime into: [:end :mnth|
+ end - end dayOfYear days.
+ ].
+ next := next - (next month - aDateAndTime month) months.
+ ^next - (next dayOfMonth - aDateAndTime dayOfMonth max: 0) days!

Item was added:
+ ----- Method: GenericYear>>addToDateTime: (in category 'ansiProtocol') -----
+ addToDateTime: aDateAndTime
+ | next |
+ number < 0 ifTrue: [^self addNegativeToDateTime: aDateAndTime].
+ ^(1 to: number) inject: aDateAndTime into: [:end :mnth|
+ next := end + end daysInYear days.
+ next month = end month
+ ifFalse: [next := next - next dayOfMonth days].
+ next
+ ].
+ !

Item was added:
+ ----- Method: GenericYear>>negated (in category 'accessing') -----
+ negated
+ number := number negated!

Item was added:
+ ----- Method: GenericYear>>number (in category 'accessing') -----
+ number
+
+ ^ number!

Item was added:
+ ----- Method: GenericYear>>number: (in category 'accessing') -----
+ number: anObject
+
+ number := anObject!

Item was added:
+ ----- Method: Number>>addToDateTime: (in category 'converting') -----
+ addToDateTime: aDateAndTime
+ ^self asDuration addToDateTime: aDateAndTime
+ !

Item was added:
+ ----- Method: Number>>month (in category 'converting') -----
+ month
+
+ ^ self sign months!

Item was added:
+ ----- Method: Number>>months (in category 'converting') -----
+ months
+
+ ^ GenericMonth months: self!

Item was added:
+ ----- Method: Number>>year (in category 'converting') -----
+ year
+
+ ^ self sign years!

Item was added:
+ ----- Method: Number>>years (in category 'converting') -----
+ years
+
+ ^ GenericYear years: self!

Item was added:
+ ----- Method: Time>>addToDateTime: (in category 'squeak protocol') -----
+ addToDateTime: aDateAndTime
+ ^self asDuration addToDateTime: aDateAndTime
+ !

Item was added:
+ ----- Method: Timespan>>addToDateTime: (in category 'squeak protocol') -----
+ addToDateTime: aDateAndTime
+ ^duration addToDateTime: aDateAndTime
+ !