> For months and days, the tricks are less trivial...
>
> Nicolas
>
>
> 2012/7/13 Sven Van Caekenberghe <
sven@beta9.be>:
>> Yeah, but sometimes a clever algorithm comes from a book, so to speak.
>>
>> Giving the variables long names, or the constants names, would not make that much difference, it would still be pretty hard to understand.
>>
>> ZTimestamp class>>withJdn: jdn dayMonthYearDo: block
>> � � � �"Return the value of executing block with the Gregorian Calender day, month and year as arguments,
>> � � � �as computed from my Julian Day Number, jdn.
>> � � � �See
http://en.wikipedia.org/wiki/Julian_date#Gregorian_calendar_from_Julian_day_number"
>>
>> � � � �| j g dg c dc b db a da y m d |
>> � � � �j := jdn + 32044.
>> � � � �g := j // 146097.
>> � � � �dg := j \\ 146097.
>> � � � �c := ((dg // 36524) + 1) * 3 // 4.
>> � � � �dc := dg - (c * 36524).
>> � � � �b := dc // 1461.
>> � � � �db := dc \\ 1461.
>> � � � �a := ((db // 365) + 1) * 3 // 4.
>> � � � �da := db - (a * 365).
>> � � � �y := (g * 400) + (c * 100) + (b * 4) + a.
>> � � � �m := ((((da * 5) + 308)) // 153) - 2.
>> � � � �d := da - ((m + 4) * 153 // 5) + 122.
>> � � � �^ block
>> � � � � � � � �value: d + 1
>> � � � � � � � �value: ((m + 2) \\ 12) + 1
>> � � � � � � � �value: (y - 4800 + ((m * 2) // 12))
>>
>> On 13 Jul 2012, at 17:53, Camillo Bruni wrote:
>>
>>> comments? decent variable names? no magic numbers?
>>> NOW you can find NONE of that in dayMonthYearDo!
>>>
>>>
>>> ==================================================================
>>> dayMonthYearDo: aBlock
>>> � � �"Evaluation the block with three arguments: day month, year."
>>>
>>> � � �| l n i j dd mm yyyy |
>>> � � �l := jdn + 68569.
>>> � � �n := 4 * l // 146097.
>>> � � �l := l - (146097 * n + 3 // 4).
>>> � � �i := 4000 * (l + 1) // 1461001.
>>> � � �l := l - (1461 * i // 4) + 31.
>>> � � �j := 80 * l // 2447.
>>> � � �dd := l - (2447 * j // 80).
>>> � � �l := j // 11.
>>> � � �mm := j + 2 - (12 * l).
>>> � � �yyyy := 100 * (n - 49) + i + l.
>>>
>>> � � �^ aBlock
>>> � � � � � � �value: dd
>>> � � � � � � �value: mm
>>> � � � � � � �value: yyyy.
>>>
>>> ==================================================================
>>>
>>> so can anyone explain me the magic numbers here??
>>>
>>
>>
>