AkiDate

A lightweight date utility library for Akinon applications. Wraps Day.js with built-in localization support and convenient parsing/formatting methods.

Installation

pnpm add @akinon/akidate

Basic Usage

import { akidate } from '@akinon/akidate';

// Format an ISO date string
const formatted = akidate.formatIsoDate('2024-01-15T14:30:00.000Z', 'LL');
// Output: "January 15, 2024"

// Set locale for localized formatting
akidate.setLocale('tr');
const turkishDate = akidate.formatIsoDate('2024-01-15T14:30:00.000Z', 'LL');
// Output: "15 Ocak 2024"

API Reference

setLocale

Sets the global locale for date formatting.

akidate.setLocale('tr');

Parameters

Parameter
Type
Description

locale

string

Two-letter locale code

Supported Locales

Code
Language

en

English (default)

tr

Turkish

de

German

fr

French

es

Spanish

pt

Portuguese

ru

Russian

ar

Arabic


formatIsoDate

Formats an ISO date string using localized format templates.

Parameters

Parameter
Type
Default
Description

date

string

-

ISO date string

template

string

'L LT'

Localized format template

Returns

Type
Description

string

Formatted date string

Format Templates

Template
Example (en)
Description

L

01/15/2024

Date (numeric)

LL

January 15, 2024

Date (long)

LLL

January 15, 2024 2:30 PM

Date and time

LLLL

Monday, January 15, 2024 2:30 PM

Full date with weekday

LT

2:30 PM

Time

LTS

2:30:45 PM

Time with seconds

l

1/15/2024

Date (short)

ll

Jan 15, 2024

Date (abbreviated)

lll

Jan 15, 2024 2:30 PM

Date and time (short)


toIsoDate

Converts various date inputs into an ISO string. Useful for normalizing different date formats before sending to an API.

Parameters

Parameter
Type
Description

value

unknown

Date input (string, Date, Day.js, or object with toISOString)

Returns

Type
Description

string | undefined

ISO date string, or undefined if invalid


parse

Parses various date inputs into a Day.js instance. Useful for date manipulation and comparison.

Parameters

Parameter
Type
Description

value

unknown

Date input (string, Date, Day.js, or object with toISOString)

Returns

Type
Description

Dayjs | undefined

Day.js instance, or undefined if invalid


Usage with Akilocale

Integrate with @akinon/akilocale for automatic locale synchronization:

Common Use Cases

Table Column Formatting

Form Date Handling

Date Comparison

Relative Time Calculation

Best Practices

  1. Set locale once at app initialization - Call setLocale in your app's root component or initialization logic

  2. Use toIsoDate for API payloads - Always normalize dates before sending to APIs

  3. Handle undefined returns - Both toIsoDate and parse can return undefined for invalid input

  4. Use localized templates - Prefer templates like LL over YYYY-MM-DD for user-facing dates

  5. Sync with Akilocale - Keep akidate locale in sync with your app's language setting

Last updated

Was this helpful?