datetime-duration-format Edge Function — Utilities
UtilitiesFormat a duration in milliseconds to a human-readable string with long, short, or compact styles.
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.
npx aerostack add navin/datetime-duration-format Use with AI Assistants
MCPConnect 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.
{
"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({
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
Tags
Publisher
@navin verified
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 →datetime-add
by @navin
Add or subtract a duration from a date, supporting units from milliseconds to years with correct month-end handling.
datetime-business-hours
by @navin
Check if a datetime falls within business hours and return the next opening time.
datetime-diff
by @navin
Calculate the difference between two dates in specified units (ms, seconds, minutes, hours, days, weeks, months, years).
datetime-format
by @navin
Format a date to a string using format tokens like YYYY-MM-DD HH:mm:ss with optional timezone support.
datetime-parse
by @navin
Parse a date string or unix timestamp to a normalised Unix millisecond timestamp and ISO string.
datetime-relative
by @navin
Format a date as a relative time string like '2 hours ago' or 'in 3 days' using Intl.RelativeTimeFormat.
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.