Aerostack
build

datetime-duration-format Edge Function — Utilities

Utilities

Format a duration in milliseconds to a human-readable string with long, short, or compact styles.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function datetime-duration-format Format a duration in milliseconds to a human-readable string with long, short, or compact styles.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/datetime-duration-format
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "datetime-duration-format",
  args: {
    "ms": 42,
    "options": null
  }
})

datetime-duration-format — Format durations to human-readable strings

Convert a millisecond duration into "2 hours 30 minutes", "2h 30m", or "02:30:00" with configurable style and precision.


API

POST /api/datetime-duration-format

Request body

Field Type Required Default Description
ms number Duration in milliseconds
options.style string 'long' long, short, or compact
options.maxUnits number 2 Max time units to include
options.includeMs boolean false Include milliseconds

Styles

Style Example output
long 2 hours 30 minutes
short 2h 30m
compact 02:30:00

Success response (200)

{
  "success": true,
  "data": {
    "formatted": "2 hours 30 minutes",
    "parts": [
      { "unit": "hour", "value": 2 },
      { "unit": "minute", "value": 30 }
    ],
    "totalMs": 9000000
  }
}

Usage

Direct import
import { datetimeDurationFormat } from '@aerostack/functions/datetime-duration-format';

const elapsed = Date.now() - task.startedAt;
const result = datetimeDurationFormat({ ms: elapsed, options: { style: 'short' } });
console.log(result.formatted); // "1h 23m"

Use Cases

  • Displaying elapsed time for tasks, CI jobs, or video durations
  • Formatting countdown timers in UI components
  • Showing "time spent" in analytics or billing dashboards

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

datetime
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Utilities Functions

Browse Utilities Functions →

Frequently asked questions

What does the datetime-duration-format function do? +

datetime-duration-format is a serverless edge function for utilities automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the datetime-duration-format function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/datetime-duration-format ``` It will be live on Cloudflare Workers in seconds.

What runtime does datetime-duration-format use? +

datetime-duration-format runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the datetime-duration-format function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.