Re: Time anomaly
Re: Time anomaly
- Subject: Re: Time anomaly
- From: Axel Luttgens <email@hidden>
- Date: Mon, 29 Oct 2012 18:57:58 +0100
Le 28 oct. 2012 à 22:44, Shane Stanley a écrit :
> [...]
> The whole idea of just changing the month is fraught.
> [...]
Agreed: expecting the ability to change a date's month (or more generally, any component of a date) to go beyond the construction of *valid* date objects is likely to quickly lead to ill-defined operations.
For example, let's consider:
set D to date "mardi 31 janvier 2012 00:00:00" -- ie 2012-01-31
Throughout the thread, it has (at least implicitly) been assumed that:
set month of D to 2
should do something "clever" such as, for example, add 31 days to D and yield:
date "vendredi 2 mars 2012 00:00:00" -- ie 2012-03-02
But why 31 days? Because january has 31 days?
(moreover, why is it then likely that nobody would suggest to add 62 days to D when setting D's month to 3 instead of 2? or to add 30 days when setting the month of 2012-04-31 to 5?)
And why not have considered another "clever" behavior in the first place, such as keeping the resulting date's within the bounds of the targeted month? And thus set D to:
date "mercredi 29 février 2012 00:00:00" -- ie 2012-02-29
Now, let's set the month back to 1; in the first case, one would get:
date "lundi 2 janvier 2012 00:00:00" -- ie 2012-01-02
and in the second case:
date "dimanche 29 janvier 2012 00:00:00" -- ie 2012-01-29
Clearly, neither is very satisfactory as soon as one considers the whole effect of:
set D to date "mardi 31 janvier 2012 00:00:00" -- ie 2012-01-31
set month of D to 2 -- expect AppleScript to provide some semantics
set month of D to 1 -- ask AppleScript to build a valid date object
Perhaps the really "clever" behavior would be to raise an error when the user tries to set a date's component to an invalid value.
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden