Mac OS X 10.5で、dateオブジェクトをISO日付形式に変換する«class isot»が動作しなくなっていました。
そして、もうこの機能はずっと動かなくなったままなのかと思っていましたが……現在動いていることに気づきました。
「AppleScript最新リファレンス」の初版執筆時には使えないことを確認していたので、OS X 10.11ぐらいの時代には動かなかったようです。
その後、手元の古いMacで確認してみたところ、
macOS 10.13:動く
macOS 10.14:動く
と、割と各バージョンで動いていることを確認。最新版のmacOS 15.5βでも動いています。
set testd to ((current date) as «class isot») as string
–> "2025-04-13T22:28:56"
★Click Here to Open This Script
目下、この機能はPiyomaru Softwareの電子書籍に掲載しているコマンドリファレンスに記載していませんが、記述を復活させるべきか悩ましいところです。
個人的には、Cocoaの機能を用いてISO日付フォーマットとの相互変換を行なっています。
AppleScript名:ISO8601日付文字列を生成 v2.scptd |
use AppleScript version "2.5" use scripting additions use framework "Foundation" set aDate to getDateInternational(2022, 10, 21, 0, 0, 0, "JPT") –―year, month, date, hour, minute, second, time zone abbreviation. –> date "2022年10月21日 金曜日 0:00:00" set bStr to retISO8601DateTimeString(aDate, "JPT") as string –> "2022-10-21T00:00:00+09:00" –NSDate -> ISO8601 Date & Time String on retISO8601DateTimeString(targDate, timeZoneAbbreviation) set theNSDateFormatter to current application’s NSDateFormatter’s alloc()’s init() theNSDateFormatter’s setDateFormat:"yyyy-MM-dd’T’HH:mm:ssZZZZZ" — Five zeds to get a colon in the time offset (except with GMT). theNSDateFormatter’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:(timeZoneAbbreviation)) return (theNSDateFormatter’s stringFromDate:targDate) as text end retISO8601DateTimeString –Make a GMT Date Object with parameters from a given time zone. on getDateInternational(aYear, aMonth, aDay, anHour, aMinute, aSecond, timeZoneAbbreviation) set theNSCalendar to current application’s NSCalendar’s currentCalendar() theNSCalendar’s setTimeZone:(current application’s NSTimeZone’s timeZoneWithAbbreviation:(timeZoneAbbreviation)) set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:aDay hour:anHour minute:aMinute |second|:aSecond nanosecond:0 return theDate as date end getDateInternational |