The-Time is a simple JavaScript library for time manipulation and comparison. It provides a flexible, easy-to-use interface for working with time.
- Create Time instances from time string.
- Get hours, minutes, and seconds from Time instances.
- Add and subtract hours, minutes, and seconds from Time instances.
- Compare Time instances.
- Convert Time instances to string format.
- Handle overflow time operations.
Use npm to install The-Time library:
npm install the-time
Here is a basic usage of the The-Time library:
import { Time } from 'the-time';
let options = { overflow: true };
let time = new Time('23:45:50', options);
console.log(time.toString()); // outputs: 23:45:50.000
time.add(20, 'minutes');
console.log(time.toString()); // outputs: 00:05:50.000 (because of overflow option)
let time2 = new Time('00:00:00');
console.log(time.isGreaterThan(time2)); // outputs: true
Creates a new Time
instance from a time string. timeString
must be in the format 'HH:mm:ss'. If options.overflow
is set to true (which is the default), time will overflow when adding or subtracting (23:59:59 + 1 minute = 00:00:59).
options.utcOffset
can be used to set the UTC offset of the time string.
Returns the string representation of the Time
instance in the format 'HH:mm:ss.fff'.
Returns the string representation of the Time
instance in the format 'HH:mm:ss'.
Returns the hour component of the Time
instance.
Returns the minute component of the Time
instance.
Returns the second component of the Time
instance.
Adds the specified amount of hours, minutes, or seconds to the Time
instance. Returns the Time
instance for chaining.
Subtracts the specified amount of hours, minutes, or seconds from the Time
instance. Returns the Time
instance for chaining.
Returns true if the Time
instance is greater than the provided value.
Returns true if the Time
instance is less than the provided value.
Returns true if the Time
instance is equal to the provided value.
Returns the total number of seconds in the Time
instance.
Returns the Time
instance as a Date
instance.
Returns the current time as a Time
instance.
Checks if a time string is valid.
Creates a new Time
instance from a Date
instance.
MIT