About weekday of date
About weekday of date
- Subject: About weekday of date
- From: Emile Schwarz <email@hidden>
- Date: Wed, 05 Jul 2006 17:24:34 +0200
I am a bit surprised with both date atom constants: Month and WeekDay.
They are defined as "constants" (see the Language Reference pdf), but
are not Read/Only! No, you cannot replace July by what you want to put
there (December), but you can set the Month to 12 for December) and get
December when you ask the date... Same (more or less) apply to the
WeekDay "Constant".
So, IMHO, the use of "constant" to define these Properties is a language
abuse; it is more a variant than a constant (but I am not sure that this
is not another language abuse...).
The following code works fine in Mac OS X 10.4.7 (French):
-- Get today's date
set theDate to current date -- the date is July 4, 2006
-- Set the month Property with a number (1 ... 12)
set month of theDate to 2 -- here, it will be February
-- Return the values
return {month of theDate}
returns: {February}
The other code works fine too:
-- Get today's date
set theDate to current date
-- Get the month number (1 ... 12) from the month property
set monthNbr to (month of theDate as integer)
-- Return the values
return {month of theDate, monthNbr}
returns: {July, 7}
So, I was asking myself: "What about the WeekDay property ?". The answer
is... mixed. The following code works:
-- Get today's date
set theDate to current date -- Today is Tuesday, July 4, 2006
-- Get the week day number (1 ... 6) from the WeekDay property
set dayNbr to (weekday of theDate as integer)
-- Return the values
return {weekday of theDate, dayNbr}
Returns: {Tuesday, 3}
but, for some reason, the following code do not works for the WeekDay:
-- Get today's date
set theDate to current date -- the date is July 4, 2006
-- Set the weekday Property with a number (1 ... 28, 29, 30 or 31 ?)
set weekday of theDate to 2 -- "second day of the week" ?
-- Return the value
return {weekday of theDate}
I get an error message for the set weekday line... [Impossible de rendre
2 dans le type attendu]
I feel that weekday is not set to do that; it is not a Week Of The Day
Property.
AND WHAT IS WEIRD is that:
-- Get today's date
set theDate to current date -- Today is Tuesday, July 4, 2006
-- Set the weekday Property with a number (1 ... 28, 29, 30 or 31 ?)
set weekday of theDate to Monday -- "second day of the week" ?
-- Return the value
return {weekday of theDate}
No error, returns: {Tuesday}.
at last, the following works:
set theDate to current date
set day of theDate to 2
return weekday of theDate
I get Sunday which is correct!
Go figure Charles !
Sweet little sixteen AppleScript (is her birth year 1990 ?) is not old
enough to take care of that !
[a bit of a shame]
Emile
--
I put the reasoning, the way I get the result (why I used weekday the
way I use it) so you - the reader - understand why I wanted to use the
property the way I use it and why I think there is a trouble there.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden