Re: About weekday of date
Re: About weekday of date
- Subject: Re: About weekday of date
- From: deivy petrescu <email@hidden>
- Date: Wed, 5 Jul 2006 21:59:28 -0400
On Jul 5, 2006, at 11:24, Emile Schwarz wrote:
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...).
No it is not!
Both are constants:
set July to 1
set Monday to "today"
produces an error as they should.
On the other hand
set x to July
set j to Monday
are fine!(Change July to 54 or Monday to 123. Get that they both are
constants?)
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" ?
Well, what you think it is not what you write...
get weekday as number coerces the weekday to number (1-7) however you
can not do the coercion the other way around
2 as weekday
3 as month
-- 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}.
Basically here you get today ; July 4 2006. It checks and see it is
a Tuesday. So you get Tuesday July 4 2006.
Now you tell it to make it a Monday. It won't because it sees it as
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!
Here you tell it get today's date: July 4 2006, it checks, it is a
Tuesday.
Now you tell it set the date to July 2 2006, it checks, and it gets
the weekday: Sunday.
Go figure Charles !
I do not know about Charles, but, I hope it is clearer to you!
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.
_______________________________________________
Deivy
_______________________________________________
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