Date format: Difference between revisions

→‎{{header|AppleScript}}: Re-restored the again-deleted non-hack solution, leaving in the non-representative and outdated hack by which it had been replaced for information.
(Undid revision 312192, which was submitted citing claims that appear to be unsubstantiated and did not demonstrably improve what it replaced. The code being reverted to is verified to be working and reliable on MacOS versions Yosemite to Big Sur.)
(→‎{{header|AppleScript}}: Re-restored the again-deleted non-hack solution, leaving in the non-representative and outdated hack by which it had been replaced for information.)
Line 471:
 
=={{header|AppleScript}}==
===Idiomatic===
 
This restores the legitimate code which has twice now been deleted by the poster of the hacks below. Explicitly: square brackets are not and have never been part of the AppleScript language and <tt>«class isot» as string</tt> is a hack someone discovered many years ago when it wasn't possible to coerce AppleScript month enums directly to integer and when AppleScript's <tt>string</tt> class used 8-bit characters. Back then, the coercion from <tt>string</tt> to <tt>«class isot»</tt> also worked. But this ended with the introduction of AppleScript 2.0 in 2007, when <tt>string</tt>, <tt>Unicode text</tt>, and <tt>text</tt> became synonymous terms for UTF-16 text. The ability to coerce from 8-bit text specifically to <tt>string</tt> was retained for compatibility with existing scripts and for reading non-Unicode text files. Other classes of text such <tt>C string</tt> were discontinued.
 
Whether or not they happen to work, to insist on posting code containing things which have never been part of the language without noting them as hacks, when they're entirely unnecessary, and deleting legitimate and effective code to make way for them, is seriously to misinform readers.
 
<lang applescript>set {year:y, month:m, day:d, weekday:w} to (current date)
 
tell (y * 10000 + m * 100 + d) as text to set shortFormat to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
set longFormat to (w as text) & (", " & m) & (space & d) & (", " & y)
 
return (shortFormat & linefeed & longFormat)</lang>
 
{{output}}
 
<lang applescript>"2020-10-28
Wednesday, October 28, 2020"</lang>
 
===Hack alternative===
AppleScript <code>date</code> objects are very simple to manipulate, provided one is familiar with the slightly unintuitive nature of how they should be handled in order to be robust and produce the desired result across all systems. Despite the official documentation claiming otherwise, AppleScript is not able to parse date strings that don’t strictly adhere to the date and time format strings specified in System Preferences—thus it is a setting that is specific to one’s system, and won’t naturally port. <br/> <br/>
 
Line 497 ⟶ 515:
Friday, September 11, 2020</pre>
 
===Functional===
 
Or, emphasising productivity and functional composition:
 
557

edits