← All procedures

quantity.formatDuration

This function prints a time as people say it: "2 h 11 min 15 s", "45 min", "2 days 3 h". A time of less than a second keeps its own unit ("250 ms"). The `parts` option sets the most units that it names, and it rounds the smallest. It is `formatOnScale` with a compound of days, hours, minutes and seconds.

CLI
Package
@procedures/quantity · README
Path
["quantity","formatDuration"]
CLI
mark quantity formatDuration --amount <object>
As data
{"$proc":["quantity","formatDuration"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/quantity/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["quantity","formatDuration"], { amount: {} });
console.log(JSON.stringify(result));

From the command line

$ mark quantity formatDuration --amount <object>

As data, in a program

{ "$proc": ["quantity", "formatDuration"], "input": { "amount": {} } }

Input

FieldTypeRequiredDefaultDescription
amountobjectyes
partsnumberno

Output

The schema does not list fields (string).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "amount": {
        "type": "object",
        "properties": {
          "value": {
            "type": "number"
          },
          "unit": {
            "type": "string"
          }
        },
        "required": [
          "value",
          "unit"
        ],
        "additionalProperties": {}
      },
      "parts": {
        "type": "number"
      }
    },
    "required": [
      "amount"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "string"
  }
}