API JavaScript
@mdgascar/date
Ce contenu n’est pas encore disponible dans votre langue.
Malagasy dates: month and weekday names, and dates written in Malagasy. Part of mdg-utils by Mdgascar.
Classes
Section titled “Classes”MdgError
Section titled “MdgError”Error thrown by mdg-utils functions. Check code, which is the same in every language.
Example
Section titled “Example”try { numberToWords(-1);} catch (error) { if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') { // handle it }}Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MdgError(
code,message):MdgError
Creates an error with a shared spec code.
Parameters
Section titled “Parameters”Shared spec error code.
message
Section titled “message”string
Human-readable explanation, in English.
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor
Properties
Section titled “Properties”
readonlycode:ErrorCode
Why the call failed; the same code in every language.
readonlyname:"MdgError"='MdgError'
Always 'MdgError'.
Overrides
Section titled “Overrides”Error.name
Methods
Section titled “Methods”[hasInstance]()
Section titled “[hasInstance]()”
static[hasInstance](value):boolean
Makes instanceof MdgError true for errors from any mdg-utils package or build.
Parameters
Section titled “Parameters”unknown
Any value, usually a caught error.
Returns
Section titled “Returns”boolean
true when value is an mdg-utils error.
Remarks
Section titled “Remarks”Each package, and its ESM and CommonJS builds, has its own copy of this class, so the check looks at the error’s shape instead of its prototype chain.
Interfaces
Section titled “Interfaces”CalendarDate
Section titled “CalendarDate”A calendar date: year 1–9999, month 1–12, day of the month.
Example
Section titled “Example”const independenceDay: CalendarDate = { year: 1960, month: 6, day: 26 };Properties
Section titled “Properties”
readonlyday:number
Day of the month, 1 to 31.
readonlymonth:number
Month, 1 (Janoary) to 12 (Desambra).
readonlyyear:number
Year, 1 to 9999.
Type Aliases
Section titled “Type Aliases”DateStyle
Section titled “DateStyle”DateStyle =
"long"|"full"|"medium"|"short"|"numeric"
Date style for formatDate; long is the default.
ErrorCode
Section titled “ErrorCode”ErrorCode =
"INVALID_TYPE"|"OUT_OF_RANGE"|"INVALID_FORMAT"|"UNKNOWN_OPERATOR"
Error code shared by every mdg-utils language port.
INVALID_TYPE: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).OUT_OF_RANGE: The input has the right type but lies outside the supported range.INVALID_FORMAT: The input text cannot be read as a value of this module (wrong characters or wrong length).UNKNOWN_OPERATOR: The phone number is well formed but its operator code is not assigned to a mobile operator.
NameWidth
Section titled “NameWidth”NameWidth =
"wide"|"abbreviated"
Name width: wide (Novambra, default) or abbreviated (Nov).
Example
Section titled “Example”const width: NameWidth = 'abbreviated';Variables
Section titled “Variables”SPEC_VERSION
Section titled “SPEC_VERSION”
constSPEC_VERSION:"0.6.0"='0.6.0'
Version of the shared spec this code was generated from.
Functions
Section titled “Functions”formatDate()
Section titled “formatDate()”formatDate(
date,style?):string
Writes a date in Malagasy.
Parameters
Section titled “Parameters”string | CalendarDate | Date
YYYY-MM-DD text, { year, month, day }, or a Date (read in its local
calendar fields).
style?
Section titled “style?”DateStyle = DEFAULT_STYLE
long (default), full, medium, short (CLDR) or numeric (dd/MM/y).
Returns
Section titled “Returns”string
The formatted date.
Throws
Section titled “Throws”MdgError INVALID_FORMAT for text that is not a real YYYY-MM-DD date,
OUT_OF_RANGE for impossible fields or years outside 1–9999, INVALID_TYPE for other
input or an unknown style.
Example
Section titled “Example”formatDate('2026-11-23'); // '23 Novambra 2026'formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'formatDate({ year: 1960, month: 6, day: 26 }, 'numeric'); // '26/06/1960'getMonthName()
Section titled “getMonthName()”getMonthName(
month,width?):string
The Malagasy name of a month.
Parameters
Section titled “Parameters”number
Month number, 1 (Janoary) to 12 (Desambra).
width?
Section titled “width?”NameWidth = 'wide'
wide (default) or abbreviated.
Returns
Section titled “Returns”string
The month name.
Throws
Section titled “Throws”MdgError OUT_OF_RANGE outside 1–12, INVALID_TYPE for non-integers or an
unknown width.
Example
Section titled “Example”getMonthName(6); // 'Jona'getMonthName(11, 'abbreviated'); // 'Nov'getWeekdayName()
Section titled “getWeekdayName()”getWeekdayName(
isoWeekday,width?):string
The Malagasy name of a weekday, numbered as in ISO 8601 (Monday 1 … Sunday 7).
Parameters
Section titled “Parameters”isoWeekday
Section titled “isoWeekday”number
1 (Alatsinainy) to 7 (Alahady).
width?
Section titled “width?”NameWidth = 'wide'
wide (default) or abbreviated.
Returns
Section titled “Returns”string
The weekday name.
Throws
Section titled “Throws”MdgError OUT_OF_RANGE outside 1–7, INVALID_TYPE for non-integers or an
unknown width.
Example
Section titled “Example”getWeekdayName(1); // 'Alatsinainy'getWeekdayName(7, 'abbreviated'); // 'Alah'