Pure JavaScript array utility functions
npm install phane-tech-date-time-utilsA lightweight, dependency-minimal JavaScript module that provides safe, consistent, and reusable Date & Time helper functions.
These utilities simplify working with dates, times, months, weekdays, and financial years, handling edge cases cleanly and predictably.
Designed for frontend (Vue/React) and Node.js applications.
---
- ⏰ Time formatting (12h / 24h)
- 🕒 Human‑readable relative time ("few moments ago")
- 📅 Month & weekday helpers (names & numbers)
- 💼 Financial year utilities (current, offset, range)
- 🌍 Locale‑aware formatting
- 🧪 Jest‑friendly & predictable outputs
- ⚡ Zero heavy dependencies
---
``bash`
npm install phane-tech-date-time-utils
---
`js`
import {
getTime,
getTimeAgo,
getMonth,
getYear,
getMonthName,
getDayName,
getAllMonths,
getAllDayNames,
getFinancialYear,
getFinancialYearByOffset,
getFinancialYearsBetween,
getMonthsBetween,
getDateTime,
isWeekend
} from "phane-js-datetime-utils";
---
`js`
getTime(); // "03:45:10 PM"
getTime(true); // "15:45:10"
getTime(false, "2026-01-10"); // Time for given date
---
`js`
getTimeAgo(new Date()); // "few moments ago"
getTimeAgo(Date.now() - 60000); // "1 min ago"
getTimeAgo(Date.now() - 7200000); // "2 hours ago"
getTimeAgo("2025-04-12"); // "x months ago"
---
`js
getMonth(); // 1–12
getMonth("2026-05"); // 5
getYear(); // 2026
getYear("2020-01"); // 2020
`
---
`js
getMonthName(true); // "January"
getMonthName(false); // "Jan"
getDayName(); // "Monday"
getDayName(false); // "Mon"
`
---
`js
getAllMonths(); // ["January", ...]
getAllMonths(false); // ["Jan", ...]
getAllDayNames(); // ["Sunday", ...]
getAllDayNames(false); // ["Sun", ...]
`
---
`js
getFinancialYear("2026-01-10"); // "2025-2026"
getFinancialYearByOffset(-1); // Previous FY
getFinancialYearByOffset(1); // Next FY
getFinancialYearsBetween(
"2021-01-01",
"2024-12-31"
);
// ["2020-2021","2021-2022","2022-2023","2023-2024"]
`
---
`js
getMonthsBetween("2026-01-01", "2026-04-01");
// ["January","February","March","April"]
getMonthsBetween("2026-01-01", "2026-04-01", { asNumber: true });
// [1,2,3,4]
getMonthsBetween("2026-01-01", "2026-04-01", { fullName: false });
// ["Jan","Feb","Mar","Apr"]
`
---
`js
getDateTime();
// "10/01/2026, 03:45 PM"
getDateTime("2026-01-10", false);
// "10/01/2026"
getDateTime("2026-01-10", true, true);
// "10/01/2026, 15:45"
`
---
`js``
isWeekend("2026-01-11"); // true
---
- Fully compatible with Jest
- Deterministic outputs
- Ideal for unit & snapshot testing
---
MIT
---
- Author: Kotipalli Phaneendra Kumar
- GitHub Repository: https://phane-tech.github.io/phane-tech-date-time-utils
- Demo / Documentation: https://phane-tech.github.io/phane-tech-date-time-utils/module-DateTimeHelpers.html
- Unit Test Cases Reports: https://phane-tech.github.io/phane-tech-date-time-utils/unit-test-report.html