Package Exports
- phane-tech-date-time-utils
- phane-tech-date-time-utils/index.cjs
- phane-tech-date-time-utils/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (phane-tech-date-time-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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