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/akidateBasic 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
locale
string
Two-letter locale code
Supported Locales
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
date
string
-
ISO date string
template
string
'L LT'
Localized format template
Returns
string
Formatted date string
Format Templates
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
value
unknown
Date input (string, Date, Day.js, or object with toISOString)
Returns
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
value
unknown
Date input (string, Date, Day.js, or object with toISOString)
Returns
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
Set locale once at app initialization - Call
setLocalein your app's root component or initialization logicUse toIsoDate for API payloads - Always normalize dates before sending to APIs
Handle undefined returns - Both
toIsoDateandparsecan return undefined for invalid inputUse localized templates - Prefer templates like
LLoverYYYY-MM-DDfor user-facing datesSync with Akilocale - Keep akidate locale in sync with your app's language setting
Last updated
Was this helpful?

