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: getting the date



On Dec 30, 2003, at 5:22 PM, Walter Ian Kaye wrote:

At 09:32p +0000 12/30/2003, Nigel Garvey didst inscribe upon an electronic papyrus:

Here we go again:

set theDate to (current date)
set {year:y, day:d} to theDate
copy theDate to b
set b's month to January

text 3 thru 8 of ((y * 10000 + (b - 2500000 - theDate) div -2500000 *
100 + d) as string)

OK, I give. Can you please *explain* that 2500000 arithmetic?
There has to be a science behind it...

I'll take a stab at it. He's stuffing a date into a number. Each place in the number will get converted to a character in a text string. The positions in the resulting string will end up like this:

y y y y m m d d
1 2 3 4 5 6 7 8

When he takes text 3 thru 8 of the resulting string he will end up with the format: yymmdd

Here's the breakdown:

y * 10000

Puts years so that they go into positions 1 through 4 (4 from the end)

(b - 2500000 - theDate) div -2500000 * 100

is pretty much equivalent to

((b - theDate) div -2500000 + 1 ) * 100

Which takes the difference (in seconds) between the current date and and the the same day in January, divides that by 289 days (in seconds) and adds a month. This gives you the current month, roughly. This will probably work fine but I'd worry about it being correct under all circumstances. The "* 100" part is to put that month into positions 5 through 6 (2 from the end)

+ d

This adds the day to the end of the number he is building, it goes in positions 7 through 8 (right on the end)

The number that is built using this method is 20031230 so he makes that into a string "20031230" and lops off the first 2 characters to get "031230".

- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: getting the date (From: Nigel Garvey <email@hidden>)
 >Re: getting the date (From: Walter Ian Kaye <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.