Skip to main content
Module

x/complaindate/mod.ts>formatInstant

JavaScript date-time utilities that keep timezones on the surface
Latest
function formatInstant
import { formatInstant } from "https://deno.land/x/complaindate@v1.0.1/mod.ts";

Curry a function to get localized strings of its JS Date arguments.

The function is curried in 3 rounds, each setting a property:

  1. Intl locale, defaults to system's locale if not given.
  2. Intl format options, defaults to include a "short" timezone-style unless timeZoneName is explicitly undefined.
  3. A named IANA timezone, defaults to system's timezone if not given.

Examples

Example 1

const formatDateTime = formatInstant()()("Europe/Stockholm"); // Use system's locale and default formatting options
const format24hDateTime = formatInstant("en")({ hourCycle: "h23" })("Europe/Stockholm");

formatDateTime(new Date()); // "6/11/2023, 4:54:32 PM GMT+2"
format24hDateTime(new Date());  // "6/11/2023, 16:54:32 GMT+2"

Parameters

optional
locale: Intl.LocalesArgument

Intl locale,

Returns

(options?: FormatInstantOptions) => (timezone?: string) => (instant: Date) => string

A curried function that takes Intl format options and returns another curried function that takes a timezone and returns the final curried function that operates on JS Date objects