Universal handlers for setting time and date instead of using literals

Hello.

The heading says it all, and these are made due to Nigel Garvey.
These functions makes setting dates in scripts shareable by whatever localization others are using - and working wherever they are run or compiled.

One shouldn’t use these handlers before Friday, 15 October 1582 due to the fact that Apple Script does switch to the Julian Calendar which preceded the Gregorian which were initiated at Friday 15th of October 1582. The fact that AppleScript does that renders the algorithms not usable before that date, since there is 10 days amiss and the calculations before that date differs slightly.

There is a very interesting article about the calendar reform at WikipediA


-- setDate(1904,1,1,(current date ))
on setDate(intYear, intMonth, intDay, dateObject) -- thanks to Nigel Garvey
	tell dateObject
		set {day, year, its month, day} to {1, intYear, intMonth, intDay}
	end tell
	return dateObject
end setDate

on setTimeOfTheDay(int23Hour, int59Minuts, int59Seconds, dateObject) -- fixed by Nigel Garvey
	set time of dateObject to int23Hour * hours + int59Minuts * minutes + int59Seconds
	return dateObject
end setTimeOfTheDay

on setDateAndTime(intYear, intMonth, intDay, int23Hour, int59Minutes, int59Seconds) -- fixed by Nigel Garvey
	tell (current date)
		set {day, year, its month, day, time} to {1, intYear, intMonth, intDay, int23Hour * hours + int59Minutes * minutes + int59Seconds}
		return it
	end tell
end setDateAndTime


Glad to see it lists 2000 as a year in the last millennium. :slight_smile:

Hello.

Good they got that one right! (Anything else would be outrageous or time reckoning starts in the year 1 AD, and 1000 AD would have to be included to make it thousand years - one millennium. (1000 − 1 ) +1 = 1000

I’d be more happy if the article had reported that AppleScript had fixed the 1900 Bug! :slight_smile: (That extra day which aren’t there because there were no 29’th of february the year 1900. I guess that is no can do, because it will break everything which has been written earlier. -It puzzled me a little today. -And Excel2008 has suddenly started to accept date numbering starting at 1900. :smiley: (Ms Windows originated spreadsheet - which I managed to save at last, both manually and by scripting! ) Then I got weird dates, because Excel for Mac uses 1904 as the base for date numbering to avoid that bug.

Here is a good Microsoft page that describes the differences of the 1900 and 1904 date systems