iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📅

I Created a VS Code Extension to Insert Dates Using Keywords like 'tomorrow' or 'next monday'

に公開

Have you ever wanted to quickly insert a date in VS Code?

I have. Today's date is fine, but I often use things like "tomorrow," "next Monday," "next Friday," "N days later," and "the first day of next month."

I looked for VS Code extensions, but couldn't find one that felt right to me.

So, thinking "My niche needs might only be answerable by myself," I created and published my own VS Code extension.

Demo

Here is a demo of the implemented features.

Insert dates like today, tomorrow, or next Monday

Demo

Insert date N (days/weeks/months/years) later

N after Example

Usage

Installation

First, install the following extension.

https://marketplace.visualstudio.com/items?itemName=bun913.easy-date-insert

Specifying the Format

You can specify the date format by opening the settings with cmd + , and searching for easyDateInsert.format. (Currently, only predefined formats are supported, and the default value is YYYY-MM-DD.)

Format

Insert dates using specific keywords

On Mac, you can open the command palette with cmd+shift+p and call the following commands to insert a date.

Tomorrow Example

This example shows entering up to tomorrow, but you can also call dates like "next Monday" by typing monday, etc.

  • Running the Easy Date Insert: Today command inserts today's date.
    • It is likely to appear as a suggestion quickly after typing just today.
  • Running the Easy Date Insert: Tomorrow command inserts tomorrow's date.
  • Running the Easy Date Insert: Next Friday command inserts the next Friday's date.
  • Running the Easy Date Insert: Next Monday command inserts the next Monday's date.
  • Running the Easy Date Insert: Last of Month command inserts the date of the last day of the current month.

Insert date N (days/weeks/months/years) later

N after Example

  • You can insert a date by running the Easy Date Insert: Insert Date command.
    • For example, after entering 3 and selecting day, you can insert the date for 3 days later.
    • After entering 2 and selecting week, you can insert the date for 2 weeks later.

TIPS: Keybinding Settings

For those who find it tedious to open the command palette with cmd+shift+p every time, you can insert dates more easily by setting keybindings.

For example, the following shows a setup where cmd+shift+D inserts the date for tomorrow. (The format is set to YYYY年MM月DD日.)

shortcut image

{
  // example for tommorow command
  {
    "key": "cmd+shift+d",
    "command": "easy-date-insert.tomorrow"
    "when": "editorTextFocus"
  }
  // You can set another command in the same way.
}

Background

I want to be able to write as many documents as possible in the same way on any PC.

Ideally, in a format that can be version-controlled using a familiar editor.

Thanks to GistPad, which I learned about in the blog below, my progress on blog post notes and technical book notes has improved.

https://zenn.dev/voluntas/scraps/7721c58680931b

  • Can enter documents in a familiar editor
  • Can enter documents in Markdown format
  • Can enter documents with Vim keybindings
  • Version control possible with Git

This is sufficient for most documents, but when I try to manage ToDos as well, I frequently need to enter information about "by when" it should be done.

Todo

If it were just today's date, I could manage with shortcuts or other extensions, but I wanted to quickly enter dates like "next Monday" or "next Friday," which are often used in ToDos.

https://jsstudy.hatenablog.com/entry/How-to-set-a-shortcut-to-enter-the-current-date-and-time-in-Visual-Studio-Code

So, I created this extension myself.

Summary

  • I created my own VS Code extension to satisfy my niche needs.
  • Thoughts
    • For such a simple feature, I was able to build it in just a few hours.
    • However, saving even a single second in daily date entry is quite significant.
    • If I can't find a good extension in the future, I'll consider making it myself.
  • Future Tasks
    • It might be a good idea to allow free-form format input.
    • There are some commands I might not use right now, and there are probably more commands I'd want.
      • It might be good to have all "Next [Day of the week]" options.
    • I'll add convenient commands as I find them through use.

Here is the repository. If you find any bugs or have points for improvement, please feel free to submit an Issue or Pull Request.

https://github.com/bun913/vscode-extension-easy-date-insert

References

I referred to the following articles while creating the extension:

https://dev.classmethod.jp/articles/easy-vs-code-extension-development/

https://code.visualstudio.com/api/get-started/your-first-extension

Also, I referred to the following article before publishing the extension:

https://qiita.com/yusu79/items/44520c4c67864b0bb3e9

Both were very clear articles with plenty of photos.
Thank you very much.

GitHubで編集を提案

Discussion