Modules
Dates
Écrire les dates grégoriennes en malgache et obtenir les noms malgaches des mois et des jours, en cinq styles.
formatDate('2026-11-23')23 Novambra 2026formatDate('2026-11-23', 'full')Alatsinainy 23 Novambra 2026
spellTime('07:15')amin'ny fito sy dimy ambin'ny folo minitra marainaspellTime('14:30')amin'ny roa sy telopolo minitra tolakandrospellTime('21:00')amin'ny sivy alina
Résultat
Alahady 26 Jona 1960
JSformatDate('1960-06-26', 'full')PHPMalagasyDate::fromString('1960-06-26')->format(DateStyle::Full)Référence rapide
Section intitulée « Référence rapide »formatDate(date, style) | Date → text in a DateStyle |
parseDate(text, style) | Malagasy date text → date, or throws |
safeParseDate(text, style) | Text → date or error code, never throws |
tryParseDate(text, style) | Text → date, or nothing, never throws |
spellTime(time) | Time → Malagasy words |
parseTime(text) | Words → time, or throws |
safeParseTime(text) | Words → time or error code, never throws |
tryParseTime(text) | Words → time, or nothing, never throws |
spellDateTime(dateTime, style) | Date and time → date, then time in words |
monthName(month, width) | 1–12 → month name, wide or abbreviated |
weekdayName(isoWeekday, width) | ISO weekday 1–7 → name, wide or abbreviated |
MalagasyDate::fromString($date)->format($style) | Date → text in a DateStyle |
MalagasyDate::parse($text, $style) | Malagasy date text → date, or throws |
MalagasyDate::safeParse($text, $style) | Text → date or error code, never throws |
MalagasyDate::tryParse($text, $style) → null | Text → date, or nothing, never throws |
MalagasyTime::fromString($time)->spell() | Time → Malagasy words |
MalagasyTime::parse($text) | Words → time, or throws |
MalagasyTime::safeParse($text) | Words → time or error code, never throws |
MalagasyTime::tryParse($text) → null | Words → time, or nothing, never throws |
MalagasyDateTime::fromString($dt)->spell($style) | Date and time → date, then time in words |
MalagasyDate::monthName($month, $width) | 1–12 → month name, wide or abbreviated |
MalagasyDate::weekdayName($weekday, $width) | ISO weekday 1–7 → name, wide or abbreviated |
Formater une date
Section intitulée « Formater une date »| Cas | Appel | Résultat |
|---|---|---|
| long | formatDate('2026-11-23', 'long') | 23 Novambra 2026 |
| full | formatDate('2026-11-23', 'full') | Alatsinainy 23 Novambra 2026 |
| medium | formatDate('2026-11-23', 'medium') | 2026 Nov 23 |
| short | formatDate('2026-11-23', 'short') | 2026-11-23 |
| numeric | formatDate('2026-11-23', 'numeric') | 23/11/2026 |
import { formatDate } from '@mdgascar/date-time';
formatDate('2026-11-23'); // '23 Novambra 2026'formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'formatDate({ year: 1960, month: 6, day: 26 }, 'full'); // 'Alahady 26 Jona 1960'formatDate(new Date(), 'numeric');use Mdgascar\MalagasyIntl\DateTime\DateStyle;use Mdgascar\MalagasyIntl\DateTime\MalagasyDate;
MalagasyDate::fromString('2026-11-23')->format(); // '23 Novambra 2026'MalagasyDate::fromString('2026-11-23')->format(DateStyle::Full); // 'Alatsinainy 23 Novambra 2026'MalagasyDate::fromParts(1960, 6, 26)->format(DateStyle::Full); // 'Alahady 26 Jona 1960'MalagasyDate::fromDateTime(new DateTimeImmutable())->format(DateStyle::Numeric);Lire une date
Section intitulée « Lire une date »parseDate relit chaque style écrit par formatDate. La casse et les espaces en trop ne comptent pas, et le jour et le mois peuvent n’avoir qu’un chiffre.
Résultat
{ year: 2026, month: 11, day: 23 }
JSparseDate('23 Novambra 2026')PHPMalagasyDate::parse('23 Novambra 2026')import { parseDate } from '@mdgascar/date-time';
parseDate('23 Novambra 2026'); // { year: 2026, month: 11, day: 23 }parseDate('23/11/2026'); // { year: 2026, month: 11, day: 23 }MalagasyDate::parse('23 Novambra 2026')->month; // 11MalagasyDate::parse('23/11/2026')->day; // 23Dire l’heure
Section intitulée « Dire l’heure »spellTime dit une heure en malgache : l’heure sur 12 heures, puis sy et les minutes comptées avec minitra, puis le moment de la journée (alina 0–3 et 20–23, maraina 4–11, atoandro 12, tolakandro 13–17, hariva 18–19). parseTime la relit.
| Moment | Heures | Exemple |
|---|---|---|
| alina | 00:00 – 03:59 | amin'ny roa ambin'ny folo alina |
| maraina | 04:00 – 11:59 | amin'ny efatra maraina |
| atoandro | 12:00 | amin'ny roa ambin'ny folo atoandro |
| tolakandro | 13:00 – 17:59 | amin'ny iray tolakandro |
| hariva | 18:00 – 19:59 | amin'ny enina hariva |
| alina | 20:00 – 23:59 | amin'ny valo alina |
Résultat
amin'ny roa sy telopolo minitra tolakandro
JSspellTime('14:30')PHPMalagasyTime::fromString('14:30')->spell()import { parseTime, spellTime } from '@mdgascar/date-time';
spellTime('07:15'); // "amin'ny fito sy dimy ambin'ny folo minitra maraina"spellTime('14:30'); // "amin'ny roa sy telopolo minitra tolakandro"spellTime('17:45'); // "amin'ny dimy sy dimy amby efapolo minitra tolakandro"parseTime("amin'ny roa sy telopolo minitra tolakandro"); // { hour: 14, minute: 30 }use Mdgascar\MalagasyIntl\DateTime\MalagasyTime;
MalagasyTime::fromString('07:15')->spell(); // "amin'ny fito sy dimy ambin'ny folo minitra maraina"MalagasyTime::fromString('14:30')->spell(); // "amin'ny roa sy telopolo minitra tolakandro"MalagasyTime::parse("amin'ny roa sy telopolo minitra tolakandro")->hour; // 14Date et heure
Section intitulée « Date et heure »spellDateTime écrit la date dans un style, puis l’heure en lettres.
Résultat
23 Novambra 2026 amin'ny roa sy telopolo minitra tolakandro
JSspellDateTime('2026-11-23T14:30')PHPMalagasyDateTime::fromString('2026-11-23T14:30')->spell()import { spellDateTime } from '@mdgascar/date-time';
spellDateTime('2026-11-23T14:30'); // "23 Novambra 2026 amin'ny roa sy telopolo minitra tolakandro"spellDateTime('2026-11-23T14:30', 'full'); // "Alatsinainy 23 Novambra 2026 amin'ny roa sy telopolo minitra tolakandro"use Mdgascar\MalagasyIntl\DateTime\DateStyle;use Mdgascar\MalagasyIntl\DateTime\MalagasyDateTime;
MalagasyDateTime::fromString('2026-11-23T14:30')->spell(); // "23 Novambra 2026 amin'ny roa sy telopolo minitra tolakandro"MalagasyDateTime::fromDateTime(new DateTimeImmutable())->spell(DateStyle::Full);Noms des mois et des jours
Section intitulée « Noms des mois et des jours »Les jours utilisent la numérotation ISO : lundi vaut 1, dimanche 7.
import { monthName, weekdayName } from '@mdgascar/date-time';
monthName(6); // 'Jona'monthName(6, 'abbreviated'); // 'Jon'weekdayName(1); // 'Alatsinainy'weekdayName(7, 'abbreviated'); // 'Alah'use Mdgascar\MalagasyIntl\DateTime\MalagasyDate;use Mdgascar\MalagasyIntl\DateTime\NameWidth;
MalagasyDate::monthName(6); // 'Jona'MalagasyDate::monthName(6, NameWidth::Abbreviated); // 'Jon'MalagasyDate::weekdayName(1); // 'Alatsinainy'MalagasyDate::weekdayName(7, NameWidth::Abbreviated); // 'Alah'| Entrée | Code d’erreur |
|---|---|
Une date qui n’est ni une chaîne, ni une Date, ni { year, month, day } ; un mois ou un jour qui n’est pas un entier |
INVALID_TYPE |
Pas une date réelle (2026-02-30) |
INVALID_FORMAT |
| Mois hors de 1–12, jour hors de 1–7 | OUT_OF_RANGE |