date-time-headache
v1.0.1
Published
A simple timezone utility package using Luxon to normalize and format inconsistent MongoDB-stored dates.
Maintainers
Readme
🧠 date-time-headache
A lightweight utility package that helps you fix timezone inconsistencies in projects — especially useful when working with MongoDB-stored dates and mixed timezones.
Built with Luxon
✨ Features
- ✅ Normalize inconsistent date formats (strings, JS Dates, Luxon instances)
- ✅ Always handle dates internally as UTC
- ✅ Display time in any target timezone
- ✅ Human-readable formatting
- ✅ Perfect for apps with historical timezone chaos (yes, the name is real 😅)
📦 Installation
Using npm:
npm install date-time-headacheOr with yarn:
yarn add date-time-headacheUsge
const {
normalizeToUTC,
convertToTimezone,
formatInTimezone,
} = require("date-time-headache");
// Example MongoDB date
const mongoDate = new Date("2024-05-24T10:00:00Z");
// Normalize to UTC (optional but safe)
const normalized = normalizeToUTC(mongoDate);
// Convert to specific timezone
const localDate = convertToTimezone(normalized, "Asia/Dhaka");
// Format as readable string
const formatted = formatInTimezone(mongoDate, "Asia/Dhaka", "yyyy-MM-dd hh:mm a");
console.log(formatted); // 2024-05-24 04:00 PM⚠️ When to Use This Package This is especially useful when:
- You’ve stored inconsistent date formats in MongoDB
- Users across timezones see wrong times
- You need to display consistent local time without changing DB data
