seconds-since-midnight
A super simple library for converting seconds since midnight to hours-minutes-seconds-am/pm and back.
Seconds since midnight can be a convenient way to store a time of day (without a date) but there isn't much support for handling these values the way there is for date and time objects, like Date()
and moment.js.
So this tiny zero-dependancy library will help you do conversions like
// 11700// { hours: '2', minutes: '05', meridian: 'PM' }
Yep, that's all it does.
npm install seconds-since-midnight --save
// or const { toSeconds, toReadableTime } = require('seconds-since-midnight') // supports strings or numbers for hours and minutes and any capitalization for AM/PM// 50700 // supports negative values to handle wrapping back around when incrementing/decrementing === // true // and values greater than 12 hours/60 minutes to support wrapping the other way === // true // going the other direction it returns an object// { hours: '3', minutes: '15', meridian: 'AM' } // it will roll with it if it recieves a negative value or a value greater than one day // 25.5 hours// { hours: '1', minutes: '30', meridian: 'AM' } // -1 hour// { hours: '11', minutes: '00', meridian: 'PM' }