• 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: WBC date library [was Re: Leopard Date Bugs]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WBC date library [was Re: Leopard Date Bugs]


  • Subject: Re: WBC date library [was Re: Leopard Date Bugs]
  • From: Takaaki Naganoya <email@hidden>
  • Date: Mon, 19 Nov 2007 13:55:11 +0900

On 2007/11/19, at 13:12, Loren Ryter wrote:

When I make the internationalization-aware date object creating
routine in AppleScript, it needs hundreds of lines.
Yes I did :-).


Care to share what you're talking about?

About the hundreds of AS code ? When I wrote it I didn't know about "class <<isot>>".
I think the my code is not far from your routine.


Well, here is my library I worked up after this that I'm pretty sure works
on all systems. I'd be interested to know it works on Naganoya- San's "true"
(not iwayuru ;-) Japanese system...

I tested your routine in my true Japanese environment.

// Tiger
--> {date "2007年 11月 19日 月曜日 0:00:00 AM", date "2007年 11月 19日 月曜日 3:49:03 AM", "ISO error", date "1000年 1月 1 日 水曜日 0:00:00 AM", date "1000年 1月 1日 水曜日 0:00:00 AM", date "2000年 1月 1日 土曜日 0:00:00 AM", date "2000年 1月 1日 土曜日 0:00:00 AM", "1000年 1月 1日 水曜日 0:00:00 AM", "1000年 1月 1日 水曜日", "2000年 1月 1日 土曜日 0:00:00 AM", "2000年 1月 1日 土曜日 0:00:00 AM"}


//Leoaprd
--> {date "2007年 11月 19日 月曜日 0:00:00 AM", date "2007年 11月 19日 月曜日 3:49:03 AM", "ISO error", date "1000年 1月 1 日 水曜日 0:00:00 AM", date "1000年 1月 1日 水曜日 0:00:00 AM", date "2000年 1月 1日 土曜日 0:00:00 AM", date "2000年 1月 1日 土曜日 0:00:00 AM", "1000年 1月 1日 水曜日 0:00:00 AM", "0999年12月27日水曜日", "2000年 1月 1日 土曜日 0:00:00 AM", "2000年 1月 1日 土曜日 0:00:00 AM"}


年:year
月:month
日:day

日曜日 = Sunday
月曜日 = Monday
火曜日 = Tuesday
水曜日 = Wednesday
木曜日 = Thursday
金曜日 = Friday
土曜日 = Saturday

--
Takaaki Naganoya
Piyomaru Software
http://piyo.piyocast.com
email@hidden

PiyoCast Web (Podcasting with Music!)
http://www.piyocast.com

(*
WBC's dateLib
Designed specifically to avoid whenever possible converting dates to strings
and back
Because this is broken on Leopard's international system
(c) 2007 Wooden Brain Concepts
http://www.woodenbrain.com
*)


--force recompile while changing international settings
set a to 5

set y1k_ds to "1/1/1000"
set y2k_ds to "1/1/2000"
set cd to current date

set today_midnight to my midnight(cd)
try
set y1k_isod to ((date y1k_ds) as «class isot») as date
on error
set y1k_isod to "ISO error"
end try
set y1k_dummy to my dummydate_year(1000)
set y1k_dummy2 to my pluck_date(y1k_ds)
set y2k_dummy to my dummydate_full(1, 1, 2000, 0, 0, 0)
set y2k_dummy2 to my dummydate_string(y2k_ds)
set old_date to my dummydate_full(1, 1, 2000, 3, 49, 3)
set time_of_old_date_but_today to my that_time_on_this_date (old_date, cd)


return {today_midnight, time_of_old_date_but_today, y1k_isod, y1k_dummy,
y1k_dummy2, y2k_dummy, y2k_dummy2, y1k_dummy as Unicode text, date string of
y1k_dummy2, y2k_dummy as string, y2k_dummy2 as string}



on midnight(d)
-- returns the midnight date of the given date object
set tmpdate to (d) - ((hours of (d)) * hours) - ((minutes of (d)) *
minutes) - (seconds of (d))
return tmpdate
end midnight


on dummydate_year(tyr)
    -- returns Jan 1 on the year given as date
    set tmpdate to current date
    set year of tmpdate to tyr
    set month of tmpdate to 1
    set day of tmpdate to 1
    set hours of tmpdate to 0
    set minutes of tmpdate to 0
    set seconds of tmpdate to 0
    return tmpdate
