• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A few questions about dates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A few questions about dates


  • Subject: Re: A few questions about dates
  • From: kai <email@hidden>
  • Date: Tue, 29 Aug 2006 02:36:32 +0100


On 27 Aug 2006, at 21:56, Mark J. Reed wrote:

None of which addresses Sweth's question about what AppleScript does.

The simplest way to convert a date to seconds is obviously to compare it with the aforementioned Mac epoch. But just for fun, the following is an attempt (albeit one that relies on a bit of a hack) to extract the seconds without such a comparison - by parsing the value of the date class's 64 bit integer:


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

on date_as_seconds(d)
	tell {{d:d}} as text to set l to {text -8 thru -5, text -4 thru -1}
	repeat with r in l
		set v to 0
		repeat with i in r
			set v to 256 * v + (ASCII number i)
		end repeat
		set r's contents to v
	end repeat
	set {g, s, f} to l & 4.294967296E+9
	if g > 59 or g is 59 and s > 2.082075135E+9 then set g to g - f
	f * g + s
end date_as_seconds

set |date| to current date (* or some other date *)
set secs to date_as_seconds(|date|)
set epoch to |date| - secs
{secs:secs, |date|:|date|, epoch:epoch}

--> {secs:3.239663754E+9, |date|:date "Tuesday, August 29, 2006 02:35:54", epoch:date "Friday, January 1, 1904 00:00:00"}

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

---
kai


_______________________________________________ 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
References: 
 >A few questions about dates (From: Sweth Chandramouli <email@hidden>)
 >Re: A few questions about dates (From: Mat <email@hidden>)
 >Re: A few questions about dates (From: Sweth Chandramouli <email@hidden>)
 >Re: A few questions about dates (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Dialog from script application displays raw codes (was: no subject)
  • Next by Date: Re: Dialog from script application displays raw codes
  • Previous by thread: Re: A few questions about dates
  • Next by thread: Re: A few questions about dates
  • Index(es):
    • Date
    • Thread