Action

/today

Posted by j10, Last update over 4 years ago

Inserts today’s date formatted for Roam Research.

For example, today is [[March 27th, 2020]].

Steps

  • script

    function insertTextPosAtEnd(p_strText) {
    	editor.setSelectedText(p_strText);
    	editor.setSelectedRange(editor.getSelectedRange()[0] + editor.getSelectedRange()[1], 0);
    	editor.activate();
    }
    
    function getOrdinalNum(n) {
      return n + (n > 0 ? ['th', 'st', 'nd', 'rd'][(n > 3 && n < 21) || n % 10 > 3 ? 0 : n % 10] : '');
    }
    
    const monthNames = ["January", "February", "March", "April", "May", "June",
      "July", "August", "September", "October", "November", "December"
    ];
    
    var today = new Date();
    var m = monthNames[today.getMonth()];
    var d = getOrdinalNum(today.getDate());
    var y = today.getFullYear();
    
    var ordinalToday = "[[" + m + " " + d + ", " + y + "]]";
    insertTextPosAtEnd(ordinalToday);
    draft.update();

Options

  • After Success Nothing
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.