• 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: Counting & trashing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Counting & trashing


  • Subject: Re: Counting & trashing
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 14 Jul 2004 14:54:10 +0100

Nigel Smith wrote on Tue, 13 Jul 2004 16:56:37 +0100:

>On 13/7/04 15:04, "Axel Luttgens" <email@hidden> wrote:
>
>> From the ASLG:
>
>> More recent date and time utilities use a 64-bit signed value that
>> can represent dates from 30081 B.C. to 29940 A.D. However,
>> AppleScript currently will not handle dates before 1/1/1000
>
>Not strictly true, at least in OSX 10.3.x, though it doesn't handle BC
>particularly well:
>
>For example:
>
> log (date "Wednesday, January 1, 1000 0:00:00") - 364877 * days
> --> date "Monday, January 1, 0001 0:00:00"
>
> log (date "Wednesday, January 1, 1000 0:00:00") - 364878 * days
> --> date "Sunday, December 31, 0001 0:00:00"
>
>So you can get earlier dates than 1/1/1000 on the fly, just not hard-coded.
>I think... :-)

That's fun! :-)

on setYear(theDate, theYear)
copy theDate to theDate
if theYear > 0 then
set theDate's year to theYear
else if theYear < 0 then
-- Set theDate's year to a positive number that's a known
-- number of Gregorian cycles after the target year
set cycles to theYear div -400 + 1
set theDate's year to theYear + 400 * cycles + 1
-- Subtract that number of cycles (1.26227808E+10 seconds is 400
years)
set theDate to theDate - cycles * 1.26227808E+10
else
error "Silly bugger!"
end if
return theDate
end setYear

on dateAsString(theDate)
set dateStr to theDate as string
-- 5.04911232E+10 seconds is 2000 years
if theDate comes before (date "Monday, 1 January 2001 00:00:00") -
5.04911232E+10 then
set spc to (offset of ((theDate's year) as string) in dateStr) + 4
set dateStr to text 1 thru spc of dateStr & "BC" & text spc thru -1
of dateStr
end if
return dateStr
end dateAsString

-- Target date: 1 second before midnight, 31 December 9999 BC
set aDate to date "Friday, 31 December 2004 23:59:59"
set BCdate to setYear(aDate, -9999)
--> date "Tuesday, 31 December 9999 23:59:59" -- ie. 9999 BC

dateAsString(BCdate + 1)
--> "Wednesday, 1 January 9998 BC 00:00:00"

NG
_______________________________________________
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.


  • Prev by Date: Re: Counting & trashing
  • Next by Date: Re: User Permissions
  • Previous by thread: Re: Counting & trashing
  • Next by thread: Re: Counting & trashing
  • Index(es):
    • Date
    • Thread