time.js
Parses time input with no relation to dates, with the option to convert to the next immediate corresponding Date.
Built for Promt, to solve this problem.
Browser
$ bower install time-js # or just manually download time.js
var t = ;t; // 2t; // 0t; // 'pm't; // '2:00 pm't; // Sep 10 2:00 (assuming it is 1 o'clock Sep 10)t // '02:00 PM't; // trueTime; // false
Node
$ npm install time-js
var time = ;;// you get the idea, or see below for more ideas
Examples
Some example uses can be viewed in examples.html.
Parses strings such as "8:20" into a Date-less Time.
'1' // 1:00'1:23' // 1:23
If you fancy it, you can use safely drop the 'new'.
// 1:23 // 1:23
am/pm can optionally be specified.
// 8:30 pm // 3:00 pm // 3:00 am
Converts Time into the next corresponding JavaScript Date.
// assume it's 3:15 pm Aug 10 // 4:15 pm Aug 10 // 2:00 am Aug 11 // 2:00 pm Aug 11
Does validation statically...
Time // trueTime // falseTime // false
... or after construction.
// true // false // false
There's basic formatting
; // '02:30 P'; // '12 a'; // '2:20 a'; // '7'
Accepts numbers too.
// true
Military time is not supported, but may be in the future (or not).
Test
$ npm test