Last active
October 25, 2018 06:41
-
-
Save fanaugen/1852783 to your computer and use it in GitHub Desktop.
simple date parser
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
(* | |
* Example of a simple string-to-date parser. | |
* Uses AppleScript's text item delimiters to split the input string | |
*) | |
set tid to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to {"-", "T", ":", "Z"} | |
set dateString to "2011-12-23T08:00:00Z" -- what's Z for? | |
set pieces to text items of dateString | |
set d to current date | |
set {year of d, month of d, day of d, time of d} to ¬ | |
{item 1 of pieces, item 2 of pieces, item 3 of pieces, ¬ | |
((item 4 of pieces) as number) * hours + ¬ | |
((item 5 of pieces) as number) * minutes + ¬ | |
((item 6 of pieces) as number)} | |
d -- is now set to December 23, 2011, 08:00:00 | |
set AppleScript's text item delimiters to tid -- because I'm a well-behaved script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment