After you install the workflow, just open it up and look at the `script-filter.php`. You'll see that I've included a library called "Alphred" that I wrote that makes writing workflows in PHP much, much easier, and so that is what controls the output for the script filter. Here, the library just easily creates the XML that Alfred reads.
The text to date functionality (for things like "now" or "tomorrow" or "+1 year") are built into PHP's date functionality. More specifically, they're built into the function `strtotime`, and so that does a lot of the heavy lifting.
The actual conversion from Arabic to Roman numerals is done by breaking the date string (31/3/1999) into an array and then using an `array_filter` (which just applies the same function to each part). So, all we needed was a single function to convert an Arabic number to a Roman numeral.
The function that does that is here:
function toRoman( $integer ) {
$output = '';
$conversion = [
'M' => 1000,
'CM'=> 900,
'D'=>500,
'CD'=>400,
'C'=>100,
'XC'=>90,
'L'=>50,
'XL'=>40,
'X'=>10,
'IX'=>9,
'V'=>5,
'IV'=>4,
'I'=>1
];
while ( $integer > 0 ) :
foreach ( $conversion as $roman => $arabic ) :
if ( $integer >= $arabic ) {
$integer -= $arabic;
$output .= $roman;
break;
}
endforeach;
endwhile;
return $output;
}
So, basically it takes an associative array that defines the translations between Arabic and Roman and then just uses two loops to modify the input value while constructing an output string. Each time it adds onto the string, it removes the equivalent value from the input integer and just keeps going until the integer reaches 0 and then returns the string.
Hopefully the explanation helps.
I did decide to make it a script filter rather than using an Applescript input box because it makes it easier to manipulate the values quickly and see the results.
I re-coded it in PHP and dropped it in a simple workflow that you can download here: https://www.dropbox.com/s/hihr5zl054wdq5u/Roman%20Date.alfredworkflow?dl=0.
It works as a script filter and uses PHP's date parser, so you can do things like "rd now" and "rd tomorrow" and "rd next friday" and "rd -1000 years" as well as "Oct 29 1993" or "10/29/1993".
Currently, if you press enter, it just displays it as large text.