peteruithoven/duration

Zed extension to calculate duration

★ 0Forks 0RustGitHub ↗Compare

README

Duration for Zed

Duration is a Zed extension that adds code actions for calculating time ranges in Markdown and Plain Text buffers.

Current scope

  • Markdown and Plain Text only
  • Code actions for the current line or current selection
  • Time-range syntax using -
  • Pure Rust time parsing and duration math with no external conversion dependency

How it works

Place the cursor on a line such as 10:00 - 12:00, 14:00 - 17:00, or 23:00 - 2:00, then open code actions in Zed and choose one of these actions:

  • Calculate duration
  • Calculate duration on line

The extension rewrites the text to include the result, for example 10:00 - 12:30 = 2.5 hours.

Local development

This repository pins Rust 1.94.0 via rust-toolchain.toml for consistent local builds. The Zed extension itself is compiled for wasm32-wasip2, so make sure that target is installed too.

  1. Install the language server binary on your PATH:

    cargo install --path language-server
  2. Install the Rust target Zed needs for compiling the extension:

    rustup target add wasm32-wasip2 --toolchain 1.94.0
  3. Install this repository as a dev extension in Zed with zed: install dev extension.

  4. Test from a saved Markdown or Plain Text file.

Supported v1 input examples:

  • 10:00 - 12:00 = 2 hours
  • 14:00 - 17:00 = 3 hours
  • 23:00 - 2:00 = 3 hours
  • 9:00 - 11:15 = 2.25 hours

Build checks

cargo check -p duration
cargo test -p duration-language-server

Notes

  • The outer parser is intentionally small and only owns the time-range syntax on each line.
  • Cross-midnight ranges are treated as next-day durations when the end time is earlier than the start time.
  • v1 only supports 24-hour H:MM and HH:MM input.

Contributors

peteruithoven

Issues