phane-tech-date-time-utils
v1.0.2
Published
Pure JavaScript array utility functions
Maintainers
Keywords
Readme
📦 Kotipalli Phaneendra Kumar – Date & Time Utilities
A 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.
✨ Highlights
- ⏰ 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
📦 Installation
npm install phane-tech-date-time-utils🚀 Import
import {
getTime,
getTimeAgo,
getMonth,
getYear,
getMonthName,
getDayName,
getAllMonths,
getAllDayNames,
getFinancialYear,
getFinancialYearByOffset,
getFinancialYearsBetween,
getMonthsBetween,
getDateTime,
isWeekend
} from "phane-js-datetime-utils";📚 API Reference & Examples
⏰ getTime(isRailway, date)
getTime(); // "03:45:10 PM"
getTime(true); // "15:45:10"
getTime(false, "2026-01-10"); // Time for given date🕒 getTimeAgo(date)
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"📅 getMonth / getYear
getMonth(); // 1–12
getMonth("2026-05"); // 5
getYear(); // 2026
getYear("2020-01"); // 2020🗓 getMonthName / getDayName
getMonthName(true); // "January"
getMonthName(false); // "Jan"
getDayName(); // "Monday"
getDayName(false); // "Mon"📆 getAllMonths / getAllDayNames
getAllMonths(); // ["January", ...]
getAllMonths(false); // ["Jan", ...]
getAllDayNames(); // ["Sunday", ...]
getAllDayNames(false); // ["Sun", ...]💼 Financial Year Helpers
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"]🗓 Months Between Dates
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"]🕰 getDateTime
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"📌 isWeekend
isWeekend("2026-01-11"); // true🧪 Testing
- Fully compatible with Jest
- Deterministic outputs
- Ideal for unit & snapshot testing
📄 License
MIT
🔗 Links
- 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
