Files
plainleaf/Library/Std/Date.md
T
Zef Hemel be86e53398 Implement new slash commands and enhance editor functionality
- Added slash commands for inserting today's, yesterday's, and tomorrow's dates.
- Introduced new admonition commands for notes and warnings.
- Implemented a table command for quick table insertion.
- Enhanced the `insertAtCursor` function to support a cursor placeholder option.
- Updated `getSelection` to return the selected text along with cursor positions.
- Added a new widget function to display linked tasks in the editor.
2025-03-30 13:03:57 +02:00

857 B

#meta

Date and time APIs

-- priority: 10

local DAY_SECONDS = 60 * 60 * 24

date = {
  date_format = "%Y-%m-%d",
  time_format = "%H:%M:%S",
}

function date.today()
  return os.date(date.date_format)
end

function date.tomorrow()
  return os.date(date.date_format, os.time() + DAY_SECONDS)
end

function date.yesterday()
  return os.date(date.date_format, os.time() - DAY_SECONDS)
end

function date.time()
  return os.date(date.time_format)
end

slashcommand.define {
  name = "today",
  run = function()
    editor.insertAtCursor(date.today())
  end
}

slashcommand.define {
  name = "yesterday",
  run = function()
    editor.insertAtCursor(date.yesterday())
  end
}

slashcommand.define {
  name = "tomorrow",
  run = function()
    editor.insertAtCursor(date.tomorrow())
  end
}

Examples

Today: ${date.today()} and ${date.time()}