end dummydate_year


on dummydate_mdy(tmo, tdy, tyr) -- returns the midnight time on the month, day, year given set tmpdate to current date set year of tmpdate to tyr set month of tmpdate to tmo set day of tmpdate to tdy set hours of tmpdate to 0 set minutes of tmpdate to 0 set seconds of tmpdate to 0 return tmpdate end dummydate_mdy


on dummydate_full(tmo, tdy, tyr, thr, tmin, tsec)
-- returns the date on the month, day, year, hours, mins, secs given
set tmpdate to current date
set year of tmpdate to tyr
set month of tmpdate to tmo
set day of tmpdate to tdy
set hours of tmpdate to thr
set minutes of tmpdate to tmin
set seconds of tmpdate to tsec
return tmpdate
end dummydate_full


on dummydate_string(ts)
-- returns a date from a string as "1/1/2000" or "1-1-2000"; on error
returns current date
set ts to my replace(ts, "-", "/")
set ods to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set tmpdate to current date
try
set year of tmpdate to (text item 3 of ts) as integer
set month of tmpdate to (text item 1 of ts) as integer
set day of tmpdate to (text item 2 of ts) as integer
set hours of tmpdate to 0
set minutes of tmpdate to 0
set seconds of tmpdate to 0
on error
set tmpdate to current date
end try
set AppleScript's text item delimiters to ods
return tmpdate
end dummydate_string


on pluck_date_string(ts)
    -- returns the sub-string of a long string with the first "word"
containing "/" or "-"; or "" if not found
    -- ie returns "1/1/2000" if given "Mon 1-1-2000 3:39:39 PM"
    set ds to ""
    set ts to my replace(ts, "-", "/")
    set ods to AppleScript's text item delimiters
    set AppleScript's text item delimiters to " "
    set ct to (count text items of ts)
    if ct > 0 then
        repeat with i from 1 to ct
            set wd to item i of (text items of ts)
            if wd contains "/" then
                set ds to wd
                exit repeat
            end if
        end repeat
    end if
    set AppleScript's text item delimiters to ods
    if ds ≠ "" then
        return (ds as string)
    else
        return ""
    end if
end pluck_date_string

on pluck_date(ts)
-- combines above two; give a string with a date word in it, returns
date (at midnight, no time) rather than a string
return (my dummydate_string(my pluck_date_string(ts)))
end pluck_date


on that_time_on_this_date(that_time, this_date)
-- first date object given is time of concern, second date object is
another date; returns first date's time on second date's date
-- ie, if second parameter is Current date, then it will return the
first parameter's time but today
set tmpdate to current date
set year of tmpdate to year of this_date
set month of tmpdate to month of this_date
set day of tmpdate to day of this_date
set hours of tmpdate to (hours of that_time)
set minutes of tmpdate to (minutes of that_time)
set seconds of tmpdate to (seconds of that_time)
return tmpdate
end that_time_on_this_date


on hms_on_this_date(hr, mn, sc, this_date)
-- returns given time in hours, minutes, seconds on given date's date
set tmpdate to current date
set year of tmpdate to year of this_date
set month of tmpdate to month of this_date
set day of tmpdate to day of this_date
set hours of tmpdate to hr
set minutes of tmpdate to mn
set seconds of tmpdate to sc
return tmpdate
end hms_on_this_date


on replace(sourcetext, search, replacement)
    set oldDelim to AppleScript's text item delimiters
    set AppleScript's text item delimiters to the search
    set the textItemList to every text item of the sourcetext
    set AppleScript's text item delimiters to the replacement
    set the output to the textItemList as string
    set AppleScript's text item delimiters to oldDelim
    return output
end replace


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
mark.nu
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden





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

This email sent to email@hidden
References: 
 >WBC date library [was Re: Leopard Date Bugs] (From: Loren Ryter <email@hidden>)

  • Prev by Date: Re: Did 10.4.11 kill applescript?
  • Next by Date: Re: Adobe Illustrator CS3 'save' command appears to be buggy
  • Previous by thread: WBC date library [was Re: Leopard Date Bugs]
  • Next by thread: Re: Leopard Date Bugs
  • Index(es):
    • Date
    • Thread