Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Days and hours




On 20 Oct 2005, at 13:46, Nigel Garvey wrote:

<Splutter!> Characteristically terse, Mr. E! Only three variables in
eighteen lines! It's interesting that that first line needs the 'my' to
avoid an error. Presumably it's because strings can't handle dates.

Quite. Of course, if anyone's into using atypical parent properties, it might be safer to refer to AppleScript, rather than to the script itself:


---------------

property parent : application "Finder" (* Or: System Events, Mail, Safari, TextEdit, etc. *)
tell "1 1 1" to tell (my date it) to it
--> date "Monday, January 1, 2001 00:00:00" (OMM)


---------------

property parent : 3 (* Or: {"a", "b"}, October, pi, etc. *)
tell "1 1 1" to tell (my date it) to it
--> error number -1728 (errAENoSuchObject): Can't get date "1 1 1" of [whatever].


---------------

property parent : 3 (* Or: {"a", "b"}, October, pi, etc. *)
tell "1 1 1" to tell (AppleScript's date it) to it
--> date "Monday, January 1, 2001 00:00:00" (OMM)

---------------

You'd no doubt enjoy this too:

  script
  end
  tell "1 1 1" to tell result's date it
[etc.]

LOL!

And finally, for kai fans everywhere, here's a complete version with no
variables at all. :-)

ROTFL! (Personally, I'm a long-standing NG fan...) :-)

Excellent stuff. I suppose that, in the interests of creating this brave new variable-less society (passed parameters and repeat loop references aside), we might also attempt something similar with respect to the original part of the question. The following assumes that the required year is the current one:

-------------

on requiredMonth()
    tell "1 1 1" to tell (my date it) + 24 * days to tell {it + ¬
        7 * days, date string's words & "1", 1} to considering case
        set end to beginning's date string's words
        repeat while end's item item 3 is in item 2
            set item 3 to (item 3) + 1
        end repeat
        set end to {item 2's item item 3, end's item item 3}
        repeat 10 times
            set beginning's day to 32
            set end's end to beginning's date string's word item 3
        end repeat
        its end
    end considering
    tell (choose from list result) to if it is false then
        error number -128
    else
        my date beginning's month
    end if
end requiredMonth

on totalHours for m from h
    tell (current date)
        set its month to m
        set day to 28
        tell {it + 4 * days, its weekday as integer, ((h's item ¬
            1) + (h's item 2) + (h's item 3) + (h's item 4) + ¬
            (h's item 5) + (h's item 6) + (h's item 7)) * 4}
            repeat with d from item 2 to (item 2) + ((beginning - ¬
                (beginning's day) * days)'s day) - 29
                set last item to end + (h's item (d mod 7 + 1))
            end repeat
            its end
        end tell
    end tell
end totalHours

totalHours for requiredMonth() from {0, 2.5, 2.5, 2, 0, 2, 0}

-------------

;-)

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden
References: 
 >Re: Days and hours (From: "Nigel Garvey" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.