Last active
December 24, 2015 22:11
-
-
Save NaanProphet/ab1154bb94076e04cde5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A helpful script to convert dates generated by IFTTT receipes like those from Maker into the ISO standard (that's used e.g. by MSQL). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- IFTTT convert date function. Call with string in format generated by | |
-- receipes, e.g. "December 24, 2015 at 05:25AM" | |
on toISOformat(iftttDate) | |
set theDate to date (iftttDate) | |
-- inspired by: http://henrysmac.org/blog/2014/1/4/formatting-short-dates-in-applescript.html | |
set y to text -4 thru -1 of ("0000" & (year of theDate)) | |
set m to text -2 thru -1 of ("00" & ((month of theDate) as integer)) | |
set d to text -2 thru -1 of ("00" & (day of theDate)) | |
-- special thanks to: http://alvinalexander.com/blog/post/mac-os-x/applescript-getting-current-time | |
set secFromMidnight to (time of theDate) | |
set h to text -2 thru -1 of ("00" & (secFromMidnight / 3600 as integer)) | |
set min to text -2 thru -1 of ("00" & ((secFromMidnight - 3600 * h) / 60 as integer)) | |
set s to text -2 thru -1 of ("00" & ((secFromMidnight - 3600 * h - 60 * min) as integer)) | |
return y & "-" & m & "-" & d & " " & h & ":" & min & ":" & s | |
end toISOformat | |
-- Demo | |
set iftttDate to "December 24, 2015 at 05:25AM" | |
set dateString to toISOformat(iftttDate) | |
--"2015-12-24 05:25:00" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To convert from an ISO string into an almost-IFTTT date string (IFTTT does not put a space before AM or PM), see the following gist, copied below for convenience.
link https://gist.github.com/RichardHyde/3386ac57b55455b71140