How to resolve the algorithm Date format step by step in the AppleScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Date format step by step in the AppleScript programming language
Table of Contents
Problem Statement
Display the current date in the formats of:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Date format step by step in the AppleScript programming language
Source code in the applescript programming language
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)
"2020-10-28
Wednesday, October 28, 2020"
tell (the current date)
set shortdate to text 1 thru 10 of (it as «class isot» as string)
set longdate to the contents of [its weekday, ", ", ¬
(its month), " ", day, ", ", year] as text
end tell
log the shortdate
log the longdate
-- iso8601Short :: Date -> String
on iso8601Short(dte)
text 1 thru 10 of iso8601Local(dte)
end iso8601Short
-- longDate :: Date -> String
on longDate(dte)
tell dte
"" & its weekday & ", " & its month & " " & its day & ", " & year
end tell
end longDate
---------------------------- TEST --------------------------
on run
unlines(apList({iso8601Short, longDate}, ¬
{current date}))
end run
-------------------------- GENERIC -------------------------
-- Each member of a list of functions applied to
-- each of a list of arguments, deriving a list of new values
-- apList (<*>) :: [(a -> b)] -> [a] -> [b]
on apList(fs, xs)
set lst to {}
repeat with f in fs
tell mReturn(contents of f)
repeat with x in xs
set end of lst to |λ|(contents of x)
end repeat
end tell
end repeat
return lst
end apList
-- iso8601Local :: Date -> String
on iso8601Local(dte)
(dte as «class isot» as string)
end iso8601Local
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
-- 2nd class handler function lifted into 1st class script wrapper.
if script is class of f then
f
else
script
property |λ| : f
end script
end if
end mReturn
-- unlines :: [String] -> String
on unlines(xs)
-- A single string formed by the intercalation
-- of a list of strings with the newline character.
set {dlm, my text item delimiters} to ¬
{my text item delimiters, linefeed}
set s to xs as text
set my text item delimiters to dlm
s
end unlines
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Wortel programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the Dart programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm Four is the number of letters in the ... step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Terminal control/Cursor positioning step by step in the Forth programming language