# [etoys-dev] Fwd: Julian dates

Bert Freudenberg bert at freudenbergs.de
Mon Jun 25 08:11:23 EDT 2012

```Maybe someone here wants to tackle this ...

- Bert -

Begin forwarded message:

> From: Bert Freudenberg <bert at freudenbergs.de>
> Subject: [squeak-dev] Julian dates
> Date: 25. Juni 2012 13:54:08 MESZ
> To: The general-purpose Squeak developers list <squeak-dev at lists.squeakfoundation.org>
> Reply-To: The general-purpose Squeak developers list <squeak-dev at lists.squeakfoundation.org>
>
> Squeak dates are based on the Julian Day Number:
>
> 	http://en.wikipedia.org/wiki/Julian_day
>
> This is defined as the number of days since January 1, 4713 BC in the Julian proleptic calendar.
>
> Now, to my surprise,
>
> 	Date julianDayNumber: 0
>
>
> 	24 November -4713
>
>
> 	1 January -4712
>
> Digging into this it is because Squeak uses the Fliegel-Van Flandern algorithm, which always results in a Gregorian date. Even for dates before the Gregorian calendar was introduced. If we were to use the algorithm by Jean Meeus, dates before 15 Nov 1582 would be converted to a Julian date.
>
> Meeus is a floating point algorithm which we may not want to use. I added a correction to our method similar to Meeus, but converted to integers. So this is a mixed one, pasted below.
>
> Would anyone be opposed to adopt this? The behavior will be unchanged for all dates more recent than 15 Nov 1582.
>
> If so, we also would need an adjustment for the reverse part in year:month:day:hour:minute:second:nanoSecond:offset:. This is already covered by a test using the year 1200 BC (DateAndTimeTest>>testFromString). Anybody up for making that work?
>
> I stumbled upon this because Etoys 5 has a new Calendar object which exposes the Julian Day Number, and setting it to 0 is a very convenient way of explaining what that means.
>
> Thanks!
>
> - Bert -
>
> dayMonthYearDo: aBlock
> 	"Evaluate the block with three arguments: day month, year.
> 	Uses the Fliegel-Van Flandern algorithm, with adjustment for dates before 15 Nov 1582 as given by Jean Meeus.
> 	See http://mathforum.org/library/drmath/view/51907.html"
>
> 	| a l n i j dd mm yyyy |
> 	a := jdn.
> 	a < 2299161 ifTrue: [ | alpha |
> 		alpha := (jdn * 4 - 7468865) // 146097.
> 		a := jdn - 1 - alpha + (alpha // 4)].
> 	l := a + 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
>
>

```