Aerostack
build

datetime-relative Edge Function — Utilities

Utilities

Format a date as a relative time string like '2 hours ago' or 'in 3 days' using Intl.RelativeTimeFormat.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function datetime-relative Format a date as a relative time string like '2 hours ago' or 'in 3 days' using Intl.RelativeTimeFormat.. 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-relative
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-relative",
  args: {
    "date": null,
    "options": null
  }
})

datetime-relative — Format dates as relative time strings

Generate human-friendly relative time strings like "2 hours ago" or "in 3 days" using native Intl.RelativeTimeFormat.


API

POST /api/datetime-relative

Request body

Field Type Required Default Description
date string | number Date to format
options.now string | number Date.now() Reference time
options.locale string 'en' BCP47 locale
options.style string 'long' long, short, or narrow

Success response (200)

{
  "success": true,
  "data": {
    "relative": "2 hours ago",
    "diffMs": -7200000,
    "direction": "past"
  }
}

Usage

Direct import
import { datetimeRelative } from '@aerostack/functions/datetime-relative';

const result = datetimeRelative({ date: post.createdAt });
console.log(result.relative); // "posted 3 days ago"

// French locale
const fr = datetimeRelative({ date: event.startsAt, options: { locale: 'fr' } });
console.log(fr.relative); // "dans 2 jours"

Use Cases

  • Showing "posted N minutes ago" on social feeds and comment sections
  • Displaying "expires in 3 days" on trial or subscription banners
  • Internationalised timestamps in multi-language applications

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-relative function do? +

datetime-relative 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-relative function? +

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

What runtime does datetime-relative use? +

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

Can I customise the datetime-relative function? +

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