datex
Insert the date, day of the week can be calculated a few days ago.

Script key: Insert the date, day of the week can be calculated a few days ago.

Posted by robraft-at-gmail-dot-com

Install

Details

Label datex
Voice Over Insert the date, day of the week can be calculated a few days ago.
Script
// based on work from @feelingplace. Thank You!!
// Please start by selecting the number of days before or numbers.

var daysB4   = getSelectedText();
var addDays  = -daysB4;
var now      = new Date();
var nowYear  = now.getFullYear();
var nowMonth = now.getMonth();
var nowDay   = now.getDate();

function calcDate(year, month, day, addDays) {
  dt = new Date(year, month, day);
  baseSec = dt.getTime();
  addSec = addDays * 86400000;
  targetSec = baseSec + addSec;
  dt.setTime(targetSec);
  return dt;
}

var b4Date = calcDate(nowYear, nowMonth, nowDay, addDays);

var DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var MONS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

var dayName = DAYS[b4Date.getDay()];
var month   = MONS[b4Date.getMonth()];
var day     = b4Date.getDate();
var year    = b4Date.getFullYear();

var buf = dayName + " " + day + "-" + month + "-" + year;
// var buf = beforeDate.getFullYear() + "年" + (beforeDate.getMonth() + 1) + "月" + beforeDate.getDate() + "日(" + dayOfWeek + ")";

var selRange = getSelectedRange();
setSelectedText(buf);
setSelectedRange(selRange[0]+buf.length, 0);
// .eof.

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus