pomeranian-durations
Version:
An immutable duration library based on the ISO-8601 format for durations.
154 lines (124 loc) • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fromYears = exports.fromMonths = exports.fromWeeks = exports.fromDays = exports.fromHours = exports.fromMinutes = exports.fromSeconds = exports.fromMilliseconds = exports.fromMicroseconds = void 0;
var _transformations = require("./transformations");
var _constants = require("./constants");
/**
* Helpers to convert an integer to an ISO8601 duration.
* @name default
*/
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromMicroseconds(1) // => 'PT0.000001S'
*/
var fromMicroseconds = function fromMicroseconds(amount) {
return fromSeconds(amount / _constants.ONE_SECOND);
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromMilliseconds(1) // => 'PT0.001S'
*/
exports.fromMicroseconds = fromMicroseconds;
var fromMilliseconds = function fromMilliseconds(amount) {
return fromSeconds(amount / _constants.ONE_MILLISECOND);
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromSeconds(1) // => 'PT1S'
*/
exports.fromMilliseconds = fromMilliseconds;
var fromSeconds = function fromSeconds(amount) {
return (0, _transformations.toIso)({
seconds: amount
});
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromMinutes(1) // => 'PT1M'
*/
exports.fromSeconds = fromSeconds;
var fromMinutes = function fromMinutes(amount) {
return (0, _transformations.toIso)({
minutes: amount
});
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromHours(1) // => 'PT1H'
*/
exports.fromMinutes = fromMinutes;
var fromHours = function fromHours(amount) {
return (0, _transformations.toIso)({
hours: amount
});
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromDays(1) // => 'P1D'
*/
exports.fromHours = fromHours;
var fromDays = function fromDays(amount) {
return (0, _transformations.toIso)({
days: amount
});
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromWeeks(1) // => 'P1W'
*/
exports.fromDays = fromDays;
var fromWeeks = function fromWeeks(amount) {
return (0, _transformations.toIso)({
weeks: amount
});
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromMonths(1) // => 'P1M'
*/
exports.fromWeeks = fromWeeks;
var fromMonths = function fromMonths(amount) {
return (0, _transformations.toIso)({
months: amount
});
};
/**
* Converts a given number to an ISO8601 duration
* @param amount {number}
* @returns {string} - an ISO8601 duration
* @example
* fromYears(1) // => 'P1Y'
*/
exports.fromMonths = fromMonths;
var fromYears = function fromYears(amount) {
return (0, _transformations.toIso)({
years: amount
});
};
exports.fromYears = fromYears;