[Glass] Comment of #newDay:monthNumber:year: is wrong (and I do not like the behavior either!)

Dale Henrichs via Glass glass at lists.gemtalksystems.com
Mon Aug 10 17:03:17 PDT 2015


Thanks Mariano,

It looks good. I've attached your patch to the internal bug .... I'll 
let you know how things go ...

Dale

On 08/10/2015 03:46 PM, Mariano Martinez Peck wrote:
> Date  class compileMethod: ' numberOfDaysIn: month year: aYear
>
> ((month == 1) or: [(month == 3) or: [(month == 5) or: [(month == 7) or:
>    [(month == 8) or: [(month == 10) or: [(month == 12)]]]]]])
>    ifTrue: [^ 31].
> ((month == 4) or: [(month == 6) or: [(month == 9) or: [(month == 11)]]])
>    ifTrue: [^ 30].
> (((aYear \\ 100) == 0)
>    ifTrue: [ ((aYear \\ 400) == 0)]
>    ifFalse: [ ((aYear \\ 4) == 0) ])
>   ifTrue: [^ 29].
> ^ 28
> '
> dictionaries: GsSession currentSession symbolList
> category: 'Accessing'
> environmentId: 0.
>
>
>
> Date  class compileMethod: '_newDay: day monthNumber: month year: year
>
> <primitive: 316>
>
> day _validateClass: SmallInteger .
> month _validateClass: SmallInteger .
> year _validateClass: SmallInteger .
>
> ^ self _primitiveFailed: #newDay:monthNumber:year:
>        args: { day . month . year }
> '
> dictionaries: GsSession currentSession symbolList
> category: 'Instance Creation'
> environmentId: 0.
>
>
> Date  class compileMethod: 'newDay: day monthNumber: month year: year
>
> (month between: 1 and: 12) ifFalse: [ self error: ''Incorrect 
> specified month: '', month asString].
> (day between: 1 and: (self numberOfDaysIn: month year: year)) ifFalse: 
> [ self error: ''Incorrect specified day: '', day asString].
>
> ^ self _newDay: day monthNumber: month year: year
> '
> dictionaries: GsSession currentSession symbolList
> category: 'Instance Creation'
> environmentId: 0.
>
>
>
> Date compileMethod: 'addMonths: anInteger
>
> "Returns a Date that describes a date anInteger months later than that 
> of the
>  receiver.
>
>  This method attempts to keep the day of the month the same.  If the
>  new month has fewer days than the receiver''s original month, then it
>  truncates to the last day of the new month."
>
> | yr month day newYear newMonth newDay newDate generatedDay |
>
> yr := self year.
> month := self month.
> day := self day.
>
> newMonth := month + anInteger.
> newYear := yr + ((newMonth - 1) // 12).
> newMonth := (newMonth - 1) \\ 12 + 1.
> newDate := self class _newDay: day monthNumber: newMonth year: newYear.
> generatedDay := newDate day.
> (generatedDay ~= day)
>   ifTrue: [
>     newDay := newDate _daysInMonth: newMonth.
>     newDate := self class _newDay: newDay monthNumber: newMonth year: 
> newYear
>     ].
> ^ newDate.
>
> '
> dictionaries: GsSession currentSession symbolList
> category: 'Arithmetic'
> environmentId: 0.
>
>
> Date compileMethod: 'addYears: anInteger
>
> "Returns a Date that describes a date anInteger years later than that 
> of the
>  receiver."
>
> | yr month day newYear newDay newDate generatedDay |
>
> yr := self year.
> month := self month.
> day := self day.
>
> newYear := yr + anInteger.
> newDate := self class _newDay: day monthNumber: month year: newYear.
> generatedDay := newDate day.
> (generatedDay ~= day)
>   ifTrue: [
>     newDay := newDate _daysInMonth: month.
>     newDate := self class _newDay: newDay monthNumber: month year: newYear
>     ].
> ^ newDate.
>
> '
> dictionaries: GsSession currentSession symbolList
> category: 'Arithmetic'
> environmentId: 0.
>
>
> Date class compileMethod: 'newDay: day year: year
>
> "Creates and returns an instance of the receiver from the specified 
> values.
>  Generates an error if any of the values are out of range."
>
> ^ self _newDay: day monthNumber: 1 year: year.
>
> '
> dictionaries: GsSession currentSession symbolList
> category: 'Instance Creation'
> environmentId: 0.
>
>
> System commit.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20150810/b4ef5efe/attachment-0001.html>


More information about the Glass mailing list