Skip to content

feat: add .toDate() and .toTime() — Malagasy date/time formatting (v1.2.0) - #10

Merged
nifaliana merged 3 commits into
mainfrom
feat/v1.2.0-date-time
Jun 9, 2026
Merged

feat: add .toDate() and .toTime() — Malagasy date/time formatting (v1.2.0)#10
nifaliana merged 3 commits into
mainfrom
feat/v1.2.0-date-time

Conversation

@nifaliana

Copy link
Copy Markdown
Owner

Summary

Adds two new public methods to the Tanisa class, hardens existing input validation, and refactors the source into focused modules.

Changes by feature

.toDate(input, options?)

Converts any string | Date | number to Malagasy date format.

tanisa.toDate('2022-12-25')                     // "25 Desambra 2022"
tanisa.toDate('2020-01-01', { format: 'long' }) // "voalohan'ny volana Janoary, taona roapolo sy roa arivo"
  • Short (default) and long spoken formats
  • ISO date strings parsed via regex to avoid UTC midnight timezone drift
  • Validates ISO calendar range — month ∈ [1–12], day ∈ [1–31]

.toTime(input, options?)

Converts any string | Date | number to Malagasy spoken time with the correct time-of-day period.

tanisa.toTime('09:30')                              // "sivy ora sy telopolo minitra maraina"
tanisa.toTime('14:30:45', { precision: 'seconds' }) // "roa ora sy telopolo minitra sy dimy amby efapolo segondra tolakandro"
tanisa.toTime('00:00')                              // "roa ambin'ny folo ora alina"
  • 5 time-of-day periods: maraina, antoandro, tolakandro, hariva, alina
  • Configurable precision: 'minutes' | 'seconds'
  • Midnight correctly maps to roa ambin'ny folo ora alina

Refactor — separation of concerns

Before After
src/converter.ts — monolithic Tanisa class src/tanisa.ts — Tanisa class only
src/date.ts — pure date parse/format functions
src/time.ts — pure time parse/format functions
src/utils.ts — shared inputToNativeDate() helper
src/converter.ts src/converter.ts — barrel entry point
tests/converter.test.ts (71 tests) tests/toWords.test.ts + tests/toDate.test.ts + tests/toTime.test.ts (124 tests)

Input validation hardening

Input Before After
toWords('1e15') Returns 'iray' (silent wrong result) TypeError
toWords('-0.5') Returns 'aotra faingo dimy' (silent wrong result) RangeError
toDate('2024-13-01') Returns '01 undefined 2024' TypeError
toTime('-1:30') Throws opaque RangeError TypeError
toTime('23abc:00') Returns result for 23:00 TypeError

Test plan

  • npx vitest run — 124 tests pass (was 71)
  • Lint passes (eslint)
  • README examples verified against actual test output
  • Security audit: no vulnerabilities found (pure computation library, zero runtime deps)

nifaliana added 3 commits June 9, 2026 15:17
.toDate(input, options?)
  - Short (default): "25 Desambra 2022"
  - Long: "dimy amby roapolo Desambra, taona roa amby roapolo sy roa arivo"
  - Accepts string | Date | number; ISO date strings parsed via regex to
    avoid UTC midnight timezone drift from new Date("YYYY-MM-DD")
  - Validates ISO calendar range (month 1-12, day 1-31)

.toTime(input, options?)
  - 5 time-of-day periods: maraina, antoandro, tolakandro, hariva, alina
  - Configurable precision: "minutes" (default) | "seconds"
  - Midnight correctly maps to "roa ambin'ny folo ora alina"
  - Accepts HH:MM, HH:MM:SS, ISO datetime, Date, Unix timestamp (ms)

Refactor: Tanisa class -> src/tanisa.ts; pure functions in src/date.ts
and src/time.ts; shared inputToNativeDate() in src/utils.ts;
src/converter.ts is now the barrel entry point.

Input validation hardening:
  - toWords: reject scientific-notation strings ("1e15" -> TypeError)
  - toWords: reject negative fractional inputs ("-0.5" -> RangeError)
  - toDate:  throw TypeError for out-of-range ISO month/day
  - toTime:  lower-bound guards and pure-digit check before parseInt
- tests/toWords.test.ts  — 73 tests (extracted from converter.test.ts)
- tests/toDate.test.ts   — 25 tests (new)
- tests/toTime.test.ts   — 26 tests (new)

Total: 124 tests across 3 files (was 71 in 1 file).
Each file covers one public method and is independently runnable.
- README: full API docs for .toDate() and .toTime() with examples,
  time-periods table, options tables, and error-handling section
- CHANGELOG: [1.2.0] entry with Added / Fixed / Changed sections
- package.json: version 1.1.5 -> 1.2.0, updated description
@nifaliana
nifaliana merged commit 091e687 into main Jun 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant