Context
Structure automatically the dates into a contract suitable format.
Metadata
{
"key": "nth-date",
"name": "Date as nth format",
"description": "Return day as nth format",
"developerEmail": "email@bryter.io",
"parameters": [
{
"name": "Date",
"type": "datetime",
"description": "The date to be formatted"
}
],
"result": {
"type": "text",
"description": "The nth formatted date"
}
}
Function
function main(input: string): string {
let inputDate = new Date(input)
let day = inputDate.getDate();
let month = inputDate.getMonth();
let year = inputDate.getFullYear();
let suffix = ['th', 'st', 'nd', 'rd'][(day % 100 > 10 && day % 100 < 14) || day % 10 > 3 ? 0 : day % 10];
let monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
return `the ${day}${suffix} day of ${monthNames[month]}, ${year}`;
}