Action Directory / Add date header

Install

Append a markdown header with the current date. Useful when writing a journal.

Shared by

Script

var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

function getOrdinal(x) {
  if (x == 1) {
    return 'st'
  } else if (x == 2) {
    return 'nd'
  } else if (x == 3) {
    return 'rd'
  } else {
    return 'th'
  }
}

var date = new Date()

var header = '# ' + DAYS[date.getDay()] + ' ' + MONTHS[date.getMonth()] + ' ' + date.getDate() + getOrdinal(date.getDate()) + ', ' + date.getFullYear();

editor.setText(editor.getText() + header);