Module: Kairos

Methods


<static> absolute(time [, pattern])

Returns an instance of Kairos.Engine with absolute time.
Parameters:
Name Type Argument Description
time String | Number | Kairos.Engine Time expression, milliseconds or a Kairos.Engine instance to get its absolute value
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with absolute value
Type
Kairos.Engine
Example
Kairos.absolute('-01:00', '#hh:mm');

<static> compare(comparand, comparator [, pattern])

Compares first time with second time and returns -1, 0 or 1 if first value is smaller, equals or bigger than second value.
Parameters:
Name Type Argument Description
comparand String | Number Literal time expression, milliseconds or a Kairos.Engine instance to compare with
comparator String | Number Literal time expression, milliseconds or a Kairos.Engine instance to be compared with
pattern String <optional>
Overrides Kairos pattern
Returns:
Smaller -1 | Equals 0 | Bigger 1
Type
Number
Examples
Kairos.compare(instance, anotherInstance);
Kairos.compare('02:00', '03:00', 'hh:mm');
Kairos.compare(300000, 10000);

<static> divide(dividend, divisor [, pattern])

Divides dividend by the divisor.
Parameters:
Name Type Argument Description
dividend String | Number | Kairos.Engine Dividend time expression, milliseconds or a Kairos.Engine instance
divisor Number Divisor value
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with division result
Type
Kairos.Engine
Examples
Kairos.divide(currentInstance, 2);
Kairos.divide('02:00', 10, 'hh:mm');
Kairos.divide(300000, 5);

<static> getAutoParser()

Gets current Kairos configuration for auto parse feature.
Returns:
True if auto parse is being used or false if not
Type
Boolean

<static> getFraction(time, numerator, denominator [, pattern])

Returns a fraction of the current time.
Parameters:
Name Type Argument Description
time String | Number | Kairos.Engine Time expression, milliseconds or a Kairos.Engine instance to extract a fraction
numerator Number Numerator value
denominator Number Denominator value
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with the fraction extracted
Type
Kairos.Engine
Examples
Kairos.getFraction(currentInstance, 2, 3);
Kairos.getFraction('02:00', 2, 3 'hh:mm');
Kairos.getFraction(300000, 3, 4);

<static> getInterval(time1, time2 [, pattern])

Returns a time expression representing the time between starting time and ending time.
Parameters:
Name Type Argument Description
time1 String | Number | Kairos.Engine Literal time expression, milliseconds or a Kairos.Engine instance
time2 String | Number | Kairos.Engine Literal time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with the interval between time1 and time2
Type
Kairos.Engine
Examples
Kairos.getInterval(instance, anotherInstance);
Kairos.getInterval('02:00', '03:00', 'hh:mm');
Kairos.getInterval(300000, 800000);

<static> getPattern()

Gets current Kairos pattern.
Returns:
Current Kairos pattern
Type
String

<static> max(values [, pattern])

Returns the maximum value from the given values.
Parameters:
Name Type Argument Description
values Array.<String> | Array.<Number> | Array.<Kairos.Engine> Array with time expressions
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with the greatest value found in the list
Type
String
Examples
Kairos.max(a, b, c, d);
Kairos.max(['02:00', '03:00', '01:00', '10:00'], 'hh:mm');
Kairos.max(300000, 10000);

<static> min(values [, pattern])

Returns the minimum value from the given values.
Parameters:
Name Type Argument Description
values Array.<String> | Array.<Number> | Array.<Kairos.Engine> Array with time expressions
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with the lowest value found in the list
Type
Kairos.Engine
Examples
Kairos.min(a, b, c, d);
Kairos.min(['02:00', '03:00', '01:00', '10:00'], 'hh:mm');
Kairos.min(300000, 10000);

<static> minus(minuend, subtrahend [, pattern])

Subtracts minuend time with subtrahend time.
Parameters:
Name Type Argument Description
minuend String | Number | Kairos.Engine Minuend time expression
subtrahend String | Number | Kairos.Engine Literal time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with subtract result
Type
Kairos.Engine
Examples
Kairos.minus(currentInstance, '01:00');
Kairos.minus('02:00', '01:00', 'hh:mm');
Kairos.minus('01:00', 1000);

<static> multiply(multiplier, multiplicand [, pattern])

Multiplies multiplier by the multiplicand.
Parameters:
Name Type Argument Description
multiplier String | Number | Kairos.Engine Multiplier time expression, milliseconds or a Kairos.Engine instance
multiplicand Number Multiplicand value
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with multiplication result
Type
Kairos.Engine
Examples
Kairos.multiply(currentInstance, 2);
Kairos.multiply('02:00', 10, 'hh:mm');
Kairos.multiply(300000, 5);

<static> new(time [, pattern])

Returns a new Kairos.Engine instance.
Parameters:
Name Type Argument Description
time String | Number | Kairos.Engine Time expression, milliseconds or a Kairos.Engine instance to create an instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance from the given time
Type
Kairos.Engine
Example
Kairos.new('01:00', 'hh:mm');

<static> noConflict()

Avoid conflict in case of another instance of Kairos is already in the scope.
Returns:
Previous Kairos object
Type
Object

<static> plus(augend, addend [, pattern])

Sums augend time with addend time.
Parameters:
Name Type Argument Description
augend String | Number | Kairos.Engine Augend time expression, milliseconds or a Kairos.Engine instance
addend String | Number | Kairos.Engine Addend time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Kairos.Engine instance with the sum result
Type
Kairos.Engine
Examples
Kairos.plus(currentInstance, '01:00');
Kairos.plus('01:00', '01:00', 'hh:mm');
Kairos.plus('01:00', 1000);

<static> setAutoParser(yN)

Sets Kairos configuration for auto parse feature.
Parameters:
Name Type Description
yN Boolean True to use or false to not use auto parser
Example
Kairos.setAutoParser(true);

<static> setPattern(pattern)

Sets Kairos time expression pattern. Pattern structure is the following:
  • # -> sign
  • h -> hours
  • m -> minutes
  • s -> seconds
  • S -> milliseconds
Parameters:
Name Type Description
pattern String The pattern to parse and format time expressions
Example
Kairos.setPattern('#hh:mm:ss.SSS');

<static> toHours(time [, pattern])

Converts the given time expression to hours.
Parameters:
Name Type Argument Description
time String | Number Literal time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Total hours in the time expression
Type
Number
Examples
Kairos.toHours(instance);
Kairos.toHours('02:00', 'hh:mm');
Kairos.toHours(300000);

<static> toMilliseconds(time [, pattern])

Converts the given time expression to milliseconds.
Parameters:
Name Type Argument Description
time String | Number Literal time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Total milliseconds in the time expression
Type
Number
Examples
Kairos.toMilliseconds(instance);
Kairos.toMilliseconds('02:00', 'hh:mm');
Kairos.toMilliseconds(300000);

<static> toMinutes(time [, pattern])

Converts the given time expression to minutes.
Parameters:
Name Type Argument Description
time String | Number Literal time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Total minutes in the time expression
Type
Number
Examples
Kairos.toMinutes(instance);
Kairos.toMinutes('02:00', 'hh:mm');
Kairos.toMinutes(300000);

<static> toSeconds(time [, pattern])

Converts the given time expression to seconds.
Parameters:
Name Type Argument Description
time String | Number Literal time expression, milliseconds or a Kairos.Engine instance
pattern String <optional>
Overrides Kairos pattern
Returns:
Total seconds in the time expression
Type
Number
Examples
Kairos.toSeconds(instance);
Kairos.toSeconds('02:00', 'hh:mm');
Kairos.toSeconds(300000);

<static> validate(expression, pattern)

Validates the give expression with the current or given pattern.
Parameters:
Name Type Description
expression String Time expression, milliseconds or a Kairos.Engine instance to validate
pattern String Pattern to test the expression
Returns:
True if valid, false if invalid
Type
Boolean
Example
Kairos.validate('10:30', 'hh:mm');