From 679a0cdef32742c35a2103451523d6982e5f7fcb Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 20 Apr 2021 08:51:32 -0300 Subject: [PATCH 01/32] creating unit conversios functions --- src/daysToWeeks/index.ts | 30 +++++++++++++++++++++++++++ src/daysToWeeks/test.ts | 12 +++++++++++ src/hoursToMilliseconds/index.ts | 31 ++++++++++++++++++++++++++++ src/hoursToMilliseconds/test.ts | 12 +++++++++++ src/hoursToMinutes/index.ts | 27 ++++++++++++++++++++++++ src/hoursToMinutes/test.ts | 12 +++++++++++ src/hoursToSeconds/index.ts | 27 ++++++++++++++++++++++++ src/hoursToSeconds/test.ts | 12 +++++++++++ src/index.js | 20 ++++++++++++++++++ src/millisecondsToHours/index.ts | 32 +++++++++++++++++++++++++++++ src/millisecondsToHours/test.ts | 12 +++++++++++ src/millisecondsToMinutes/index.ts | 32 +++++++++++++++++++++++++++++ src/millisecondsToMinutes/test.ts | 12 +++++++++++ src/millisecondsToSeconds/index.ts | 33 ++++++++++++++++++++++++++++++ src/millisecondsToSeconds/test.ts | 12 +++++++++++ src/minutesToHours/index.ts | 30 +++++++++++++++++++++++++++ src/minutesToHours/test.ts | 12 +++++++++++ src/minutesToMilliseconds/index.ts | 30 +++++++++++++++++++++++++++ src/minutesToMilliseconds/test.ts | 12 +++++++++++ src/minutesToSeconds/index.ts | 27 ++++++++++++++++++++++++ src/minutesToSeconds/test.ts | 12 +++++++++++ src/monthsToQuarters/index.ts | 31 ++++++++++++++++++++++++++++ src/monthsToQuarters/test.ts | 12 +++++++++++ src/monthsToYears/index.ts | 31 ++++++++++++++++++++++++++++ src/monthsToYears/test.ts | 12 +++++++++++ src/quartersToMonths/index.ts | 27 ++++++++++++++++++++++++ src/quartersToMonths/test.ts | 12 +++++++++++ src/quartersToYears/index.ts | 31 ++++++++++++++++++++++++++++ src/quartersToYears/test.ts | 12 +++++++++++ src/secondsToHours/index.ts | 30 +++++++++++++++++++++++++++ src/secondsToHours/test.ts | 12 +++++++++++ src/secondsToMilliseconds/index.ts | 27 ++++++++++++++++++++++++ src/secondsToMilliseconds/test.ts | 12 +++++++++++ src/secondsToMinutes/index.ts | 30 +++++++++++++++++++++++++++ src/secondsToMinutes/test.ts | 12 +++++++++++ src/weeksToDays/index.ts | 26 +++++++++++++++++++++++ src/weeksToDays/test.ts | 12 +++++++++++ src/yearsToMonths/index.ts | 27 ++++++++++++++++++++++++ src/yearsToMonths/test.ts | 12 +++++++++++ src/yearsToQuarters/index.ts | 24 ++++++++++++++++++++++ src/yearsToQuarters/test.ts | 12 +++++++++++ 41 files changed, 843 insertions(+) create mode 100644 src/daysToWeeks/index.ts create mode 100644 src/daysToWeeks/test.ts create mode 100644 src/hoursToMilliseconds/index.ts create mode 100644 src/hoursToMilliseconds/test.ts create mode 100644 src/hoursToMinutes/index.ts create mode 100644 src/hoursToMinutes/test.ts create mode 100644 src/hoursToSeconds/index.ts create mode 100644 src/hoursToSeconds/test.ts create mode 100644 src/millisecondsToHours/index.ts create mode 100644 src/millisecondsToHours/test.ts create mode 100644 src/millisecondsToMinutes/index.ts create mode 100644 src/millisecondsToMinutes/test.ts create mode 100644 src/millisecondsToSeconds/index.ts create mode 100644 src/millisecondsToSeconds/test.ts create mode 100644 src/minutesToHours/index.ts create mode 100644 src/minutesToHours/test.ts create mode 100644 src/minutesToMilliseconds/index.ts create mode 100644 src/minutesToMilliseconds/test.ts create mode 100644 src/minutesToSeconds/index.ts create mode 100644 src/minutesToSeconds/test.ts create mode 100644 src/monthsToQuarters/index.ts create mode 100644 src/monthsToQuarters/test.ts create mode 100644 src/monthsToYears/index.ts create mode 100644 src/monthsToYears/test.ts create mode 100644 src/quartersToMonths/index.ts create mode 100644 src/quartersToMonths/test.ts create mode 100644 src/quartersToYears/index.ts create mode 100644 src/quartersToYears/test.ts create mode 100644 src/secondsToHours/index.ts create mode 100644 src/secondsToHours/test.ts create mode 100644 src/secondsToMilliseconds/index.ts create mode 100644 src/secondsToMilliseconds/test.ts create mode 100644 src/secondsToMinutes/index.ts create mode 100644 src/secondsToMinutes/test.ts create mode 100644 src/weeksToDays/index.ts create mode 100644 src/weeksToDays/test.ts create mode 100644 src/yearsToMonths/index.ts create mode 100644 src/yearsToMonths/test.ts create mode 100644 src/yearsToQuarters/index.ts create mode 100644 src/yearsToQuarters/test.ts diff --git a/src/daysToWeeks/index.ts b/src/daysToWeeks/index.ts new file mode 100644 index 0000000000..b3bfef8436 --- /dev/null +++ b/src/daysToWeeks/index.ts @@ -0,0 +1,30 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name daysToWeeks + * @category Common Helpers + * @summary Convert days to weeks. + * + * @description + * Convert days number to weeks numbers. + * + * @param { number } days - number of days to be converted. + * + * @returns {number} the number of days converted in weeks + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 14 days to weeks + * const result = daysToWeeks(14) => 2 + */ + +export default function daysToWeeks( + days: number, + +): number { + requiredArgs(1, arguments); + + const weeks = days/7; + const weeksRounded = Number(Math.round(Number(weeks + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals + + return weeksRounded; +} diff --git a/src/daysToWeeks/test.ts b/src/daysToWeeks/test.ts new file mode 100644 index 0000000000..ffd50489b5 --- /dev/null +++ b/src/daysToWeeks/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import daysToWeeks from '.' + +describe('daysToWeeks', function() { + it('converts days to weeks', function() { + const result = daysToWeeks(14); + assert.deepStrictEqual(result, 2) + }); +}); diff --git a/src/hoursToMilliseconds/index.ts b/src/hoursToMilliseconds/index.ts new file mode 100644 index 0000000000..fcd38d9b8e --- /dev/null +++ b/src/hoursToMilliseconds/index.ts @@ -0,0 +1,31 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name hoursToMilliseconds + * @category Common Helpers + * @summary Convert hours to milliseconds. + * + * @description + * Convert hours number to milliseconds numbers. + * + * @param { number } hours - number of hours to be converted. + * + * @returns {number} the number of hours converted in milliseconds + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 hours to milliseconds + * const result = hoursToMilliseconds(2) => 7,200,000 + */ + +export default function hoursToMilliseconds( + hours: number, + +): number { + requiredArgs(1, arguments); + + const MILLISECONDS_IN_1HOUR = 3600000; + + const milliseconds = hours * MILLISECONDS_IN_1HOUR; + + return milliseconds; +} diff --git a/src/hoursToMilliseconds/test.ts b/src/hoursToMilliseconds/test.ts new file mode 100644 index 0000000000..4a2f58db07 --- /dev/null +++ b/src/hoursToMilliseconds/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import hoursToMilliseconds from '.' + +describe('hoursToMilliseconds', function() { + it('converts hours to milliseconds', function() { + const result = hoursToMilliseconds(2); + assert.deepStrictEqual(result, 7200000) + }); +}); diff --git a/src/hoursToMinutes/index.ts b/src/hoursToMinutes/index.ts new file mode 100644 index 0000000000..b714d836bb --- /dev/null +++ b/src/hoursToMinutes/index.ts @@ -0,0 +1,27 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name hoursToMinutes + * @category Common Helpers + * @summary Convert hours to minutes. + * + * @description + * Convert hours number to minutes numbers. + * + * @param { number } hours - number of hours to be converted. + * + * @returns {number} the number of hours converted in minutes + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 hours to minutes + * const result = hoursToMinutes(2) => 120 + */ + +export default function hoursToMinutes( + hours: number, + +): number { + requiredArgs(1, arguments); + + return hours*60; +} diff --git a/src/hoursToMinutes/test.ts b/src/hoursToMinutes/test.ts new file mode 100644 index 0000000000..65fb40884c --- /dev/null +++ b/src/hoursToMinutes/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import hoursToMinutes from '.' + +describe('hoursToMinutes', function() { + it('converts hours to minutes', function() { + const result = hoursToMinutes(2); + assert.deepStrictEqual(result, 120) + }); +}); diff --git a/src/hoursToSeconds/index.ts b/src/hoursToSeconds/index.ts new file mode 100644 index 0000000000..300606f4ce --- /dev/null +++ b/src/hoursToSeconds/index.ts @@ -0,0 +1,27 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name hoursToSeconds + * @category Common Helpers + * @summary Convert hours to seconds. + * + * @description + * Convert hours number to seconds numbers. + * + * @param { number } hours - number of hours to be converted. + * + * @returns {number} the number of hours converted in seconds + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 hours to seconds + * const result = hoursToSeconds(2) => 7200 + */ + +export default function hoursToSeconds( + hours: number, + +): number { + requiredArgs(1, arguments); + + return hours * 3600; +} diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts new file mode 100644 index 0000000000..48dce03f3a --- /dev/null +++ b/src/hoursToSeconds/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import hoursToSeconds from '.' + +describe('hoursToSeconds', function() { + it('converts hours to minutes', function() { + const result = hoursToSeconds(2); + assert.deepStrictEqual(result, 7200) + }); +}); diff --git a/src/index.js b/src/index.js index b3c6e50c6b..9640ef760d 100644 --- a/src/index.js +++ b/src/index.js @@ -206,4 +206,24 @@ export { default as subSeconds } from './subSeconds/index' export { default as subWeeks } from './subWeeks/index' export { default as subYears } from './subYears/index' export { default as toDate } from './toDate/index' +export { default as daysToWeeks } from './daysToWeeks/index' +export { default as hoursToMilliseconds } from './hoursToMilliseconds/index' +export { default as hoursToMinutes } from './hoursToMinutes/index' +export { default as hoursToSeconds } from './hoursToSeconds/index' +export { default as millisecondsToHours } from './millisecondsToHours/index' +export { default as millisecondsToMinutes } from './millisecondsToMinutes/index' +export { default as millisecondsToSeconds } from './millisecondsToSeconds/index' +export { default as minutesToHours } from './minutesToHours/index' +export { default as minutesToMilliseconds } from './minutesToMilliseconds/index' +export { default as minutesToSeconds } from './minutesToSeconds/index' +export { default as monthsToQuarters } from './monthsToQuarters/index' +export { default as monthsToYears } from './monthsToYears/index' +export { default as quartersToMonths } from './quartersToMonths/index' +export { default as quartersToYears } from './quartersToYears/index' +export { default as secondsToHours } from './secondsToHours/index' +export { default as secondsToMilliseconds } from './secondsToMilliseconds/index' +export { default as secondsToMinutes } from './secondsToMinutes/index' +export { default as weeksToDays } from './weeksToDays/index' +export { default as yearsToMonths } from './yearsToMonths/index' +export { default as yearsToQuarters } from './yearsToQuarters/index' export * from './constants/index' diff --git a/src/millisecondsToHours/index.ts b/src/millisecondsToHours/index.ts new file mode 100644 index 0000000000..f639d5cf72 --- /dev/null +++ b/src/millisecondsToHours/index.ts @@ -0,0 +1,32 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name millisecondsToHours + * @category Common Helpers + * @summary Convert milliseconds to hours. + * + * @description + * Convert milliseconds number to hours numbers. + * + * @param { number } milliseconds - number of milliseconds to be converted. + * + * @returns {number} the number of milliseconds converted in hours + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 720000 milliseconds to hours + * const result = millisecondsToHours(7200000) => 2 + */ + +export default function millisecondsToHours( + milliseconds: number, + +): number { + requiredArgs(1, arguments); + + const MILLISECONDS_IN_1HOUR = 3600000; + + const hours = milliseconds/MILLISECONDS_IN_1HOUR; + const hoursRounded = Number(Math.round(Number(hours + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals + + return hoursRounded; +} diff --git a/src/millisecondsToHours/test.ts b/src/millisecondsToHours/test.ts new file mode 100644 index 0000000000..1ba5f97f7b --- /dev/null +++ b/src/millisecondsToHours/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import millisecondsToHours from '.' + +describe('millisecondsToHours', function() { + it('converts milliseconds to hours', function() { + const result = millisecondsToHours(7200000); + assert.deepStrictEqual(result, 2) + }); +}); diff --git a/src/millisecondsToMinutes/index.ts b/src/millisecondsToMinutes/index.ts new file mode 100644 index 0000000000..7094c6f851 --- /dev/null +++ b/src/millisecondsToMinutes/index.ts @@ -0,0 +1,32 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name millisecondsToMinutes + * @category Common Helpers + * @summary Convert milliseconds to minutes. + * + * @description + * //Converting milliseconds number to minutes numbers. + * + * @param { number } milliseconds - number of milliseconds to be converted. + * + * @returns {number} the number of milliseconds converted in minutes + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 60000 milliseconds to minutes + * const result = millisecondsToMinutes(60000) => 1 + */ + +export default function millisecondsToMinutes( + milliseconds: number, + +): number { + requiredArgs(1, arguments); + + const MILLISECONDS_IN_1MINUTE = 60000; + + const minutes = milliseconds/MILLISECONDS_IN_1MINUTE; + const minutesRounded = Number(Math.round(Number(minutes + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals + + return minutesRounded; +} diff --git a/src/millisecondsToMinutes/test.ts b/src/millisecondsToMinutes/test.ts new file mode 100644 index 0000000000..356e1d31fa --- /dev/null +++ b/src/millisecondsToMinutes/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import millisecondsToMinutes from '.' + +describe('millisecondsToMinutes', function() { + it('converts milliseconds to minutes', function() { + const result = millisecondsToMinutes(120000); + assert.deepStrictEqual(result, 2) + }); +}); diff --git a/src/millisecondsToSeconds/index.ts b/src/millisecondsToSeconds/index.ts new file mode 100644 index 0000000000..725ca64474 --- /dev/null +++ b/src/millisecondsToSeconds/index.ts @@ -0,0 +1,33 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name millisecondsToSeconds + * @category Common Helpers + * @summary Convert milliseconds to seconds. + * + * @description + * Convert milliseconds number to seconds numbers. + * + * @param { number } milliseconds - number of milliseconds to be converted. + * + * @returns {number} the number of milliseconds converted in seconds + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 1000 miliseconds to seconds + * const result = millisecondsToSeconds(1000) => 1 + */ + +export default function millisecondsToSeconds( + milliseconds: number, + +): number { + requiredArgs(1, arguments); + + const MILLISECONDS_IN_1SECOND = 1000; + + const seconds = milliseconds/MILLISECONDS_IN_1SECOND; + + const secondsRounded = Number(Math.round(Number(seconds + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals + + return secondsRounded; +} diff --git a/src/millisecondsToSeconds/test.ts b/src/millisecondsToSeconds/test.ts new file mode 100644 index 0000000000..b128c49b24 --- /dev/null +++ b/src/millisecondsToSeconds/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import millisecondsToSeconds from '.' + +describe('millisecondsToSeconds', function() { + it('converts milliseconds to seconds', function() { + const result = millisecondsToSeconds(3000); + assert.deepStrictEqual(result, 3) + }); +}); diff --git a/src/minutesToHours/index.ts b/src/minutesToHours/index.ts new file mode 100644 index 0000000000..e8df34dfd2 --- /dev/null +++ b/src/minutesToHours/index.ts @@ -0,0 +1,30 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name minutesToHours + * @category Common Helpers + * @summary Convert minutes to hours. + * + * @description + * Convert minutes number to hours numbers. + * + * @param { number } minutes - number of minutes to be converted. + * + * @returns {number} the number of minutes converted in hours + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 140 minutes to hours + * const result = minutesToHours(140) => 2.3 + */ + +export default function minutesToHours( + minutes: number, + +): number { + requiredArgs(1, arguments); + + const hours = minutes/60; + const hoursRounded = Number(Math.round(Number(hours + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals + + return hoursRounded; +} diff --git a/src/minutesToHours/test.ts b/src/minutesToHours/test.ts new file mode 100644 index 0000000000..41bb767b64 --- /dev/null +++ b/src/minutesToHours/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import minuteToHours from '.' + +describe('minuteToHours', function() { + it('converts minutes to hours', function() { + const result = minuteToHours(140); + assert.deepStrictEqual(result, 2.33) + }); +}); diff --git a/src/minutesToMilliseconds/index.ts b/src/minutesToMilliseconds/index.ts new file mode 100644 index 0000000000..2fcad54291 --- /dev/null +++ b/src/minutesToMilliseconds/index.ts @@ -0,0 +1,30 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name minutesToMilliseconds + * @category Common Helpers + * @summary Convert minutes to milliseconds. + * + * @description + * Convert minutes number to milliseconds numbers. + * + * @param { number } minutes - number of minutes to be converted. + * + * @returns {number} the number of minutes converted in milliseconds + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 minutes to milliseconds + * const result = minutesToMilliseconds(2) => 120000 + */ + +export default function minutesToMilliseconds( + minutes: number, + +): number { + requiredArgs(1, arguments); + + const MILLISECONDS_IN_1MINUTE = 60000; + + return minutes * MILLISECONDS_IN_1MINUTE; + +} diff --git a/src/minutesToMilliseconds/test.ts b/src/minutesToMilliseconds/test.ts new file mode 100644 index 0000000000..a00348d34a --- /dev/null +++ b/src/minutesToMilliseconds/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import minutesToMilliseconds from '.' + +describe('minutesToMilliseconds', function() { + it('converts minutes to milliseconds', function() { + const result = minutesToMilliseconds(2); + assert.deepStrictEqual(result, 120000) + }); +}); diff --git a/src/minutesToSeconds/index.ts b/src/minutesToSeconds/index.ts new file mode 100644 index 0000000000..61871a70b6 --- /dev/null +++ b/src/minutesToSeconds/index.ts @@ -0,0 +1,27 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name minutesToSeconds + * @category Common Helpers + * @summary Convert minutes to seconds. + * + * @description + * Convert minutes number to seconds numbers. + * + * @param { number } minutes - number of minutes to be converted. + * + * @returns {number} the number of minutes converted in seconds + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 minutes to seconds + * const result = minutesToSeconds(2) => 120 + */ + +export default function minutesToSeconds( + minutes: number, + +): number { + requiredArgs(1, arguments); + + return minutes*60; +} diff --git a/src/minutesToSeconds/test.ts b/src/minutesToSeconds/test.ts new file mode 100644 index 0000000000..8d5edaba05 --- /dev/null +++ b/src/minutesToSeconds/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import minutesToSeconds from '.' + +describe('minutesToSeconds', function() { + it('converts minutes to seconds', function() { + const result = minutesToSeconds(2); + assert.deepStrictEqual(result, 120) + }); +}); diff --git a/src/monthsToQuarters/index.ts b/src/monthsToQuarters/index.ts new file mode 100644 index 0000000000..07fee2ad25 --- /dev/null +++ b/src/monthsToQuarters/index.ts @@ -0,0 +1,31 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name monthsToQuarters + * @category Common Helpers + * @summary Convert number of months to quarters. + * + * @description + * Convert number of months to quarters. + * + * @param { number } months - number of months to be converted. + * + * @returns {number} the number of months converted in quarters + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 6 months to quarters + * const result = monthsToQuarters(6) => 2 + */ + +export default function monthsToQuarters( + months: number, + +): number { + requiredArgs(1, arguments); + + const quarters = months/3; + + const quartersRounded = Number(Math.round(Number(quarters + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals + + return quartersRounded; +} diff --git a/src/monthsToQuarters/test.ts b/src/monthsToQuarters/test.ts new file mode 100644 index 0000000000..c3ef533c7f --- /dev/null +++ b/src/monthsToQuarters/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import monthsToQuarters from '.' + +describe('monthsToQuarters', function() { + it('converts months to quarters', function() { + const result = monthsToQuarters(6); + assert.deepStrictEqual(result, 2) + }); +}); diff --git a/src/monthsToYears/index.ts b/src/monthsToYears/index.ts new file mode 100644 index 0000000000..28c1f973dd --- /dev/null +++ b/src/monthsToYears/index.ts @@ -0,0 +1,31 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name monthsToYears + * @category Common Helpers + * @summary Convert number of months to years. + * + * @description + * Convert number of months to years. + * + * @param { number } months - number of months to be converted. + * + * @returns {number} the number of months converted in years + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 40 months to years + * const result = monthsToYears(40) => 3.33 + */ + +export default function monthsToYears( + months: number, + +): number { + requiredArgs(1, arguments); + + const years = months/12; + + const yearsRounded = Number(Math.round(Number(years + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals + + return yearsRounded; +} diff --git a/src/monthsToYears/test.ts b/src/monthsToYears/test.ts new file mode 100644 index 0000000000..91de0e5f1e --- /dev/null +++ b/src/monthsToYears/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import monthsToYears from '.' + +describe('monthsToYears', function() { + it('converts months to year', function() { + const result = monthsToYears(40); + assert.deepStrictEqual(result, 3.33) + }); +}); diff --git a/src/quartersToMonths/index.ts b/src/quartersToMonths/index.ts new file mode 100644 index 0000000000..b7a7f485c4 --- /dev/null +++ b/src/quartersToMonths/index.ts @@ -0,0 +1,27 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name quartersToMonths + * @category Common Helpers + * @summary Convert number of quarters to months. + * + * @description + * Convert number of quarters to months. + * + * @param { number } quarters - number of quarters to be converted. + * + * @returns {number} the number of quarters converted in months + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 quarters to months + * const result = quartersToMonths(2) => 6 + */ + +export default function quartersToMonths( + quarters: number, + +): number { + requiredArgs(1, arguments); + + return quarters*3; +} diff --git a/src/quartersToMonths/test.ts b/src/quartersToMonths/test.ts new file mode 100644 index 0000000000..023ecf1e16 --- /dev/null +++ b/src/quartersToMonths/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import quartersToMonths from '.' + +describe('quartersToMonths', function() { + it('converts quarters to months', function() { + const result = quartersToMonths(2); + assert.deepStrictEqual(result, 6) + }); +}); diff --git a/src/quartersToYears/index.ts b/src/quartersToYears/index.ts new file mode 100644 index 0000000000..b3169b8df7 --- /dev/null +++ b/src/quartersToYears/index.ts @@ -0,0 +1,31 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name quartersToYears + * @category Common Helpers + * @summary Convert number of quarters to years. + * + * @description + * Convert number of quarters to years. + * + * @param { number } quarters - number of quarters to be converted. + * + * @returns {number} the number of quarters converted in years + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 8 quarters to years + * const result = quartersToYears(8) => 2 + */ + +export default function quartersToYears( + quarters: number, + +): number { + requiredArgs(1, arguments); + + const years = quarters/4; + + const yearsRounded = Number(Math.round(Number(years + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals + + return yearsRounded; +} diff --git a/src/quartersToYears/test.ts b/src/quartersToYears/test.ts new file mode 100644 index 0000000000..1ddae33689 --- /dev/null +++ b/src/quartersToYears/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import quartersToYears from '.' + +describe('quartersToYears', function() { + it('converts quarters to years', function() { + const result = quartersToYears(4); + assert.deepStrictEqual(result, 1) + }); +}); diff --git a/src/secondsToHours/index.ts b/src/secondsToHours/index.ts new file mode 100644 index 0000000000..36aeae4320 --- /dev/null +++ b/src/secondsToHours/index.ts @@ -0,0 +1,30 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name secondsToHours + * @category Common Helpers + * @summary Convert seconds to hours. + * + * @description + * Convert seconds number to hours numbers. + * + * @param { number } seconds - number of seconds to be converted. + * + * @returns {number} the number of seconds converted in hours + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 7200 seconds into hours + * const result = secondsToHours(7200) => 2 + */ + +export default function secondsToHours( + seconds: number, + +): number { + requiredArgs(1, arguments); + + const hours = seconds/3600; + const hoursRounded = Number(Math.round(Number(hours + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals + + return hoursRounded; +} diff --git a/src/secondsToHours/test.ts b/src/secondsToHours/test.ts new file mode 100644 index 0000000000..cd9bb8770d --- /dev/null +++ b/src/secondsToHours/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import secondsToHours from '.' + +describe('secondsToHours', function() { + it('converts seconds to hours', function() { + const result = secondsToHours(7200); + assert.deepStrictEqual(result, 2) + }); +}); diff --git a/src/secondsToMilliseconds/index.ts b/src/secondsToMilliseconds/index.ts new file mode 100644 index 0000000000..9f35df1a47 --- /dev/null +++ b/src/secondsToMilliseconds/index.ts @@ -0,0 +1,27 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name secondsToMilliseconds + * @category Common Helpers + * @summary Convert seconds to milliseconds. + * + * @description + * Convert seconds number to milliseconds numbers. + * + * @param { number } seconds - number of seconds to be converted. + * + * @returns {number} the number of seconds converted in milliseconds + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 seconds into milliseconds + * const result = secondsToMilliseconds(2) => 2000 + */ + +export default function secondsToMilliseconds( + seconds: number, + +): number { + requiredArgs(1, arguments); + + return seconds*1000; +} diff --git a/src/secondsToMilliseconds/test.ts b/src/secondsToMilliseconds/test.ts new file mode 100644 index 0000000000..3d8a65d29d --- /dev/null +++ b/src/secondsToMilliseconds/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import secondsToMilliseconds from '.' + +describe('secondsToMilliseconds', function() { + it('converts seconds to milliseconds', function() { + const result = secondsToMilliseconds(2); + assert.deepStrictEqual(result, 2000) + }); +}); diff --git a/src/secondsToMinutes/index.ts b/src/secondsToMinutes/index.ts new file mode 100644 index 0000000000..ff7c3af380 --- /dev/null +++ b/src/secondsToMinutes/index.ts @@ -0,0 +1,30 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name secondsToMinutes + * @category Common Helpers + * @summary Convert seconds to minutes. + * + * @description + * Convert seconds number to minutes numbers. + * + * @param { number } seconds - number of seconds to be converted. + * + * @returns {number} the number of seconds converted in minutes + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 120 seconds into minutes + * const result = secondsToMinutes(120) => 2 + */ + +export default function secondsToMinutes( + seconds: number, + +): number { + requiredArgs(1, arguments); + + const minutes = seconds/60; + const minutesRounded = Number(Math.round(Number(minutes + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals + + return minutesRounded; +} diff --git a/src/secondsToMinutes/test.ts b/src/secondsToMinutes/test.ts new file mode 100644 index 0000000000..e5a6230152 --- /dev/null +++ b/src/secondsToMinutes/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import secondsToMinutes from '.' + +describe('secondsToMinutes', function() { + it('converts seconds to minutes', function() { + const result = secondsToMinutes(120); + assert.deepStrictEqual(result, 2) + }); +}); diff --git a/src/weeksToDays/index.ts b/src/weeksToDays/index.ts new file mode 100644 index 0000000000..e25cec6618 --- /dev/null +++ b/src/weeksToDays/index.ts @@ -0,0 +1,26 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name weeksToDays + * @category Common Helpers + * @summary Convert weeks to days. + * + * @description + * Convert weeks number to days numbers. + * + * @param { number } weeks - number of days to be converted. + * + * @returns {number} the number of weeks converted in days + * @throws {TypeError} 1 argument required + * + * @example + * const result = weeksToDays(2) => 14 + */ + +export default function weeksToDays( + weeks: number, + +): number { + requiredArgs(1, arguments); + + return weeks*7; +} diff --git a/src/weeksToDays/test.ts b/src/weeksToDays/test.ts new file mode 100644 index 0000000000..4f09370268 --- /dev/null +++ b/src/weeksToDays/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import weeksToDays from '.' + +describe('weeksToDays', function() { + it('converts weeks to days', function() { + const result = weeksToDays(2); + assert.deepStrictEqual(result, 14) + }); +}); diff --git a/src/yearsToMonths/index.ts b/src/yearsToMonths/index.ts new file mode 100644 index 0000000000..9a818900bb --- /dev/null +++ b/src/yearsToMonths/index.ts @@ -0,0 +1,27 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name yearsToMonths + * @category Common Helpers + * @summary Convert year to months. + * + * @description + * Convert years number to months numbers. + * + * @param { number } years - number of months to be converted. + * + * @returns {number} the number of years converted in months + * @throws {TypeError} 1 argument required + * + * @example + * //Converting 2 years into months + * const result = yearsToMonths(2) => 24 + */ + +export default function yearsToMonths( + years: number, + +): number { + requiredArgs(1, arguments); + + return years*12; +} diff --git a/src/yearsToMonths/test.ts b/src/yearsToMonths/test.ts new file mode 100644 index 0000000000..3956d936b3 --- /dev/null +++ b/src/yearsToMonths/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import yearsToMonths from '.' + +describe('yearsToMonths', function() { + it('converts years to months', function() { + const result = yearsToMonths(2); + assert.deepStrictEqual(result, 24) + }); +}); diff --git a/src/yearsToQuarters/index.ts b/src/yearsToQuarters/index.ts new file mode 100644 index 0000000000..e2a905c439 --- /dev/null +++ b/src/yearsToQuarters/index.ts @@ -0,0 +1,24 @@ +import requiredArgs from '../_lib/requiredArgs/index' +/** + * @name yearsToQuarters + * @category Common Helpers + * @summary Convert years to quarters. + * + * @description + * Convert number of years to quarters. + * + * @param { number } years - number of years to be converted. + * + * @returns {number} the number of years converted in quarters + * @throws {TypeError} 1 argument required + * + * @example + * //Convertinging 1 year to quarters + * const result = yearsToQuarters(2) => 8 + */ + +export default function yearsToQuarters(years: number): number { + requiredArgs(1, arguments); + + return years*4; +} diff --git a/src/yearsToQuarters/test.ts b/src/yearsToQuarters/test.ts new file mode 100644 index 0000000000..4d8c183ab0 --- /dev/null +++ b/src/yearsToQuarters/test.ts @@ -0,0 +1,12 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'assert' +import yearsToQuarters from '.' + +describe('yearsToQuarters', function() { + it('converts years to quarters', function() { + const result = yearsToQuarters(2); + assert.deepStrictEqual(result, 8) + }); +}); From 2c56fa644b8bd2069a78f45bb6327fcc050d5e44 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Fri, 23 Apr 2021 15:26:27 +0100 Subject: [PATCH 02/32] Fix example --- src/daysToWeeks/index.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/daysToWeeks/index.ts b/src/daysToWeeks/index.ts index b3bfef8436..a9e6094356 100644 --- a/src/daysToWeeks/index.ts +++ b/src/daysToWeeks/index.ts @@ -13,18 +13,18 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 14 days to weeks - * const result = daysToWeeks(14) => 2 + * // Convert 14 days to weeks + * const result = daysToWeeks(14) + * //=> 2 */ -export default function daysToWeeks( - days: number, +export default function daysToWeeks(days: number): number { + requiredArgs(1, arguments) -): number { - requiredArgs(1, arguments); + const weeks = days / 7 + const weeksRounded = Number( + Math.round(Number(weeks + 'e' + 2)) + 'e' + 2 * -1 + ) //Precision of 2 in decimals - const weeks = days/7; - const weeksRounded = Number(Math.round(Number(weeks + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals - - return weeksRounded; + return weeksRounded } From 27145243de2461cacf4b4cee620bb5973adff38d Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Wed, 28 Apr 2021 09:34:16 -0300 Subject: [PATCH 03/32] rounding decimal results with Math floor and fixing examples --- src/daysToWeeks/index.ts | 15 +++++---------- src/hoursToMilliseconds/index.ts | 18 ++++++------------ src/hoursToMinutes/index.ts | 11 ++++------- src/hoursToSeconds/index.ts | 11 ++++------- src/millisecondsToHours/index.ts | 20 +++++++------------- src/millisecondsToMinutes/index.ts | 20 +++++++------------- src/millisecondsToSeconds/index.ts | 19 ++++++------------- src/minutesToHours/index.ts | 15 +++++---------- src/minutesToMilliseconds/index.ts | 17 ++++++----------- src/minutesToSeconds/index.ts | 11 ++++------- src/monthsToQuarters/index.ts | 16 +++++----------- src/monthsToYears/index.ts | 16 +++++----------- src/quartersToMonths/index.ts | 11 ++++------- src/quartersToYears/index.ts | 16 +++++----------- src/secondsToHours/index.ts | 15 +++++---------- src/secondsToMilliseconds/index.ts | 11 ++++------- src/secondsToMinutes/index.ts | 15 +++++---------- src/weeksToDays/index.ts | 10 ++++------ src/yearsToMonths/index.ts | 11 ++++------- src/yearsToQuarters/index.ts | 6 +++--- 20 files changed, 98 insertions(+), 186 deletions(-) diff --git a/src/daysToWeeks/index.ts b/src/daysToWeeks/index.ts index b3bfef8436..bca08eae2d 100644 --- a/src/daysToWeeks/index.ts +++ b/src/daysToWeeks/index.ts @@ -13,18 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 14 days to weeks - * const result = daysToWeeks(14) => 2 + * // Convert 15 days to weeks + * const result = daysToWeeks(15) + * //=> 2 */ -export default function daysToWeeks( - days: number, - -): number { +export default function daysToWeeks(days: number): number { requiredArgs(1, arguments); - const weeks = days/7; - const weeksRounded = Number(Math.round(Number(weeks + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals - - return weeksRounded; + return Math.floor(weeks) } diff --git a/src/hoursToMilliseconds/index.ts b/src/hoursToMilliseconds/index.ts index fcd38d9b8e..593ad3309a 100644 --- a/src/hoursToMilliseconds/index.ts +++ b/src/hoursToMilliseconds/index.ts @@ -13,19 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 hours to milliseconds - * const result = hoursToMilliseconds(2) => 7,200,000 + * //Convert 2 hours to milliseconds + * const result = hoursToMilliseconds(2) + * //=> 7200000 */ -export default function hoursToMilliseconds( - hours: number, - -): number { +export default function hoursToMilliseconds(hours: number): number { requiredArgs(1, arguments); - - const MILLISECONDS_IN_1HOUR = 3600000; - - const milliseconds = hours * MILLISECONDS_IN_1HOUR; - - return milliseconds; + // milliseconds in 1 hour => 3600000; + return hours * 3600000; } diff --git a/src/hoursToMinutes/index.ts b/src/hoursToMinutes/index.ts index b714d836bb..75d79aef83 100644 --- a/src/hoursToMinutes/index.ts +++ b/src/hoursToMinutes/index.ts @@ -13,15 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 hours to minutes - * const result = hoursToMinutes(2) => 120 + * //Convert 2 hours to minutes + * const result = hoursToMinutes(2) + * //=> 120 */ -export default function hoursToMinutes( - hours: number, - -): number { +export default function hoursToMinutes(hours: number): number { requiredArgs(1, arguments); - return hours*60; } diff --git a/src/hoursToSeconds/index.ts b/src/hoursToSeconds/index.ts index 300606f4ce..6e5ec1d88a 100644 --- a/src/hoursToSeconds/index.ts +++ b/src/hoursToSeconds/index.ts @@ -13,15 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 hours to seconds - * const result = hoursToSeconds(2) => 7200 + * //Convert 2 hours to seconds + * const result = hoursToSeconds(2) + * //=> 7200 */ -export default function hoursToSeconds( - hours: number, - -): number { +export default function hoursToSeconds(hours: number): number { requiredArgs(1, arguments); - return hours * 3600; } diff --git a/src/millisecondsToHours/index.ts b/src/millisecondsToHours/index.ts index f639d5cf72..5564c20ffb 100644 --- a/src/millisecondsToHours/index.ts +++ b/src/millisecondsToHours/index.ts @@ -13,20 +13,14 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 720000 milliseconds to hours - * const result = millisecondsToHours(7200000) => 2 + * //Convert 720000 milliseconds to hours + * const result = millisecondsToHours(7200000) + * //=> 2 */ -export default function millisecondsToHours( - milliseconds: number, - -): number { +export default function millisecondsToHours(milliseconds: number): number { requiredArgs(1, arguments); - - const MILLISECONDS_IN_1HOUR = 3600000; - - const hours = milliseconds/MILLISECONDS_IN_1HOUR; - const hoursRounded = Number(Math.round(Number(hours + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals - - return hoursRounded; + // milliseconds in 1 hour => 3600000; + const hours = milliseconds/3600000; + return Math.floor(hours); } diff --git a/src/millisecondsToMinutes/index.ts b/src/millisecondsToMinutes/index.ts index 7094c6f851..cb2d6b186e 100644 --- a/src/millisecondsToMinutes/index.ts +++ b/src/millisecondsToMinutes/index.ts @@ -13,20 +13,14 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 60000 milliseconds to minutes - * const result = millisecondsToMinutes(60000) => 1 + * //Convert 60000 milliseconds to minutes + * const result = millisecondsToMinutes(60000) + * //=> 1 */ -export default function millisecondsToMinutes( - milliseconds: number, - -): number { +export default function millisecondsToMinutes(milliseconds: number): number { requiredArgs(1, arguments); - - const MILLISECONDS_IN_1MINUTE = 60000; - - const minutes = milliseconds/MILLISECONDS_IN_1MINUTE; - const minutesRounded = Number(Math.round(Number(minutes + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals - - return minutesRounded; + // const milliseconds in 1 minute => 60000; + const minutes = milliseconds/60000; + return Math.floor(minutes); } diff --git a/src/millisecondsToSeconds/index.ts b/src/millisecondsToSeconds/index.ts index 725ca64474..b490421a86 100644 --- a/src/millisecondsToSeconds/index.ts +++ b/src/millisecondsToSeconds/index.ts @@ -14,20 +14,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * * @example * //Converting 1000 miliseconds to seconds - * const result = millisecondsToSeconds(1000) => 1 + * const result = millisecondsToSeconds(1000) + * //=> 1 */ -export default function millisecondsToSeconds( - milliseconds: number, - -): number { +export default function millisecondsToSeconds(milliseconds: number): number { requiredArgs(1, arguments); - - const MILLISECONDS_IN_1SECOND = 1000; - - const seconds = milliseconds/MILLISECONDS_IN_1SECOND; - - const secondsRounded = Number(Math.round(Number(seconds + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals - - return secondsRounded; + // milliseconds in 1 seconds => 1000; + const seconds = milliseconds/1000; + return Math.floor(seconds); } diff --git a/src/minutesToHours/index.ts b/src/minutesToHours/index.ts index e8df34dfd2..29170cc8e6 100644 --- a/src/minutesToHours/index.ts +++ b/src/minutesToHours/index.ts @@ -13,18 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 140 minutes to hours - * const result = minutesToHours(140) => 2.3 + * //Convert 140 minutes to hours + * const result = minutesToHours(140) + * //=> 2 */ -export default function minutesToHours( - minutes: number, - -): number { +export default function minutesToHours(minutes: number): number { requiredArgs(1, arguments); - const hours = minutes/60; - const hoursRounded = Number(Math.round(Number(hours + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals - - return hoursRounded; + return Math.floor(hours); } diff --git a/src/minutesToMilliseconds/index.ts b/src/minutesToMilliseconds/index.ts index 2fcad54291..83aaf641e7 100644 --- a/src/minutesToMilliseconds/index.ts +++ b/src/minutesToMilliseconds/index.ts @@ -13,18 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 minutes to milliseconds - * const result = minutesToMilliseconds(2) => 120000 + * //Convert 2 minutes to milliseconds + * const result = minutesToMilliseconds(2) + * //=> 120000 */ -export default function minutesToMilliseconds( - minutes: number, - -): number { +export default function minutesToMilliseconds(minutes: number): number { requiredArgs(1, arguments); - - const MILLISECONDS_IN_1MINUTE = 60000; - - return minutes * MILLISECONDS_IN_1MINUTE; - + // milliseconds in 1 minute => 60000; + return minutes * 60000; } diff --git a/src/minutesToSeconds/index.ts b/src/minutesToSeconds/index.ts index 61871a70b6..b521bcb46c 100644 --- a/src/minutesToSeconds/index.ts +++ b/src/minutesToSeconds/index.ts @@ -13,15 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 minutes to seconds - * const result = minutesToSeconds(2) => 120 + * //Convert 2 minutes to seconds + * const result = minutesToSeconds(2) + * //=> 120 */ -export default function minutesToSeconds( - minutes: number, - -): number { +export default function minutesToSeconds(minutes: number): number { requiredArgs(1, arguments); - return minutes*60; } diff --git a/src/monthsToQuarters/index.ts b/src/monthsToQuarters/index.ts index 07fee2ad25..2983dec76f 100644 --- a/src/monthsToQuarters/index.ts +++ b/src/monthsToQuarters/index.ts @@ -13,19 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 6 months to quarters - * const result = monthsToQuarters(6) => 2 + * //Convert 6 months to quarters + * const result = monthsToQuarters(6) + * //=> 2 */ -export default function monthsToQuarters( - months: number, - -): number { +export default function monthsToQuarters(months: number): number { requiredArgs(1, arguments); - const quarters = months/3; - - const quartersRounded = Number(Math.round(Number(quarters + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals - - return quartersRounded; + return Math.floor(quarters); } diff --git a/src/monthsToYears/index.ts b/src/monthsToYears/index.ts index 28c1f973dd..69681bc320 100644 --- a/src/monthsToYears/index.ts +++ b/src/monthsToYears/index.ts @@ -13,19 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 40 months to years - * const result = monthsToYears(40) => 3.33 + * //Convert 40 months to years + * const result = monthsToYears(40) + * //=> 3 */ -export default function monthsToYears( - months: number, - -): number { +export default function monthsToYears(months: number): number { requiredArgs(1, arguments); - const years = months/12; - - const yearsRounded = Number(Math.round(Number(years + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals - - return yearsRounded; + return Math.floor(years); } diff --git a/src/quartersToMonths/index.ts b/src/quartersToMonths/index.ts index b7a7f485c4..dbf643cf01 100644 --- a/src/quartersToMonths/index.ts +++ b/src/quartersToMonths/index.ts @@ -13,15 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 quarters to months - * const result = quartersToMonths(2) => 6 + * //Convert 2 quarters to months + * const result = quartersToMonths(2) + * //=> 6 */ -export default function quartersToMonths( - quarters: number, - -): number { +export default function quartersToMonths(quarters: number): number { requiredArgs(1, arguments); - return quarters*3; } diff --git a/src/quartersToYears/index.ts b/src/quartersToYears/index.ts index b3169b8df7..c26658b50e 100644 --- a/src/quartersToYears/index.ts +++ b/src/quartersToYears/index.ts @@ -13,19 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 8 quarters to years - * const result = quartersToYears(8) => 2 + * //Convert 8 quarters to years + * const result = quartersToYears(8) + * //=> 2 */ -export default function quartersToYears( - quarters: number, - -): number { +export default function quartersToYears(quarters: number): number { requiredArgs(1, arguments); - const years = quarters/4; - - const yearsRounded = Number(Math.round(Number(years + "e" + 2)) + "e" + 2 * -1); //Precision of 2 in decimals - - return yearsRounded; + return Math.floor(years); } diff --git a/src/secondsToHours/index.ts b/src/secondsToHours/index.ts index 36aeae4320..ded7aed2cf 100644 --- a/src/secondsToHours/index.ts +++ b/src/secondsToHours/index.ts @@ -13,18 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 7200 seconds into hours - * const result = secondsToHours(7200) => 2 + * //Convert 7200 seconds into hours + * const result = secondsToHours(7200) + * //=> 2 */ -export default function secondsToHours( - seconds: number, - -): number { +export default function secondsToHours(seconds: number): number { requiredArgs(1, arguments); - const hours = seconds/3600; - const hoursRounded = Number(Math.round(Number(hours + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals - - return hoursRounded; + return Math.floor(hours); } diff --git a/src/secondsToMilliseconds/index.ts b/src/secondsToMilliseconds/index.ts index 9f35df1a47..5202d131de 100644 --- a/src/secondsToMilliseconds/index.ts +++ b/src/secondsToMilliseconds/index.ts @@ -13,15 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 seconds into milliseconds - * const result = secondsToMilliseconds(2) => 2000 + * //Convert 2 seconds into milliseconds + * const result = secondsToMilliseconds(2) + * //=> 2000 */ -export default function secondsToMilliseconds( - seconds: number, - -): number { +export default function secondsToMilliseconds(seconds: number): number { requiredArgs(1, arguments); - return seconds*1000; } diff --git a/src/secondsToMinutes/index.ts b/src/secondsToMinutes/index.ts index ff7c3af380..3ca0743ea4 100644 --- a/src/secondsToMinutes/index.ts +++ b/src/secondsToMinutes/index.ts @@ -13,18 +13,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 120 seconds into minutes - * const result = secondsToMinutes(120) => 2 + * //Convert 120 seconds into minutes + * const result = secondsToMinutes(120) + * //=> 2 */ -export default function secondsToMinutes( - seconds: number, - -): number { +export default function secondsToMinutes(seconds: number): number { requiredArgs(1, arguments); - const minutes = seconds/60; - const minutesRounded = Number(Math.round(Number(minutes + "e" + 3)) + "e" + 3 * -1); //Precision of 3 in decimals - - return minutesRounded; + return Math.floor(minutes); } diff --git a/src/weeksToDays/index.ts b/src/weeksToDays/index.ts index e25cec6618..f5aab5f0c9 100644 --- a/src/weeksToDays/index.ts +++ b/src/weeksToDays/index.ts @@ -13,14 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * const result = weeksToDays(2) => 14 + * //Convert 2 weeks into days + * const result = weeksToDays(2) + * //=> 14 */ -export default function weeksToDays( - weeks: number, - -): number { +export default function weeksToDays(weeks: number): number { requiredArgs(1, arguments); - return weeks*7; } diff --git a/src/yearsToMonths/index.ts b/src/yearsToMonths/index.ts index 9a818900bb..65ba4dbab1 100644 --- a/src/yearsToMonths/index.ts +++ b/src/yearsToMonths/index.ts @@ -13,15 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 2 years into months - * const result = yearsToMonths(2) => 24 + * //Convert 2 years into months + * const result = yearsToMonths(2) + * //=> 24 */ -export default function yearsToMonths( - years: number, - -): number { +export default function yearsToMonths(years: number): number { requiredArgs(1, arguments); - return years*12; } diff --git a/src/yearsToQuarters/index.ts b/src/yearsToQuarters/index.ts index e2a905c439..3eb70e4879 100644 --- a/src/yearsToQuarters/index.ts +++ b/src/yearsToQuarters/index.ts @@ -13,12 +13,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convertinging 1 year to quarters - * const result = yearsToQuarters(2) => 8 + * //Convert 1 year to quarters + * const result = yearsToQuarters(2) + * //=> 8 */ export default function yearsToQuarters(years: number): number { requiredArgs(1, arguments); - return years*4; } From 97f7e5bad64d41d9d43f32948c2f98e82e68e837 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Wed, 28 Apr 2021 09:38:04 -0300 Subject: [PATCH 04/32] exercising more the tests --- src/daysToWeeks/test.ts | 20 ++++++++++++++++++-- src/hoursToMilliseconds/test.ts | 13 ++++++++++++- src/hoursToMinutes/test.ts | 12 +++++++++++- src/hoursToSeconds/test.ts | 10 +++++++++- src/millisecondsToHours/test.ts | 19 +++++++++++++++++-- src/millisecondsToMinutes/test.ts | 21 ++++++++++++++++++--- src/millisecondsToSeconds/test.ts | 17 +++++++++++++++-- src/minutesToHours/test.ts | 16 ++++++++++++++-- src/minutesToMilliseconds/test.ts | 14 +++++++++++--- src/minutesToSeconds/test.ts | 14 +++++++++++--- src/monthsToQuarters/test.ts | 18 +++++++++++++++--- src/monthsToYears/test.ts | 16 ++++++++++++++-- src/quartersToMonths/test.ts | 14 +++++++++++--- src/quartersToYears/test.ts | 14 ++++++++++++-- src/secondsToHours/test.ts | 18 +++++++++++++++--- src/secondsToMilliseconds/test.ts | 14 +++++++++++--- src/secondsToMinutes/test.ts | 18 +++++++++++++++--- src/weeksToDays/test.ts | 14 +++++++++++--- src/yearsToMonths/test.ts | 14 +++++++++++--- src/yearsToQuarters/test.ts | 14 +++++++++++--- 20 files changed, 262 insertions(+), 48 deletions(-) diff --git a/src/daysToWeeks/test.ts b/src/daysToWeeks/test.ts index ffd50489b5..8f158116ce 100644 --- a/src/daysToWeeks/test.ts +++ b/src/daysToWeeks/test.ts @@ -5,8 +5,24 @@ import assert from 'assert' import daysToWeeks from '.' describe('daysToWeeks', function() { - it('converts days to weeks', function() { - const result = daysToWeeks(14); + + it('converts 5 days to weeks', function() { + const result = daysToWeeks(5); + assert.deepStrictEqual(result, 0) + }); + + it('converts 8 days to weeks', function() { + const result = daysToWeeks(8); + assert.deepStrictEqual(result, 1) + }); + + it('converts 13 days to weeks', function() { + const result = daysToWeeks(13); + assert.deepStrictEqual(result, 1) + }); + + it('converts 15 days to weeks', function() { + const result = daysToWeeks(15); assert.deepStrictEqual(result, 2) }); }); diff --git a/src/hoursToMilliseconds/test.ts b/src/hoursToMilliseconds/test.ts index 4a2f58db07..675df284e1 100644 --- a/src/hoursToMilliseconds/test.ts +++ b/src/hoursToMilliseconds/test.ts @@ -5,8 +5,19 @@ import assert from 'assert' import hoursToMilliseconds from '.' describe('hoursToMilliseconds', function() { - it('converts hours to milliseconds', function() { + + it('converts 1 hour to milliseconds', function() { + const result = hoursToMilliseconds(1); + assert.deepStrictEqual(result, 3600000) + }); + + it('converts 2 hours to milliseconds', function() { const result = hoursToMilliseconds(2); assert.deepStrictEqual(result, 7200000) }); + + it('converts 5 hours to milliseconds', function() { + const result = hoursToMilliseconds(5); + assert.deepStrictEqual(result, 18000000) + }); }); diff --git a/src/hoursToMinutes/test.ts b/src/hoursToMinutes/test.ts index 65fb40884c..93d455e97e 100644 --- a/src/hoursToMinutes/test.ts +++ b/src/hoursToMinutes/test.ts @@ -5,8 +5,18 @@ import assert from 'assert' import hoursToMinutes from '.' describe('hoursToMinutes', function() { - it('converts hours to minutes', function() { + it('converts 2 hours to minutes', function() { const result = hoursToMinutes(2); assert.deepStrictEqual(result, 120) }); + + it('converts 5 hours to minutes', function() { + const result = hoursToMinutes(5); + assert.deepStrictEqual(result, 300) + }); + + it('converts 7 hours to minutes', function() { + const result = hoursToMinutes(7); + assert.deepStrictEqual(result, 420) + }); }); diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts index 48dce03f3a..41a5041959 100644 --- a/src/hoursToSeconds/test.ts +++ b/src/hoursToSeconds/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import hoursToSeconds from '.' describe('hoursToSeconds', function() { - it('converts hours to minutes', function() { + it('converts 2 hours to minutes', function() { const result = hoursToSeconds(2); assert.deepStrictEqual(result, 7200) }); + it('converts 5 hours to minutes', function() { + const result = hoursToSeconds(5); + assert.deepStrictEqual(result, 18000) + }); + it('converts 7 hours to minutes', function() { + const result = hoursToSeconds(7); + assert.deepStrictEqual(result, 25200) + }); }); diff --git a/src/millisecondsToHours/test.ts b/src/millisecondsToHours/test.ts index 1ba5f97f7b..16e3f32181 100644 --- a/src/millisecondsToHours/test.ts +++ b/src/millisecondsToHours/test.ts @@ -5,8 +5,23 @@ import assert from 'assert' import millisecondsToHours from '.' describe('millisecondsToHours', function() { - it('converts milliseconds to hours', function() { - const result = millisecondsToHours(7200000); + it('converts 3500000 milliseconds to hours', function() { + const result = millisecondsToHours(3500000); + assert.deepStrictEqual(result, 0) + }); + + it('converts 7000000 milliseconds to hours', function() { + const result = millisecondsToHours(7000000); + assert.deepStrictEqual(result, 1) + }); + + it('converts 7600000 milliseconds to hours', function() { + const result = millisecondsToHours(7600000); assert.deepStrictEqual(result, 2) }); + + it('converts 18000000 milliseconds to hours', function() { + const result = millisecondsToHours(18000000); + assert.deepStrictEqual(result, 5) + }); }); diff --git a/src/millisecondsToMinutes/test.ts b/src/millisecondsToMinutes/test.ts index 356e1d31fa..8b8179ff97 100644 --- a/src/millisecondsToMinutes/test.ts +++ b/src/millisecondsToMinutes/test.ts @@ -5,8 +5,23 @@ import assert from 'assert' import millisecondsToMinutes from '.' describe('millisecondsToMinutes', function() { - it('converts milliseconds to minutes', function() { - const result = millisecondsToMinutes(120000); - assert.deepStrictEqual(result, 2) + it('converts 50000 milliseconds to minutes', function() { + const result = millisecondsToMinutes(50000); + assert.deepStrictEqual(result, 0) + }); + + it('converts 65000 milliseconds to minutes', function() { + const result = millisecondsToMinutes(65000); + assert.deepStrictEqual(result, 1) + }); + + it('converts 190000 milliseconds to minutes', function() { + const result = millisecondsToMinutes(190000); + assert.deepStrictEqual(result, 3) + }); + + it('converts 310000 milliseconds to minutes', function() { + const result = millisecondsToMinutes(310000); + assert.deepStrictEqual(result, 5) }); }); diff --git a/src/millisecondsToSeconds/test.ts b/src/millisecondsToSeconds/test.ts index b128c49b24..7aad6d773f 100644 --- a/src/millisecondsToSeconds/test.ts +++ b/src/millisecondsToSeconds/test.ts @@ -5,8 +5,21 @@ import assert from 'assert' import millisecondsToSeconds from '.' describe('millisecondsToSeconds', function() { - it('converts milliseconds to seconds', function() { - const result = millisecondsToSeconds(3000); + it('converts 700 milliseconds to seconds', function() { + const result = millisecondsToSeconds(700); + assert.deepStrictEqual(result, 0) + }); + it('converts 1500 milliseconds to seconds', function() { + const result = millisecondsToSeconds(1500); + assert.deepStrictEqual(result, 1) + }); + + it('converts 3500 milliseconds to seconds', function() { + const result = millisecondsToSeconds(3500); assert.deepStrictEqual(result, 3) }); + it('converts 5500 milliseconds to seconds', function() { + const result = millisecondsToSeconds(5500); + assert.deepStrictEqual(result, 5) + }); }); diff --git a/src/minutesToHours/test.ts b/src/minutesToHours/test.ts index 41bb767b64..4ee9b1695a 100644 --- a/src/minutesToHours/test.ts +++ b/src/minutesToHours/test.ts @@ -5,8 +5,20 @@ import assert from 'assert' import minuteToHours from '.' describe('minuteToHours', function() { - it('converts minutes to hours', function() { + it('converts 50 minutes to hours', function() { + const result = minuteToHours(50); + assert.deepStrictEqual(result, 0) + }); + it('converts 90 minutes to hours', function() { + const result = minuteToHours(90); + assert.deepStrictEqual(result, 1) + }); + it('converts 140 minutes to hours', function() { const result = minuteToHours(140); - assert.deepStrictEqual(result, 2.33) + assert.deepStrictEqual(result, 2) + }); + it('converts 310 minutes to hours', function() { + const result = minuteToHours(310); + assert.deepStrictEqual(result, 5) }); }); diff --git a/src/minutesToMilliseconds/test.ts b/src/minutesToMilliseconds/test.ts index a00348d34a..e65e7ddb52 100644 --- a/src/minutesToMilliseconds/test.ts +++ b/src/minutesToMilliseconds/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import minutesToMilliseconds from '.' describe('minutesToMilliseconds', function() { - it('converts minutes to milliseconds', function() { - const result = minutesToMilliseconds(2); - assert.deepStrictEqual(result, 120000) + it('converts 1 minute to milliseconds', function() { + const result = minutesToMilliseconds(1); + assert.deepStrictEqual(result, 60000) + }); + it('converts 3 minutes to milliseconds', function() { + const result = minutesToMilliseconds(3); + assert.deepStrictEqual(result, 180000) + }); + it('converts 5 minutes to milliseconds', function() { + const result = minutesToMilliseconds(5); + assert.deepStrictEqual(result, 300000) }); }); diff --git a/src/minutesToSeconds/test.ts b/src/minutesToSeconds/test.ts index 8d5edaba05..97ff340228 100644 --- a/src/minutesToSeconds/test.ts +++ b/src/minutesToSeconds/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import minutesToSeconds from '.' describe('minutesToSeconds', function() { - it('converts minutes to seconds', function() { - const result = minutesToSeconds(2); - assert.deepStrictEqual(result, 120) + it('converts 1 minute to seconds', function() { + const result = minutesToSeconds(1); + assert.deepStrictEqual(result, 60) + }); + it('converts 3 minutes to seconds', function() { + const result = minutesToSeconds(3); + assert.deepStrictEqual(result, 180) + }); + it('converts 5 minutes to seconds', function() { + const result = minutesToSeconds(5); + assert.deepStrictEqual(result, 300) }); }); diff --git a/src/monthsToQuarters/test.ts b/src/monthsToQuarters/test.ts index c3ef533c7f..83acb44f17 100644 --- a/src/monthsToQuarters/test.ts +++ b/src/monthsToQuarters/test.ts @@ -5,8 +5,20 @@ import assert from 'assert' import monthsToQuarters from '.' describe('monthsToQuarters', function() { - it('converts months to quarters', function() { - const result = monthsToQuarters(6); - assert.deepStrictEqual(result, 2) + it('converts 2 months to quarters', function() { + const result = monthsToQuarters(2); + assert.deepStrictEqual(result, 0) + }); + it('converts 4 months to quarters', function() { + const result = monthsToQuarters(4); + assert.deepStrictEqual(result, 1) + }); + it('converts 10 months to quarters', function() { + const result = monthsToQuarters(10); + assert.deepStrictEqual(result, 3) + }); + it('converts 15 months to quarters', function() { + const result = monthsToQuarters(15); + assert.deepStrictEqual(result, 5) }); }); diff --git a/src/monthsToYears/test.ts b/src/monthsToYears/test.ts index 91de0e5f1e..f9c6fef100 100644 --- a/src/monthsToYears/test.ts +++ b/src/monthsToYears/test.ts @@ -5,8 +5,20 @@ import assert from 'assert' import monthsToYears from '.' describe('monthsToYears', function() { - it('converts months to year', function() { + it('converts 10 months to year', function() { + const result = monthsToYears(10); + assert.deepStrictEqual(result, 0) + }); + it('converts 15 months to year', function() { + const result = monthsToYears(15); + assert.deepStrictEqual(result, 1) + }); + it('converts 40 months to year', function() { const result = monthsToYears(40); - assert.deepStrictEqual(result, 3.33) + assert.deepStrictEqual(result, 3) + }); + it('converts 65 months to year', function() { + const result = monthsToYears(65); + assert.deepStrictEqual(result, 5) }); }); diff --git a/src/quartersToMonths/test.ts b/src/quartersToMonths/test.ts index 023ecf1e16..d6da369af6 100644 --- a/src/quartersToMonths/test.ts +++ b/src/quartersToMonths/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import quartersToMonths from '.' describe('quartersToMonths', function() { - it('converts quarters to months', function() { - const result = quartersToMonths(2); - assert.deepStrictEqual(result, 6) + it('converts 1 quarter to months', function() { + const result = quartersToMonths(1); + assert.deepStrictEqual(result, 3) + }); + it('converts 3 quarters to months', function() { + const result = quartersToMonths(3); + assert.deepStrictEqual(result, 9) + }); + it('converts 5 quarters to months', function() { + const result = quartersToMonths(5); + assert.deepStrictEqual(result, 15) }); }); diff --git a/src/quartersToYears/test.ts b/src/quartersToYears/test.ts index 1ddae33689..b893d95c09 100644 --- a/src/quartersToYears/test.ts +++ b/src/quartersToYears/test.ts @@ -5,8 +5,18 @@ import assert from 'assert' import quartersToYears from '.' describe('quartersToYears', function() { - it('converts quarters to years', function() { - const result = quartersToYears(4); + it('converts 3 quarters to years', function() { + const result = quartersToYears(3); + assert.deepStrictEqual(result, 0) + }); + + it('converts 5 quarters to years', function() { + const result = quartersToYears(5); assert.deepStrictEqual(result, 1) }); + + it('converts 13 quarters to years', function() { + const result = quartersToYears(13); + assert.deepStrictEqual(result, 3) + }); }); diff --git a/src/secondsToHours/test.ts b/src/secondsToHours/test.ts index cd9bb8770d..d0c38e2e7d 100644 --- a/src/secondsToHours/test.ts +++ b/src/secondsToHours/test.ts @@ -5,8 +5,20 @@ import assert from 'assert' import secondsToHours from '.' describe('secondsToHours', function() { - it('converts seconds to hours', function() { - const result = secondsToHours(7200); - assert.deepStrictEqual(result, 2) + it('converts 3000 seconds to hours', function() { + const result = secondsToHours(3000); + assert.deepStrictEqual(result, 0) + }); + it('converts 3700 seconds to hours', function() { + const result = secondsToHours(3700); + assert.deepStrictEqual(result, 1) + }); + it('converts 11000 seconds to hours', function() { + const result = secondsToHours(11000); + assert.deepStrictEqual(result, 3) + }); + it('converts 19000 seconds to hours', function() { + const result = secondsToHours(19000); + assert.deepStrictEqual(result, 5) }); }); diff --git a/src/secondsToMilliseconds/test.ts b/src/secondsToMilliseconds/test.ts index 3d8a65d29d..560e9bceb0 100644 --- a/src/secondsToMilliseconds/test.ts +++ b/src/secondsToMilliseconds/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import secondsToMilliseconds from '.' describe('secondsToMilliseconds', function() { - it('converts seconds to milliseconds', function() { - const result = secondsToMilliseconds(2); - assert.deepStrictEqual(result, 2000) + it('converts 1 second to milliseconds', function() { + const result = secondsToMilliseconds(1); + assert.deepStrictEqual(result, 1000) + }); + it('converts 3 seconds to milliseconds', function() { + const result = secondsToMilliseconds(3); + assert.deepStrictEqual(result, 3000) + }); + it('converts 5 seconds to milliseconds', function() { + const result = secondsToMilliseconds(5); + assert.deepStrictEqual(result, 5000) }); }); diff --git a/src/secondsToMinutes/test.ts b/src/secondsToMinutes/test.ts index e5a6230152..63d486c749 100644 --- a/src/secondsToMinutes/test.ts +++ b/src/secondsToMinutes/test.ts @@ -5,8 +5,20 @@ import assert from 'assert' import secondsToMinutes from '.' describe('secondsToMinutes', function() { - it('converts seconds to minutes', function() { - const result = secondsToMinutes(120); - assert.deepStrictEqual(result, 2) + it('converts 50 seconds to minutes', function() { + const result = secondsToMinutes(50); + assert.deepStrictEqual(result, 0) + }); + it('converts 70 seconds to minutes', function() { + const result = secondsToMinutes(70); + assert.deepStrictEqual(result, 1) + }); + it('converts 190 seconds to minutes', function() { + const result = secondsToMinutes(190); + assert.deepStrictEqual(result, 3) + }); + it('converts 310 seconds to minutes', function() { + const result = secondsToMinutes(310); + assert.deepStrictEqual(result, 5) }); }); diff --git a/src/weeksToDays/test.ts b/src/weeksToDays/test.ts index 4f09370268..4bbd68077b 100644 --- a/src/weeksToDays/test.ts +++ b/src/weeksToDays/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import weeksToDays from '.' describe('weeksToDays', function() { - it('converts weeks to days', function() { - const result = weeksToDays(2); - assert.deepStrictEqual(result, 14) + it('converts 1 week to days', function() { + const result = weeksToDays(1); + assert.deepStrictEqual(result, 7) + }); + it('converts 3 weeks to days', function() { + const result = weeksToDays(3); + assert.deepStrictEqual(result, 21) + }); + it('converts 5 weeks to days', function() { + const result = weeksToDays(5); + assert.deepStrictEqual(result, 35) }); }); diff --git a/src/yearsToMonths/test.ts b/src/yearsToMonths/test.ts index 3956d936b3..a7a458bd65 100644 --- a/src/yearsToMonths/test.ts +++ b/src/yearsToMonths/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import yearsToMonths from '.' describe('yearsToMonths', function() { - it('converts years to months', function() { - const result = yearsToMonths(2); - assert.deepStrictEqual(result, 24) + it('converts 1 year to months', function() { + const result = yearsToMonths(1); + assert.deepStrictEqual(result, 12) + }); + it('converts 3 years to months', function() { + const result = yearsToMonths(3); + assert.deepStrictEqual(result, 36) + }); + it('converts 5 years to months', function() { + const result = yearsToMonths(5); + assert.deepStrictEqual(result, 60) }); }); diff --git a/src/yearsToQuarters/test.ts b/src/yearsToQuarters/test.ts index 4d8c183ab0..8081126711 100644 --- a/src/yearsToQuarters/test.ts +++ b/src/yearsToQuarters/test.ts @@ -5,8 +5,16 @@ import assert from 'assert' import yearsToQuarters from '.' describe('yearsToQuarters', function() { - it('converts years to quarters', function() { - const result = yearsToQuarters(2); - assert.deepStrictEqual(result, 8) + it('converts 1 year to quarters', function() { + const result = yearsToQuarters(1); + assert.deepStrictEqual(result, 4) + }); + it('converts 3 years to quarters', function() { + const result = yearsToQuarters(3); + assert.deepStrictEqual(result, 12) + }); + it('converts 5 years to quarters', function() { + const result = yearsToQuarters(5); + assert.deepStrictEqual(result, 20) }); }); From f3a3e8ee677986e4a087bdb9ebdb38e7fe26eb27 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 14:01:50 +0100 Subject: [PATCH 05/32] Review PR - minor changes --- src/daysToWeeks/index.ts | 12 +++++++----- src/daysToWeeks/test.ts | 30 ++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/daysToWeeks/index.ts b/src/daysToWeeks/index.ts index c36de5dd9e..cc60b2ebef 100644 --- a/src/daysToWeeks/index.ts +++ b/src/daysToWeeks/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function daysToWeeks(days: number): number + /** * @name daysToWeeks - * @category Common Helpers + * @category Conversion Helpers * @summary Convert days to weeks. * * @description - * Convert days number to weeks numbers. + * Convert a number of days to a number of weeks. * * @param { number } days - number of days to be converted. * @@ -17,9 +20,8 @@ import requiredArgs from '../_lib/requiredArgs/index' * const result = daysToWeeks(14) * //=> 2 */ - export default function daysToWeeks(days: number): number { - requiredArgs(1, arguments); - const weeks = days/7; + requiredArgs(1, arguments) + const weeks = days / 7 return Math.floor(weeks) } diff --git a/src/daysToWeeks/test.ts b/src/daysToWeeks/test.ts index 8f158116ce..4594c2061c 100644 --- a/src/daysToWeeks/test.ts +++ b/src/daysToWeeks/test.ts @@ -1,28 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import daysToWeeks from '.' -describe('daysToWeeks', function() { - - it('converts 5 days to weeks', function() { - const result = daysToWeeks(5); +describe('daysToWeeks', function () { + it('converts 5 days to weeks', function () { + const result = daysToWeeks(5) assert.deepStrictEqual(result, 0) - }); + }) - it('converts 8 days to weeks', function() { - const result = daysToWeeks(8); + it('converts 8 days to weeks', function () { + const result = daysToWeeks(8) assert.deepStrictEqual(result, 1) - }); + }) - it('converts 13 days to weeks', function() { - const result = daysToWeeks(13); + it('converts 13 days to weeks', function () { + const result = daysToWeeks(13) assert.deepStrictEqual(result, 1) - }); + }) - it('converts 15 days to weeks', function() { - const result = daysToWeeks(15); + it('converts 15 days to weeks', function () { + const result = daysToWeeks(15) assert.deepStrictEqual(result, 2) - }); -}); + }) +}) From e10abce5fcd870f024eea522a81d54c74a1cad8c Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 14:19:55 +0100 Subject: [PATCH 06/32] Add minor changes Review hoursToMilliseconds --- src/hoursToMilliseconds/index.ts | 14 ++++++++------ src/hoursToMilliseconds/test.ts | 24 +++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/hoursToMilliseconds/index.ts b/src/hoursToMilliseconds/index.ts index 593ad3309a..0f36ca65ff 100644 --- a/src/hoursToMilliseconds/index.ts +++ b/src/hoursToMilliseconds/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function hoursToMilliseconds(hours: number): number + /** * @name hoursToMilliseconds - * @category Common Helpers + * @category Conversion Helpers * @summary Convert hours to milliseconds. * * @description - * Convert hours number to milliseconds numbers. + * Convert a number of hours to a number of milliseconds . * * @param { number } hours - number of hours to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 hours to milliseconds + * // Convert 2 hours to milliseconds * const result = hoursToMilliseconds(2) * //=> 7200000 */ - export default function hoursToMilliseconds(hours: number): number { - requiredArgs(1, arguments); + requiredArgs(1, arguments) // milliseconds in 1 hour => 3600000; - return hours * 3600000; + return hours * 3600000 } diff --git a/src/hoursToMilliseconds/test.ts b/src/hoursToMilliseconds/test.ts index 675df284e1..5c0f27339e 100644 --- a/src/hoursToMilliseconds/test.ts +++ b/src/hoursToMilliseconds/test.ts @@ -1,23 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import hoursToMilliseconds from '.' -describe('hoursToMilliseconds', function() { - - it('converts 1 hour to milliseconds', function() { - const result = hoursToMilliseconds(1); +describe('hoursToMilliseconds', function () { + it('converts 1 hour to milliseconds', function () { + const result = hoursToMilliseconds(1) assert.deepStrictEqual(result, 3600000) - }); + }) - it('converts 2 hours to milliseconds', function() { - const result = hoursToMilliseconds(2); + it('converts 2 hours to milliseconds', function () { + const result = hoursToMilliseconds(2) assert.deepStrictEqual(result, 7200000) - }); + }) - it('converts 5 hours to milliseconds', function() { - const result = hoursToMilliseconds(5); + it('converts 5 hours to milliseconds', function () { + const result = hoursToMilliseconds(5) assert.deepStrictEqual(result, 18000000) - }); -}); + }) +}) From b4821c707ab4f8726545f96364c38c1660062ecf Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 14:29:56 +0100 Subject: [PATCH 07/32] Add minor changes Review of hoursToMinutes --- src/hoursToMinutes/index.ts | 13 ++++++++----- src/hoursToMinutes/test.ts | 23 +++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/hoursToMinutes/index.ts b/src/hoursToMinutes/index.ts index 75d79aef83..0409791c07 100644 --- a/src/hoursToMinutes/index.ts +++ b/src/hoursToMinutes/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function hoursToMinutes(hours: number): number + /** * @name hoursToMinutes - * @category Common Helpers + * @category Conversion Helpers * @summary Convert hours to minutes. * * @description - * Convert hours number to minutes numbers. + * Convert a number of hours to a number of minutes. * * @param { number } hours - number of hours to be converted. * @@ -13,12 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 hours to minutes + * // Convert 2 hours to minutes * const result = hoursToMinutes(2) * //=> 120 */ export default function hoursToMinutes(hours: number): number { - requiredArgs(1, arguments); - return hours*60; + requiredArgs(1, arguments) + return hours * 60 } diff --git a/src/hoursToMinutes/test.ts b/src/hoursToMinutes/test.ts index 93d455e97e..1ac0971a3e 100644 --- a/src/hoursToMinutes/test.ts +++ b/src/hoursToMinutes/test.ts @@ -1,22 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import hoursToMinutes from '.' -describe('hoursToMinutes', function() { - it('converts 2 hours to minutes', function() { - const result = hoursToMinutes(2); +describe('hoursToMinutes', function () { + it('converts 2 hours to minutes', function () { + const result = hoursToMinutes(2) assert.deepStrictEqual(result, 120) - }); + }) - it('converts 5 hours to minutes', function() { - const result = hoursToMinutes(5); + it('converts 5 hours to minutes', function () { + const result = hoursToMinutes(5) assert.deepStrictEqual(result, 300) - }); + }) - it('converts 7 hours to minutes', function() { - const result = hoursToMinutes(7); + it('converts 7 hours to minutes', function () { + const result = hoursToMinutes(7) assert.deepStrictEqual(result, 420) - }); -}); + }) +}) From 44fca471da6531c086ae851f78b0cc0a6d298947 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 14:35:25 +0100 Subject: [PATCH 08/32] Add minor changes, fix docs Review of hoursToSeconds --- src/hoursToSeconds/index.ts | 13 ++++++++----- src/hoursToSeconds/test.ts | 23 +++++++++++------------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/hoursToSeconds/index.ts b/src/hoursToSeconds/index.ts index 6e5ec1d88a..91e69d027a 100644 --- a/src/hoursToSeconds/index.ts +++ b/src/hoursToSeconds/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function hoursToSeconds(hours: number): number + /** * @name hoursToSeconds - * @category Common Helpers + * @category Conversion Helpers * @summary Convert hours to seconds. * * @description - * Convert hours number to seconds numbers. + * Convert a number of hours to a number of seconds. * * @param { number } hours - number of hours to be converted. * @@ -13,12 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 hours to seconds + * // Convert 2 hours to seconds * const result = hoursToSeconds(2) * //=> 7200 */ export default function hoursToSeconds(hours: number): number { - requiredArgs(1, arguments); - return hours * 3600; + requiredArgs(1, arguments) + return hours * 3600 } diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts index 41a5041959..577b514f37 100644 --- a/src/hoursToSeconds/test.ts +++ b/src/hoursToSeconds/test.ts @@ -1,20 +1,19 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import hoursToSeconds from '.' -describe('hoursToSeconds', function() { - it('converts 2 hours to minutes', function() { - const result = hoursToSeconds(2); +describe('hoursToSeconds', function () { + it('converts 2 hours to seconds', function () { + const result = hoursToSeconds(2) assert.deepStrictEqual(result, 7200) - }); - it('converts 5 hours to minutes', function() { - const result = hoursToSeconds(5); + }) + it('converts 5 hours to seconds', function () { + const result = hoursToSeconds(5) assert.deepStrictEqual(result, 18000) - }); - it('converts 7 hours to minutes', function() { - const result = hoursToSeconds(7); + }) + it('converts 7 hours to seconds', function () { + const result = hoursToSeconds(7) assert.deepStrictEqual(result, 25200) - }); -}); + }) +}) From 1b3d5fab150a95d5bd5519c6e6245a0ce95a5277 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 15:07:15 +0100 Subject: [PATCH 09/32] Add minor changes, fix docs Review of millisecondsToHours --- src/millisecondsToHours/index.ts | 15 ++++++++------- src/millisecondsToHours/test.ts | 29 ++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/millisecondsToHours/index.ts b/src/millisecondsToHours/index.ts index 5564c20ffb..4345538ad2 100644 --- a/src/millisecondsToHours/index.ts +++ b/src/millisecondsToHours/index.ts @@ -1,11 +1,13 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function millisecondsToHours(milliseconds: number): number /** * @name millisecondsToHours - * @category Common Helpers + * @category Conversion Helpers * @summary Convert milliseconds to hours. * * @description - * Convert milliseconds number to hours numbers. + * Convert a number of milliseconds to a number of hours. * * @param { number } milliseconds - number of milliseconds to be converted. * @@ -13,14 +15,13 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 720000 milliseconds to hours + * // Convert 720000 milliseconds to hours * const result = millisecondsToHours(7200000) * //=> 2 */ - export default function millisecondsToHours(milliseconds: number): number { - requiredArgs(1, arguments); + requiredArgs(1, arguments) // milliseconds in 1 hour => 3600000; - const hours = milliseconds/3600000; - return Math.floor(hours); + const hours = milliseconds / 3600000 + return Math.floor(hours) } diff --git a/src/millisecondsToHours/test.ts b/src/millisecondsToHours/test.ts index 16e3f32181..3ebf993c20 100644 --- a/src/millisecondsToHours/test.ts +++ b/src/millisecondsToHours/test.ts @@ -1,27 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import millisecondsToHours from '.' -describe('millisecondsToHours', function() { - it('converts 3500000 milliseconds to hours', function() { - const result = millisecondsToHours(3500000); +describe('millisecondsToHours', function () { + it('converts 3500000 milliseconds to hours', function () { + const result = millisecondsToHours(3500000) assert.deepStrictEqual(result, 0) - }); + }) - it('converts 7000000 milliseconds to hours', function() { - const result = millisecondsToHours(7000000); + it('converts 7000000 milliseconds to hours', function () { + const result = millisecondsToHours(7000000) assert.deepStrictEqual(result, 1) - }); + }) - it('converts 7600000 milliseconds to hours', function() { - const result = millisecondsToHours(7600000); + it('converts 7600000 milliseconds to hours', function () { + const result = millisecondsToHours(7600000) assert.deepStrictEqual(result, 2) - }); + }) - it('converts 18000000 milliseconds to hours', function() { - const result = millisecondsToHours(18000000); + it('converts 18000000 milliseconds to hours', function () { + const result = millisecondsToHours(18000000) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From 95515980fe290dec13cf8611cfb9286320c5dfd3 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 20:23:49 +0100 Subject: [PATCH 10/32] Add minor changes, doc fix Review millisecondsToMinutes --- src/millisecondsToMinutes/index.ts | 17 ++++++++++------- src/millisecondsToMinutes/test.ts | 29 ++++++++++++++--------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/millisecondsToMinutes/index.ts b/src/millisecondsToMinutes/index.ts index cb2d6b186e..52d4e193e9 100644 --- a/src/millisecondsToMinutes/index.ts +++ b/src/millisecondsToMinutes/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function millisecondsToMinutes(milliseconds: number): number + /** * @name millisecondsToMinutes - * @category Common Helpers + * @category Conversion Helpers * @summary Convert milliseconds to minutes. * * @description - * //Converting milliseconds number to minutes numbers. + * Convert a number of milliseconds to a number of minutes. * * @param { number } milliseconds - number of milliseconds to be converted. * @@ -13,14 +16,14 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 60000 milliseconds to minutes + * // Convert 60000 milliseconds to minutes * const result = millisecondsToMinutes(60000) * //=> 1 */ export default function millisecondsToMinutes(milliseconds: number): number { - requiredArgs(1, arguments); - // const milliseconds in 1 minute => 60000; - const minutes = milliseconds/60000; - return Math.floor(minutes); + requiredArgs(1, arguments) + // 60000 milliseconds in 1 minute + const minutes = milliseconds / 60000 + return Math.floor(minutes) } diff --git a/src/millisecondsToMinutes/test.ts b/src/millisecondsToMinutes/test.ts index 8b8179ff97..8b8a1021f2 100644 --- a/src/millisecondsToMinutes/test.ts +++ b/src/millisecondsToMinutes/test.ts @@ -1,27 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import millisecondsToMinutes from '.' -describe('millisecondsToMinutes', function() { - it('converts 50000 milliseconds to minutes', function() { - const result = millisecondsToMinutes(50000); +describe('millisecondsToMinutes', function () { + it('converts 50000 milliseconds to minutes', function () { + const result = millisecondsToMinutes(50000) assert.deepStrictEqual(result, 0) - }); + }) - it('converts 65000 milliseconds to minutes', function() { - const result = millisecondsToMinutes(65000); + it('converts 65000 milliseconds to minutes', function () { + const result = millisecondsToMinutes(65000) assert.deepStrictEqual(result, 1) - }); + }) - it('converts 190000 milliseconds to minutes', function() { - const result = millisecondsToMinutes(190000); + it('converts 190000 milliseconds to minutes', function () { + const result = millisecondsToMinutes(190000) assert.deepStrictEqual(result, 3) - }); + }) - it('converts 310000 milliseconds to minutes', function() { - const result = millisecondsToMinutes(310000); + it('converts 310000 milliseconds to minutes', function () { + const result = millisecondsToMinutes(310000) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From e4a0cfccfbcb5102c4dd018f954a6b8706b7543b Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 20:29:45 +0100 Subject: [PATCH 11/32] Add minor changes, fix docs Review of millisecondsToSeconds --- src/millisecondsToSeconds/index.ts | 15 +++++++++------ src/millisecondsToSeconds/test.ts | 29 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/millisecondsToSeconds/index.ts b/src/millisecondsToSeconds/index.ts index b490421a86..05a5b414b9 100644 --- a/src/millisecondsToSeconds/index.ts +++ b/src/millisecondsToSeconds/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function millisecondsToSeconds(milliseconds: number): number + /** * @name millisecondsToSeconds - * @category Common Helpers + * @category Conversion Helpers * @summary Convert milliseconds to seconds. * * @description - * Convert milliseconds number to seconds numbers. + * Convert a number of milliseconds to a number of seconds. * * @param { number } milliseconds - number of milliseconds to be converted. * @@ -13,14 +16,14 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Converting 1000 miliseconds to seconds + * // Convert 1000 miliseconds to seconds * const result = millisecondsToSeconds(1000) * //=> 1 */ export default function millisecondsToSeconds(milliseconds: number): number { - requiredArgs(1, arguments); + requiredArgs(1, arguments) // milliseconds in 1 seconds => 1000; - const seconds = milliseconds/1000; - return Math.floor(seconds); + const seconds = milliseconds / 1000 + return Math.floor(seconds) } diff --git a/src/millisecondsToSeconds/test.ts b/src/millisecondsToSeconds/test.ts index 7aad6d773f..d6b8bfb7b9 100644 --- a/src/millisecondsToSeconds/test.ts +++ b/src/millisecondsToSeconds/test.ts @@ -1,25 +1,24 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import millisecondsToSeconds from '.' -describe('millisecondsToSeconds', function() { - it('converts 700 milliseconds to seconds', function() { - const result = millisecondsToSeconds(700); +describe('millisecondsToSeconds', function () { + it('converts 700 milliseconds to seconds', function () { + const result = millisecondsToSeconds(700) assert.deepStrictEqual(result, 0) - }); - it('converts 1500 milliseconds to seconds', function() { - const result = millisecondsToSeconds(1500); + }) + it('converts 1500 milliseconds to seconds', function () { + const result = millisecondsToSeconds(1500) assert.deepStrictEqual(result, 1) - }); + }) - it('converts 3500 milliseconds to seconds', function() { - const result = millisecondsToSeconds(3500); + it('converts 3500 milliseconds to seconds', function () { + const result = millisecondsToSeconds(3500) assert.deepStrictEqual(result, 3) - }); - it('converts 5500 milliseconds to seconds', function() { - const result = millisecondsToSeconds(5500); + }) + it('converts 5500 milliseconds to seconds', function () { + const result = millisecondsToSeconds(5500) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From 98afdc166f018a938c78a3a247036d2db1d2a397 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 20:33:40 +0100 Subject: [PATCH 12/32] Add minor changes, fix docs Review of minuteToHours --- src/minutesToHours/index.ts | 16 +++++++++------- src/minutesToHours/test.ts | 32 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/minutesToHours/index.ts b/src/minutesToHours/index.ts index 29170cc8e6..b6ef04fe14 100644 --- a/src/minutesToHours/index.ts +++ b/src/minutesToHours/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function minutesToHours(minutes: number): number + /** * @name minutesToHours - * @category Common Helpers + * @category Conversion Helpers * @summary Convert minutes to hours. * * @description - * Convert minutes number to hours numbers. + * Convert a number of minutes to a number of hours. * * @param { number } minutes - number of minutes to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 140 minutes to hours + * // Convert 140 minutes to hours * const result = minutesToHours(140) * //=> 2 */ - export default function minutesToHours(minutes: number): number { - requiredArgs(1, arguments); - const hours = minutes/60; - return Math.floor(hours); + requiredArgs(1, arguments) + const hours = minutes / 60 + return Math.floor(hours) } diff --git a/src/minutesToHours/test.ts b/src/minutesToHours/test.ts index 4ee9b1695a..9d50cc06b7 100644 --- a/src/minutesToHours/test.ts +++ b/src/minutesToHours/test.ts @@ -1,24 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import minuteToHours from '.' -describe('minuteToHours', function() { - it('converts 50 minutes to hours', function() { - const result = minuteToHours(50); +describe('minuteToHours', function () { + it('converts 50 minutes to hours', function () { + const result = minuteToHours(50) assert.deepStrictEqual(result, 0) - }); - it('converts 90 minutes to hours', function() { - const result = minuteToHours(90); + }) + + it('converts 90 minutes to hours', function () { + const result = minuteToHours(90) assert.deepStrictEqual(result, 1) - }); - it('converts 140 minutes to hours', function() { - const result = minuteToHours(140); + }) + + it('converts 140 minutes to hours', function () { + const result = minuteToHours(140) assert.deepStrictEqual(result, 2) - }); - it('converts 310 minutes to hours', function() { - const result = minuteToHours(310); + }) + + it('converts 310 minutes to hours', function () { + const result = minuteToHours(310) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From c0384e85e57c187acdd0efbba93b45777c0f9c70 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 20:41:40 +0100 Subject: [PATCH 13/32] Add minor changes, fix docs Review minutesToMilliseconds --- src/minutesToMilliseconds/index.ts | 14 ++++++++------ src/minutesToMilliseconds/test.ts | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/minutesToMilliseconds/index.ts b/src/minutesToMilliseconds/index.ts index 83aaf641e7..f88063d32d 100644 --- a/src/minutesToMilliseconds/index.ts +++ b/src/minutesToMilliseconds/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function minutesToMilliseconds(minutes: number): number + /** * @name minutesToMilliseconds - * @category Common Helpers + * @category Conversion Helpers * @summary Convert minutes to milliseconds. * * @description - * Convert minutes number to milliseconds numbers. + * Convert a number of minutes to a number of milliseconds. * * @param { number } minutes - number of minutes to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 minutes to milliseconds + * // Convert 2 minutes to milliseconds * const result = minutesToMilliseconds(2) * //=> 120000 */ - export default function minutesToMilliseconds(minutes: number): number { - requiredArgs(1, arguments); + requiredArgs(1, arguments) // milliseconds in 1 minute => 60000; - return minutes * 60000; + return minutes * 60000 } diff --git a/src/minutesToMilliseconds/test.ts b/src/minutesToMilliseconds/test.ts index e65e7ddb52..0444b9aff6 100644 --- a/src/minutesToMilliseconds/test.ts +++ b/src/minutesToMilliseconds/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import minutesToMilliseconds from '.' -describe('minutesToMilliseconds', function() { - it('converts 1 minute to milliseconds', function() { - const result = minutesToMilliseconds(1); +describe('minutesToMilliseconds', function () { + it('converts 1 minute to milliseconds', function () { + const result = minutesToMilliseconds(1) assert.deepStrictEqual(result, 60000) - }); - it('converts 3 minutes to milliseconds', function() { - const result = minutesToMilliseconds(3); + }) + + it('converts 3 minutes to milliseconds', function () { + const result = minutesToMilliseconds(3) assert.deepStrictEqual(result, 180000) - }); - it('converts 5 minutes to milliseconds', function() { - const result = minutesToMilliseconds(5); + }) + + it('converts 5 minutes to milliseconds', function () { + const result = minutesToMilliseconds(5) assert.deepStrictEqual(result, 300000) - }); -}); + }) +}) From 4512e0f679d15b6b49bb0435eeb00e351099be49 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 20:57:22 +0100 Subject: [PATCH 14/32] Add minor changes, fix docs Review minutesToSeconds --- src/minutesToSeconds/index.ts | 14 ++++++++------ src/minutesToSeconds/test.ts | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/minutesToSeconds/index.ts b/src/minutesToSeconds/index.ts index b521bcb46c..8b4014a8a0 100644 --- a/src/minutesToSeconds/index.ts +++ b/src/minutesToSeconds/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function minutesToSeconds(minutes: number): number + /** * @name minutesToSeconds - * @category Common Helpers + * @category Conversion Helpers * @summary Convert minutes to seconds. * * @description - * Convert minutes number to seconds numbers. + * Convert a number of minutes to a number of seconds. * * @param { number } minutes - number of minutes to be converted. * @@ -13,12 +16,11 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 minutes to seconds + * // Convert 2 minutes to seconds * const result = minutesToSeconds(2) * //=> 120 */ - export default function minutesToSeconds(minutes: number): number { - requiredArgs(1, arguments); - return minutes*60; + requiredArgs(1, arguments) + return minutes * 60 } diff --git a/src/minutesToSeconds/test.ts b/src/minutesToSeconds/test.ts index 97ff340228..01be3a2989 100644 --- a/src/minutesToSeconds/test.ts +++ b/src/minutesToSeconds/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import minutesToSeconds from '.' -describe('minutesToSeconds', function() { - it('converts 1 minute to seconds', function() { - const result = minutesToSeconds(1); +describe('minutesToSeconds', function () { + it('converts 1 minute to seconds', function () { + const result = minutesToSeconds(1) assert.deepStrictEqual(result, 60) - }); - it('converts 3 minutes to seconds', function() { - const result = minutesToSeconds(3); + }) + + it('converts 3 minutes to seconds', function () { + const result = minutesToSeconds(3) assert.deepStrictEqual(result, 180) - }); - it('converts 5 minutes to seconds', function() { - const result = minutesToSeconds(5); + }) + + it('converts 5 minutes to seconds', function () { + const result = minutesToSeconds(5) assert.deepStrictEqual(result, 300) - }); -}); + }) +}) From ba00a35b4bc06e8e301037c2da48a42bd898e7b2 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:00:10 +0100 Subject: [PATCH 15/32] Add minor changes, fix docs Review of monthsToQuarters --- src/monthsToQuarters/index.ts | 16 +++++++++------- src/monthsToQuarters/test.ts | 32 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/monthsToQuarters/index.ts b/src/monthsToQuarters/index.ts index 2983dec76f..f60363fb9b 100644 --- a/src/monthsToQuarters/index.ts +++ b/src/monthsToQuarters/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function monthsToQuarters(months: number): number + /** * @name monthsToQuarters - * @category Common Helpers + * @category Conversion Helpers * @summary Convert number of months to quarters. * * @description - * Convert number of months to quarters. + * Convert a number of months to a number of quarters. * * @param { number } months - number of months to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 6 months to quarters + * // Convert 6 months to quarters * const result = monthsToQuarters(6) * //=> 2 */ - export default function monthsToQuarters(months: number): number { - requiredArgs(1, arguments); - const quarters = months/3; - return Math.floor(quarters); + requiredArgs(1, arguments) + const quarters = months / 3 + return Math.floor(quarters) } diff --git a/src/monthsToQuarters/test.ts b/src/monthsToQuarters/test.ts index 83acb44f17..163bf663d3 100644 --- a/src/monthsToQuarters/test.ts +++ b/src/monthsToQuarters/test.ts @@ -1,24 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import monthsToQuarters from '.' -describe('monthsToQuarters', function() { - it('converts 2 months to quarters', function() { - const result = monthsToQuarters(2); +describe('monthsToQuarters', function () { + it('converts 2 months to quarters', function () { + const result = monthsToQuarters(2) assert.deepStrictEqual(result, 0) - }); - it('converts 4 months to quarters', function() { - const result = monthsToQuarters(4); + }) + + it('converts 4 months to quarters', function () { + const result = monthsToQuarters(4) assert.deepStrictEqual(result, 1) - }); - it('converts 10 months to quarters', function() { - const result = monthsToQuarters(10); + }) + + it('converts 10 months to quarters', function () { + const result = monthsToQuarters(10) assert.deepStrictEqual(result, 3) - }); - it('converts 15 months to quarters', function() { - const result = monthsToQuarters(15); + }) + + it('converts 15 months to quarters', function () { + const result = monthsToQuarters(15) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From 66ff56afbb1463ec843d4a9081c5e20171ef7fc9 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:06:07 +0100 Subject: [PATCH 16/32] Add minor changes, fix docs Review monthsToYears --- src/monthsToYears/index.ts | 16 +++++++++------- src/monthsToYears/test.ts | 32 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/monthsToYears/index.ts b/src/monthsToYears/index.ts index 69681bc320..b83d8ae1bd 100644 --- a/src/monthsToYears/index.ts +++ b/src/monthsToYears/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function monthsToYears(months: number): number + /** * @name monthsToYears - * @category Common Helpers + * @category Conversion Helpers * @summary Convert number of months to years. * * @description - * Convert number of months to years. + * Convert a number of months to a number of years. * * @param { number } months - number of months to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 40 months to years + * // Convert 40 months to years * const result = monthsToYears(40) * //=> 3 */ - export default function monthsToYears(months: number): number { - requiredArgs(1, arguments); - const years = months/12; - return Math.floor(years); + requiredArgs(1, arguments) + const years = months / 12 + return Math.floor(years) } diff --git a/src/monthsToYears/test.ts b/src/monthsToYears/test.ts index f9c6fef100..8f2c73bfbf 100644 --- a/src/monthsToYears/test.ts +++ b/src/monthsToYears/test.ts @@ -1,24 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import monthsToYears from '.' -describe('monthsToYears', function() { - it('converts 10 months to year', function() { - const result = monthsToYears(10); +describe('monthsToYears', function () { + it('converts 10 months to year', function () { + const result = monthsToYears(10) assert.deepStrictEqual(result, 0) - }); - it('converts 15 months to year', function() { - const result = monthsToYears(15); + }) + + it('converts 15 months to year', function () { + const result = monthsToYears(15) assert.deepStrictEqual(result, 1) - }); - it('converts 40 months to year', function() { - const result = monthsToYears(40); + }) + + it('converts 40 months to year', function () { + const result = monthsToYears(40) assert.deepStrictEqual(result, 3) - }); - it('converts 65 months to year', function() { - const result = monthsToYears(65); + }) + + it('converts 65 months to year', function () { + const result = monthsToYears(65) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From 24db4fe4406305aa1f25ab7b8ce44849b87b2630 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:09:06 +0100 Subject: [PATCH 17/32] Add minor changes, fix docs quartersToMonths --- src/quartersToMonths/index.ts | 14 ++++++++------ src/quartersToMonths/test.ts | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/quartersToMonths/index.ts b/src/quartersToMonths/index.ts index dbf643cf01..026ee6cd5a 100644 --- a/src/quartersToMonths/index.ts +++ b/src/quartersToMonths/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function quartersToMonths(quarters: number): number + /** * @name quartersToMonths - * @category Common Helpers + * @category Conversion Helpers * @summary Convert number of quarters to months. * * @description - * Convert number of quarters to months. + * Convert a number of quarters to a number of months. * * @param { number } quarters - number of quarters to be converted. * @@ -13,12 +16,11 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 quarters to months + * // Convert 2 quarters to months * const result = quartersToMonths(2) * //=> 6 */ - export default function quartersToMonths(quarters: number): number { - requiredArgs(1, arguments); - return quarters*3; + requiredArgs(1, arguments) + return quarters * 3 } diff --git a/src/quartersToMonths/test.ts b/src/quartersToMonths/test.ts index d6da369af6..b6e8b59182 100644 --- a/src/quartersToMonths/test.ts +++ b/src/quartersToMonths/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import quartersToMonths from '.' -describe('quartersToMonths', function() { - it('converts 1 quarter to months', function() { - const result = quartersToMonths(1); +describe('quartersToMonths', function () { + it('converts 1 quarter to months', function () { + const result = quartersToMonths(1) assert.deepStrictEqual(result, 3) - }); - it('converts 3 quarters to months', function() { - const result = quartersToMonths(3); + }) + + it('converts 3 quarters to months', function () { + const result = quartersToMonths(3) assert.deepStrictEqual(result, 9) - }); - it('converts 5 quarters to months', function() { - const result = quartersToMonths(5); + }) + + it('converts 5 quarters to months', function () { + const result = quartersToMonths(5) assert.deepStrictEqual(result, 15) - }); -}); + }) +}) From 01441b476b14038c71623e64b8ed3540f690a13e Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:19:39 +0100 Subject: [PATCH 18/32] Add minor changes, fix docs Review quartersToYears --- src/quartersToYears/index.ts | 16 +++++++++------- src/quartersToYears/test.ts | 23 +++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/quartersToYears/index.ts b/src/quartersToYears/index.ts index c26658b50e..a78711c448 100644 --- a/src/quartersToYears/index.ts +++ b/src/quartersToYears/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function quartersToYears(quarters: number): number + /** * @name quartersToYears - * @category Common Helpers + * @category Conversion Helpers * @summary Convert number of quarters to years. * * @description - * Convert number of quarters to years. + * Convert a number of quarters to a number of years. * * @param { number } quarters - number of quarters to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 8 quarters to years + * // Convert 8 quarters to years * const result = quartersToYears(8) * //=> 2 */ - export default function quartersToYears(quarters: number): number { - requiredArgs(1, arguments); - const years = quarters/4; - return Math.floor(years); + requiredArgs(1, arguments) + const years = quarters / 4 + return Math.floor(years) } diff --git a/src/quartersToYears/test.ts b/src/quartersToYears/test.ts index b893d95c09..99440f2bff 100644 --- a/src/quartersToYears/test.ts +++ b/src/quartersToYears/test.ts @@ -1,22 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import quartersToYears from '.' -describe('quartersToYears', function() { - it('converts 3 quarters to years', function() { - const result = quartersToYears(3); +describe('quartersToYears', function () { + it('converts 3 quarters to years', function () { + const result = quartersToYears(3) assert.deepStrictEqual(result, 0) - }); + }) - it('converts 5 quarters to years', function() { - const result = quartersToYears(5); + it('converts 5 quarters to years', function () { + const result = quartersToYears(5) assert.deepStrictEqual(result, 1) - }); + }) - it('converts 13 quarters to years', function() { - const result = quartersToYears(13); + it('converts 13 quarters to years', function () { + const result = quartersToYears(13) assert.deepStrictEqual(result, 3) - }); -}); + }) +}) From 31bd40ed441c12ebbd89f20bb47d70228b4a1002 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:24:34 +0100 Subject: [PATCH 19/32] Add minor changes, fix docs Review secondsToHours --- src/secondsToHours/index.ts | 16 +++++++++------- src/secondsToHours/test.ts | 32 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/secondsToHours/index.ts b/src/secondsToHours/index.ts index ded7aed2cf..7b893f1218 100644 --- a/src/secondsToHours/index.ts +++ b/src/secondsToHours/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function secondsToHours(seconds: number): number + /** * @name secondsToHours - * @category Common Helpers + * @category Conversion Helpers * @summary Convert seconds to hours. * * @description - * Convert seconds number to hours numbers. + * Convert a number of seconds to a number of hours. * * @param { number } seconds - number of seconds to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 7200 seconds into hours + * // Convert 7200 seconds into hours * const result = secondsToHours(7200) * //=> 2 */ - export default function secondsToHours(seconds: number): number { - requiredArgs(1, arguments); - const hours = seconds/3600; - return Math.floor(hours); + requiredArgs(1, arguments) + const hours = seconds / 3600 + return Math.floor(hours) } diff --git a/src/secondsToHours/test.ts b/src/secondsToHours/test.ts index d0c38e2e7d..84caa119f5 100644 --- a/src/secondsToHours/test.ts +++ b/src/secondsToHours/test.ts @@ -1,24 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import secondsToHours from '.' -describe('secondsToHours', function() { - it('converts 3000 seconds to hours', function() { - const result = secondsToHours(3000); +describe('secondsToHours', function () { + it('converts 3000 seconds to hours', function () { + const result = secondsToHours(3000) assert.deepStrictEqual(result, 0) - }); - it('converts 3700 seconds to hours', function() { - const result = secondsToHours(3700); + }) + + it('converts 3700 seconds to hours', function () { + const result = secondsToHours(3700) assert.deepStrictEqual(result, 1) - }); - it('converts 11000 seconds to hours', function() { - const result = secondsToHours(11000); + }) + + it('converts 11000 seconds to hours', function () { + const result = secondsToHours(11000) assert.deepStrictEqual(result, 3) - }); - it('converts 19000 seconds to hours', function() { - const result = secondsToHours(19000); + }) + + it('converts 19000 seconds to hours', function () { + const result = secondsToHours(19000) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From 1c0bcfac9fbdbe0e97d0148dd73fc6b6057f16bb Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:27:59 +0100 Subject: [PATCH 20/32] Add minor changes, fix docs Review secondsToMilliseconds --- src/secondsToMilliseconds/index.ts | 14 ++++++++------ src/secondsToMilliseconds/test.ts | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/secondsToMilliseconds/index.ts b/src/secondsToMilliseconds/index.ts index 5202d131de..6c1bdfb250 100644 --- a/src/secondsToMilliseconds/index.ts +++ b/src/secondsToMilliseconds/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function secondsToMilliseconds(seconds: number): number + /** * @name secondsToMilliseconds - * @category Common Helpers + * @category Conversion Helpers * @summary Convert seconds to milliseconds. * * @description - * Convert seconds number to milliseconds numbers. + * Convert a number of seconds to a number of milliseconds. * * @param { number } seconds - number of seconds to be converted. * @@ -13,12 +16,11 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 seconds into milliseconds + * // Convert 2 seconds into milliseconds * const result = secondsToMilliseconds(2) * //=> 2000 */ - export default function secondsToMilliseconds(seconds: number): number { - requiredArgs(1, arguments); - return seconds*1000; + requiredArgs(1, arguments) + return seconds * 1000 } diff --git a/src/secondsToMilliseconds/test.ts b/src/secondsToMilliseconds/test.ts index 560e9bceb0..fb865d015c 100644 --- a/src/secondsToMilliseconds/test.ts +++ b/src/secondsToMilliseconds/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import secondsToMilliseconds from '.' -describe('secondsToMilliseconds', function() { - it('converts 1 second to milliseconds', function() { - const result = secondsToMilliseconds(1); +describe('secondsToMilliseconds', function () { + it('converts 1 second to milliseconds', function () { + const result = secondsToMilliseconds(1) assert.deepStrictEqual(result, 1000) - }); - it('converts 3 seconds to milliseconds', function() { - const result = secondsToMilliseconds(3); + }) + + it('converts 3 seconds to milliseconds', function () { + const result = secondsToMilliseconds(3) assert.deepStrictEqual(result, 3000) - }); - it('converts 5 seconds to milliseconds', function() { - const result = secondsToMilliseconds(5); + }) + + it('converts 5 seconds to milliseconds', function () { + const result = secondsToMilliseconds(5) assert.deepStrictEqual(result, 5000) - }); -}); + }) +}) From 68cdb7fe1584033fd2661a47f18e736fe32cece1 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:30:40 +0100 Subject: [PATCH 21/32] Add minor changes, fix docs Review secondsToMinutes --- src/secondsToMinutes/index.ts | 16 +++++++++------- src/secondsToMinutes/test.ts | 32 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/secondsToMinutes/index.ts b/src/secondsToMinutes/index.ts index 3ca0743ea4..9051a1a079 100644 --- a/src/secondsToMinutes/index.ts +++ b/src/secondsToMinutes/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function secondsToMinutes(seconds: number): number + /** * @name secondsToMinutes - * @category Common Helpers + * @category Conversion Helpers * @summary Convert seconds to minutes. * * @description - * Convert seconds number to minutes numbers. + * Convert a number of seconds to a number of minutes. * * @param { number } seconds - number of seconds to be converted. * @@ -13,13 +16,12 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 120 seconds into minutes + * // Convert 120 seconds into minutes * const result = secondsToMinutes(120) * //=> 2 */ - export default function secondsToMinutes(seconds: number): number { - requiredArgs(1, arguments); - const minutes = seconds/60; - return Math.floor(minutes); + requiredArgs(1, arguments) + const minutes = seconds / 60 + return Math.floor(minutes) } diff --git a/src/secondsToMinutes/test.ts b/src/secondsToMinutes/test.ts index 63d486c749..f5ddb8cff8 100644 --- a/src/secondsToMinutes/test.ts +++ b/src/secondsToMinutes/test.ts @@ -1,24 +1,26 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import secondsToMinutes from '.' -describe('secondsToMinutes', function() { - it('converts 50 seconds to minutes', function() { - const result = secondsToMinutes(50); +describe('secondsToMinutes', function () { + it('converts 50 seconds to minutes', function () { + const result = secondsToMinutes(50) assert.deepStrictEqual(result, 0) - }); - it('converts 70 seconds to minutes', function() { - const result = secondsToMinutes(70); + }) + + it('converts 70 seconds to minutes', function () { + const result = secondsToMinutes(70) assert.deepStrictEqual(result, 1) - }); - it('converts 190 seconds to minutes', function() { - const result = secondsToMinutes(190); + }) + + it('converts 190 seconds to minutes', function () { + const result = secondsToMinutes(190) assert.deepStrictEqual(result, 3) - }); - it('converts 310 seconds to minutes', function() { - const result = secondsToMinutes(310); + }) + + it('converts 310 seconds to minutes', function () { + const result = secondsToMinutes(310) assert.deepStrictEqual(result, 5) - }); -}); + }) +}) From 03cbd906949f1ccff9f8191681869f327cf8673e Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:33:57 +0100 Subject: [PATCH 22/32] Add minor changes, fix docs --- src/weeksToDays/index.ts | 14 ++++++++------ src/weeksToDays/test.ts | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/weeksToDays/index.ts b/src/weeksToDays/index.ts index f5aab5f0c9..2b36624783 100644 --- a/src/weeksToDays/index.ts +++ b/src/weeksToDays/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function weeksToDays(weeks: number): number + /** * @name weeksToDays - * @category Common Helpers + * @category Conversion Helpers * @summary Convert weeks to days. * * @description - * Convert weeks number to days numbers. + * Convert a number of weeks to a number of days. * * @param { number } weeks - number of days to be converted. * @@ -13,12 +16,11 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 2 weeks into days + * // Convert 2 weeks into days * const result = weeksToDays(2) * //=> 14 */ - export default function weeksToDays(weeks: number): number { - requiredArgs(1, arguments); - return weeks*7; + requiredArgs(1, arguments) + return weeks * 7 } diff --git a/src/weeksToDays/test.ts b/src/weeksToDays/test.ts index 4bbd68077b..030d06dba0 100644 --- a/src/weeksToDays/test.ts +++ b/src/weeksToDays/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import weeksToDays from '.' -describe('weeksToDays', function() { - it('converts 1 week to days', function() { - const result = weeksToDays(1); +describe('weeksToDays', function () { + it('converts 1 week to days', function () { + const result = weeksToDays(1) assert.deepStrictEqual(result, 7) - }); - it('converts 3 weeks to days', function() { - const result = weeksToDays(3); + }) + + it('converts 3 weeks to days', function () { + const result = weeksToDays(3) assert.deepStrictEqual(result, 21) - }); - it('converts 5 weeks to days', function() { - const result = weeksToDays(5); + }) + + it('converts 5 weeks to days', function () { + const result = weeksToDays(5) assert.deepStrictEqual(result, 35) - }); -}); + }) +}) From b4305a44509a70253a7652a557f74e25e6155a53 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:53:12 +0100 Subject: [PATCH 23/32] Add minor changes, fix docs Review yearsToMonths --- src/yearsToMonths/index.ts | 18 ++++++++++-------- src/yearsToMonths/test.ts | 25 +++++++++++++------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/yearsToMonths/index.ts b/src/yearsToMonths/index.ts index 65ba4dbab1..b0df874734 100644 --- a/src/yearsToMonths/index.ts +++ b/src/yearsToMonths/index.ts @@ -1,24 +1,26 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function yearsToMonths(years: number): number + /** * @name yearsToMonths - * @category Common Helpers - * @summary Convert year to months. + * @category Conversion Helpers + * @summary Convert years to months. * * @description - * Convert years number to months numbers. + * Convert a number of years to a number of months. * - * @param { number } years - number of months to be converted. + * @param { number } years - number of years to be converted. * * @returns {number} the number of years converted in months * @throws {TypeError} 1 argument required * * @example - * //Convert 2 years into months + * // Convert 2 years into months * const result = yearsToMonths(2) * //=> 24 */ - export default function yearsToMonths(years: number): number { - requiredArgs(1, arguments); - return years*12; + requiredArgs(1, arguments) + return years * 12 } diff --git a/src/yearsToMonths/test.ts b/src/yearsToMonths/test.ts index a7a458bd65..a0a720593b 100644 --- a/src/yearsToMonths/test.ts +++ b/src/yearsToMonths/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import yearsToMonths from '.' -describe('yearsToMonths', function() { - it('converts 1 year to months', function() { - const result = yearsToMonths(1); +describe('yearsToMonths', function () { + it('converts 1 year to months', function () { + const result = yearsToMonths(1) assert.deepStrictEqual(result, 12) - }); - it('converts 3 years to months', function() { - const result = yearsToMonths(3); + }) + + it('converts 3 years to months', function () { + const result = yearsToMonths(3) assert.deepStrictEqual(result, 36) - }); - it('converts 5 years to months', function() { - const result = yearsToMonths(5); + }) + + it('converts 5 years to months', function () { + const result = yearsToMonths(5) assert.deepStrictEqual(result, 60) - }); -}); + }) +}) From b9a7be32040b8da848aa55ecf95c2666a7355924 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Sun, 2 May 2021 21:57:54 +0100 Subject: [PATCH 24/32] Add minor changes, fix docs Review yearsToQuarters --- src/yearsToQuarters/index.ts | 14 ++++++++------ src/yearsToQuarters/test.ts | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/yearsToQuarters/index.ts b/src/yearsToQuarters/index.ts index 3eb70e4879..8d7b2e2cc1 100644 --- a/src/yearsToQuarters/index.ts +++ b/src/yearsToQuarters/index.ts @@ -1,11 +1,14 @@ import requiredArgs from '../_lib/requiredArgs/index' + +export default function yearsToQuarters(years: number): number + /** * @name yearsToQuarters - * @category Common Helpers + * @category Conversion Helpers * @summary Convert years to quarters. * * @description - * Convert number of years to quarters. + * Convert a number of years to a number of quarters. * * @param { number } years - number of years to be converted. * @@ -13,12 +16,11 @@ import requiredArgs from '../_lib/requiredArgs/index' * @throws {TypeError} 1 argument required * * @example - * //Convert 1 year to quarters + * // Convert 1 year to quarters * const result = yearsToQuarters(2) * //=> 8 */ - export default function yearsToQuarters(years: number): number { - requiredArgs(1, arguments); - return years*4; + requiredArgs(1, arguments) + return years * 4 } diff --git a/src/yearsToQuarters/test.ts b/src/yearsToQuarters/test.ts index 8081126711..d5581a7ef2 100644 --- a/src/yearsToQuarters/test.ts +++ b/src/yearsToQuarters/test.ts @@ -1,20 +1,21 @@ -// @flow /* eslint-env mocha */ import assert from 'assert' import yearsToQuarters from '.' -describe('yearsToQuarters', function() { - it('converts 1 year to quarters', function() { - const result = yearsToQuarters(1); +describe('yearsToQuarters', function () { + it('converts 1 year to quarters', function () { + const result = yearsToQuarters(1) assert.deepStrictEqual(result, 4) - }); - it('converts 3 years to quarters', function() { - const result = yearsToQuarters(3); + }) + + it('converts 3 years to quarters', function () { + const result = yearsToQuarters(3) assert.deepStrictEqual(result, 12) - }); - it('converts 5 years to quarters', function() { - const result = yearsToQuarters(5); + }) + + it('converts 5 years to quarters', function () { + const result = yearsToQuarters(5) assert.deepStrictEqual(result, 20) - }); -}); + }) +}) From 5ac84038c6f9d7c8385cdb44f4b988c12971513d Mon Sep 17 00:00:00 2001 From: Tetiana Date: Wed, 12 May 2021 22:43:49 +0100 Subject: [PATCH 25/32] Move constants to separate file, add minor changes --- src/constants/index.ts | 80 ++++++++++++++++++++++++++++++ src/daysToWeeks/index.ts | 3 +- src/hoursToMilliseconds/index.ts | 4 +- src/hoursToMinutes/index.ts | 4 +- src/hoursToSeconds/index.ts | 4 +- src/hoursToSeconds/test.ts | 2 + src/millisecondsToHours/index.ts | 5 +- src/millisecondsToMinutes/index.ts | 5 +- src/millisecondsToSeconds/index.ts | 5 +- src/millisecondsToSeconds/test.ts | 2 + src/minutesToHours/index.ts | 3 +- src/minutesToMilliseconds/index.ts | 4 +- src/minutesToSeconds/index.ts | 3 +- src/monthsToQuarters/index.ts | 3 +- src/monthsToYears/index.ts | 3 +- src/quartersToMonths/index.ts | 3 +- src/quartersToYears/index.ts | 3 +- src/secondsToHours/index.ts | 3 +- src/secondsToMilliseconds/index.ts | 3 +- src/secondsToMinutes/index.ts | 3 +- src/weeksToDays/index.ts | 5 +- src/yearsToMonths/index.ts | 3 +- src/yearsToQuarters/index.ts | 5 +- 23 files changed, 127 insertions(+), 31 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index 3f1e161122..9de3878189 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,3 +1,83 @@ +/** + * Days in 1 week. + * @constant + * @type {number} + * @default + */ +export const daysInWeek = 7 + +/** + * Milliseconds in 1 hour + * @constant + * @type {number} + * @default + */ +export const millisecondsInHour = 3600000 + +/** + * Milliseconds in 1 minute + * @constant + * @type {number} + * @default + */ +export const millisecondsInMinute = 60000 + +/** + * Milliseconds in 1 second + * @constant + * @type {number} + * @default + */ +export const millisecondsInSecond = 1000 + +/** + * Minutes in 1 hour + * @constant + * @type {number} + * @default + */ +export const minutesInHour = 60 + +/** + * Months in 1 quarter + * @constant + * @type {number} + * @default + */ +export const monthsInQuarter = 3 + +/** + * Months in 1 year + * @constant + * @type {number} + * @default + */ +export const monthsInYear = 12 + +/** + * Quarters in 1 year + * @constant + * @type {number} + * @default + */ +export const quartersInYear = 4 + +/** + * Seconds in 1 hour + * @constant + * @type {number} + * @default + */ +export const secondsInHour = 3600 + +/** + * Seconds in 1 minute + * @constant + * @type {number} + * @default + */ +export const secondsInMinute = 60 + /** * Maximum allowed time. * @constant diff --git a/src/daysToWeeks/index.ts b/src/daysToWeeks/index.ts index cc60b2ebef..00cc14408f 100644 --- a/src/daysToWeeks/index.ts +++ b/src/daysToWeeks/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { daysInWeek } from '../constants/index' export default function daysToWeeks(days: number): number @@ -22,6 +23,6 @@ export default function daysToWeeks(days: number): number */ export default function daysToWeeks(days: number): number { requiredArgs(1, arguments) - const weeks = days / 7 + const weeks = days / daysInWeek return Math.floor(weeks) } diff --git a/src/hoursToMilliseconds/index.ts b/src/hoursToMilliseconds/index.ts index 0f36ca65ff..3bbba906a8 100644 --- a/src/hoursToMilliseconds/index.ts +++ b/src/hoursToMilliseconds/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { millisecondsInHour } from '../constants/index' export default function hoursToMilliseconds(hours: number): number @@ -22,6 +23,5 @@ export default function hoursToMilliseconds(hours: number): number */ export default function hoursToMilliseconds(hours: number): number { requiredArgs(1, arguments) - // milliseconds in 1 hour => 3600000; - return hours * 3600000 + return hours * millisecondsInHour } diff --git a/src/hoursToMinutes/index.ts b/src/hoursToMinutes/index.ts index 0409791c07..b3ef623880 100644 --- a/src/hoursToMinutes/index.ts +++ b/src/hoursToMinutes/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { minutesInHour } from '../constants/index' export default function hoursToMinutes(hours: number): number @@ -20,8 +21,7 @@ export default function hoursToMinutes(hours: number): number * const result = hoursToMinutes(2) * //=> 120 */ - export default function hoursToMinutes(hours: number): number { requiredArgs(1, arguments) - return hours * 60 + return hours * minutesInHour } diff --git a/src/hoursToSeconds/index.ts b/src/hoursToSeconds/index.ts index 91e69d027a..9e83877ca6 100644 --- a/src/hoursToSeconds/index.ts +++ b/src/hoursToSeconds/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { secondsInHour } from '../constants/index' export default function hoursToSeconds(hours: number): number @@ -20,8 +21,7 @@ export default function hoursToSeconds(hours: number): number * const result = hoursToSeconds(2) * //=> 7200 */ - export default function hoursToSeconds(hours: number): number { requiredArgs(1, arguments) - return hours * 3600 + return hours * secondsInHour } diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts index 577b514f37..593294d972 100644 --- a/src/hoursToSeconds/test.ts +++ b/src/hoursToSeconds/test.ts @@ -8,10 +8,12 @@ describe('hoursToSeconds', function () { const result = hoursToSeconds(2) assert.deepStrictEqual(result, 7200) }) + it('converts 5 hours to seconds', function () { const result = hoursToSeconds(5) assert.deepStrictEqual(result, 18000) }) + it('converts 7 hours to seconds', function () { const result = hoursToSeconds(7) assert.deepStrictEqual(result, 25200) diff --git a/src/millisecondsToHours/index.ts b/src/millisecondsToHours/index.ts index 4345538ad2..2ae8342a5c 100644 --- a/src/millisecondsToHours/index.ts +++ b/src/millisecondsToHours/index.ts @@ -1,6 +1,8 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { millisecondsInHour } from '../constants/index' export default function millisecondsToHours(milliseconds: number): number + /** * @name millisecondsToHours * @category Conversion Helpers @@ -21,7 +23,6 @@ export default function millisecondsToHours(milliseconds: number): number */ export default function millisecondsToHours(milliseconds: number): number { requiredArgs(1, arguments) - // milliseconds in 1 hour => 3600000; - const hours = milliseconds / 3600000 + const hours = milliseconds / millisecondsInHour return Math.floor(hours) } diff --git a/src/millisecondsToMinutes/index.ts b/src/millisecondsToMinutes/index.ts index 52d4e193e9..39c3ee46c1 100644 --- a/src/millisecondsToMinutes/index.ts +++ b/src/millisecondsToMinutes/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { millisecondsInMinute } from '../constants/index' export default function millisecondsToMinutes(milliseconds: number): number @@ -20,10 +21,8 @@ export default function millisecondsToMinutes(milliseconds: number): number * const result = millisecondsToMinutes(60000) * //=> 1 */ - export default function millisecondsToMinutes(milliseconds: number): number { requiredArgs(1, arguments) - // 60000 milliseconds in 1 minute - const minutes = milliseconds / 60000 + const minutes = milliseconds / millisecondsInMinute return Math.floor(minutes) } diff --git a/src/millisecondsToSeconds/index.ts b/src/millisecondsToSeconds/index.ts index 05a5b414b9..99ed9d8684 100644 --- a/src/millisecondsToSeconds/index.ts +++ b/src/millisecondsToSeconds/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { millisecondsInSecond } from '../constants/index' export default function millisecondsToSeconds(milliseconds: number): number @@ -20,10 +21,8 @@ export default function millisecondsToSeconds(milliseconds: number): number * const result = millisecondsToSeconds(1000) * //=> 1 */ - export default function millisecondsToSeconds(milliseconds: number): number { requiredArgs(1, arguments) - // milliseconds in 1 seconds => 1000; - const seconds = milliseconds / 1000 + const seconds = milliseconds / millisecondsInSecond return Math.floor(seconds) } diff --git a/src/millisecondsToSeconds/test.ts b/src/millisecondsToSeconds/test.ts index d6b8bfb7b9..d0ffd79f21 100644 --- a/src/millisecondsToSeconds/test.ts +++ b/src/millisecondsToSeconds/test.ts @@ -8,6 +8,7 @@ describe('millisecondsToSeconds', function () { const result = millisecondsToSeconds(700) assert.deepStrictEqual(result, 0) }) + it('converts 1500 milliseconds to seconds', function () { const result = millisecondsToSeconds(1500) assert.deepStrictEqual(result, 1) @@ -17,6 +18,7 @@ describe('millisecondsToSeconds', function () { const result = millisecondsToSeconds(3500) assert.deepStrictEqual(result, 3) }) + it('converts 5500 milliseconds to seconds', function () { const result = millisecondsToSeconds(5500) assert.deepStrictEqual(result, 5) diff --git a/src/minutesToHours/index.ts b/src/minutesToHours/index.ts index b6ef04fe14..9897a73368 100644 --- a/src/minutesToHours/index.ts +++ b/src/minutesToHours/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { minutesInHour } from '../constants/index' export default function minutesToHours(minutes: number): number @@ -22,6 +23,6 @@ export default function minutesToHours(minutes: number): number */ export default function minutesToHours(minutes: number): number { requiredArgs(1, arguments) - const hours = minutes / 60 + const hours = minutes / minutesInHour return Math.floor(hours) } diff --git a/src/minutesToMilliseconds/index.ts b/src/minutesToMilliseconds/index.ts index f88063d32d..07d2404977 100644 --- a/src/minutesToMilliseconds/index.ts +++ b/src/minutesToMilliseconds/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { millisecondsInMinute } from '../constants/index' export default function minutesToMilliseconds(minutes: number): number @@ -22,6 +23,5 @@ export default function minutesToMilliseconds(minutes: number): number */ export default function minutesToMilliseconds(minutes: number): number { requiredArgs(1, arguments) - // milliseconds in 1 minute => 60000; - return minutes * 60000 + return minutes * millisecondsInMinute } diff --git a/src/minutesToSeconds/index.ts b/src/minutesToSeconds/index.ts index 8b4014a8a0..41729eeb35 100644 --- a/src/minutesToSeconds/index.ts +++ b/src/minutesToSeconds/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { secondsInMinute } from '../constants/index' export default function minutesToSeconds(minutes: number): number @@ -22,5 +23,5 @@ export default function minutesToSeconds(minutes: number): number */ export default function minutesToSeconds(minutes: number): number { requiredArgs(1, arguments) - return minutes * 60 + return minutes * secondsInMinute } diff --git a/src/monthsToQuarters/index.ts b/src/monthsToQuarters/index.ts index f60363fb9b..aafbb9f6c6 100644 --- a/src/monthsToQuarters/index.ts +++ b/src/monthsToQuarters/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { monthsInQuarter } from '../constants/index' export default function monthsToQuarters(months: number): number @@ -22,6 +23,6 @@ export default function monthsToQuarters(months: number): number */ export default function monthsToQuarters(months: number): number { requiredArgs(1, arguments) - const quarters = months / 3 + const quarters = months / monthsInQuarter return Math.floor(quarters) } diff --git a/src/monthsToYears/index.ts b/src/monthsToYears/index.ts index b83d8ae1bd..260eac9547 100644 --- a/src/monthsToYears/index.ts +++ b/src/monthsToYears/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { monthsInYear } from '../constants/index' export default function monthsToYears(months: number): number @@ -22,6 +23,6 @@ export default function monthsToYears(months: number): number */ export default function monthsToYears(months: number): number { requiredArgs(1, arguments) - const years = months / 12 + const years = months / monthsInYear return Math.floor(years) } diff --git a/src/quartersToMonths/index.ts b/src/quartersToMonths/index.ts index 026ee6cd5a..584992a068 100644 --- a/src/quartersToMonths/index.ts +++ b/src/quartersToMonths/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { monthsInQuarter } from '../constants/index' export default function quartersToMonths(quarters: number): number @@ -22,5 +23,5 @@ export default function quartersToMonths(quarters: number): number */ export default function quartersToMonths(quarters: number): number { requiredArgs(1, arguments) - return quarters * 3 + return quarters * monthsInQuarter } diff --git a/src/quartersToYears/index.ts b/src/quartersToYears/index.ts index a78711c448..3124dadaba 100644 --- a/src/quartersToYears/index.ts +++ b/src/quartersToYears/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { quartersInYear } from '../constants/index' export default function quartersToYears(quarters: number): number @@ -22,6 +23,6 @@ export default function quartersToYears(quarters: number): number */ export default function quartersToYears(quarters: number): number { requiredArgs(1, arguments) - const years = quarters / 4 + const years = quarters / quartersInYear return Math.floor(years) } diff --git a/src/secondsToHours/index.ts b/src/secondsToHours/index.ts index 7b893f1218..4181b6c7a0 100644 --- a/src/secondsToHours/index.ts +++ b/src/secondsToHours/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { secondsInHour } from '../constants/index' export default function secondsToHours(seconds: number): number @@ -22,6 +23,6 @@ export default function secondsToHours(seconds: number): number */ export default function secondsToHours(seconds: number): number { requiredArgs(1, arguments) - const hours = seconds / 3600 + const hours = seconds / secondsInHour return Math.floor(hours) } diff --git a/src/secondsToMilliseconds/index.ts b/src/secondsToMilliseconds/index.ts index 6c1bdfb250..52944c2bc0 100644 --- a/src/secondsToMilliseconds/index.ts +++ b/src/secondsToMilliseconds/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { millisecondsInSecond } from '../constants/index' export default function secondsToMilliseconds(seconds: number): number @@ -22,5 +23,5 @@ export default function secondsToMilliseconds(seconds: number): number */ export default function secondsToMilliseconds(seconds: number): number { requiredArgs(1, arguments) - return seconds * 1000 + return seconds * millisecondsInSecond } diff --git a/src/secondsToMinutes/index.ts b/src/secondsToMinutes/index.ts index 9051a1a079..f280c29382 100644 --- a/src/secondsToMinutes/index.ts +++ b/src/secondsToMinutes/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { secondsInMinute } from '../constants/index' export default function secondsToMinutes(seconds: number): number @@ -22,6 +23,6 @@ export default function secondsToMinutes(seconds: number): number */ export default function secondsToMinutes(seconds: number): number { requiredArgs(1, arguments) - const minutes = seconds / 60 + const minutes = seconds / secondsInMinute return Math.floor(minutes) } diff --git a/src/weeksToDays/index.ts b/src/weeksToDays/index.ts index 2b36624783..fb4f7c7d34 100644 --- a/src/weeksToDays/index.ts +++ b/src/weeksToDays/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { daysInWeek } from '../constants/index' export default function weeksToDays(weeks: number): number @@ -10,7 +11,7 @@ export default function weeksToDays(weeks: number): number * @description * Convert a number of weeks to a number of days. * - * @param { number } weeks - number of days to be converted. + * @param { number } weeks - number of weeks to be converted. * * @returns {number} the number of weeks converted in days * @throws {TypeError} 1 argument required @@ -22,5 +23,5 @@ export default function weeksToDays(weeks: number): number */ export default function weeksToDays(weeks: number): number { requiredArgs(1, arguments) - return weeks * 7 + return weeks * daysInWeek } diff --git a/src/yearsToMonths/index.ts b/src/yearsToMonths/index.ts index b0df874734..89f269c5c8 100644 --- a/src/yearsToMonths/index.ts +++ b/src/yearsToMonths/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { monthsInYear } from '../constants/index' export default function yearsToMonths(years: number): number @@ -22,5 +23,5 @@ export default function yearsToMonths(years: number): number */ export default function yearsToMonths(years: number): number { requiredArgs(1, arguments) - return years * 12 + return years * monthsInYear } diff --git a/src/yearsToQuarters/index.ts b/src/yearsToQuarters/index.ts index 8d7b2e2cc1..ccc317156c 100644 --- a/src/yearsToQuarters/index.ts +++ b/src/yearsToQuarters/index.ts @@ -1,4 +1,5 @@ import requiredArgs from '../_lib/requiredArgs/index' +import { quartersInYear } from '../constants/index' export default function yearsToQuarters(years: number): number @@ -16,11 +17,11 @@ export default function yearsToQuarters(years: number): number * @throws {TypeError} 1 argument required * * @example - * // Convert 1 year to quarters + * // Convert 2 years to quarters * const result = yearsToQuarters(2) * //=> 8 */ export default function yearsToQuarters(years: number): number { requiredArgs(1, arguments) - return years * 4 + return years * quartersInYear } From 81aa438a004edb273c3856ecda2504b3134fb294 Mon Sep 17 00:00:00 2001 From: Sasha Koss Date: Fri, 14 May 2021 12:23:00 +0800 Subject: [PATCH 26/32] Clean up conversion functions, add doc category --- docs/index.js | 1 + src/daysToWeeks/index.ts | 13 ++++++++----- src/daysToWeeks/test.ts | 8 ++++---- src/hoursToMilliseconds/index.ts | 10 ++++------ src/hoursToMilliseconds/test.ts | 6 +++--- src/hoursToMinutes/index.ts | 8 +++----- src/hoursToMinutes/test.ts | 6 +++--- src/hoursToSeconds/index.ts | 8 +++----- src/hoursToSeconds/test.ts | 6 +++--- src/milliseconds/index.ts | 6 +++--- src/millisecondsToHours/index.ts | 13 ++++++++----- src/millisecondsToMinutes/index.ts | 13 ++++++++----- src/millisecondsToMinutes/test.ts | 8 ++++---- src/millisecondsToSeconds/index.ts | 13 ++++++++----- src/millisecondsToSeconds/test.ts | 8 ++++---- src/minutesToHours/index.ts | 15 +++++++++------ src/minutesToHours/test.ts | 8 ++++---- src/minutesToMilliseconds/index.ts | 6 ++---- src/minutesToMilliseconds/test.ts | 6 +++--- src/minutesToSeconds/index.ts | 6 ++---- src/minutesToSeconds/test.ts | 6 +++--- src/monthsToQuarters/index.ts | 13 ++++++++----- src/monthsToQuarters/test.ts | 8 ++++---- src/monthsToYears/index.ts | 12 +++++++----- src/monthsToYears/test.ts | 10 +++++----- src/quartersToMonths/index.ts | 6 ++---- src/quartersToMonths/test.ts | 6 +++--- src/quartersToYears/index.ts | 11 +++++++---- src/quartersToYears/test.ts | 6 +++--- src/secondsToHours/index.ts | 11 +++++++---- src/secondsToHours/test.ts | 8 ++++---- src/secondsToMilliseconds/index.ts | 6 ++---- src/secondsToMilliseconds/test.ts | 6 +++--- src/secondsToMinutes/index.ts | 11 +++++++---- src/secondsToMinutes/test.ts | 8 ++++---- src/weeksToDays/index.ts | 6 ++---- src/weeksToDays/test.ts | 6 +++--- src/yearsToMonths/index.ts | 6 ++---- src/yearsToMonths/test.ts | 6 +++--- src/yearsToQuarters/index.ts | 6 ++---- src/yearsToQuarters/test.ts | 6 +++--- 41 files changed, 171 insertions(+), 161 deletions(-) diff --git a/docs/index.js b/docs/index.js index 08ca1e8bdd..bd8ee265ca 100644 --- a/docs/index.js +++ b/docs/index.js @@ -5,6 +5,7 @@ module.exports = { 'General', 'Types', 'Common Helpers', + 'Conversion Helpers', 'Interval Helpers', 'Timestamp Helpers', 'Millisecond Helpers', diff --git a/src/daysToWeeks/index.ts b/src/daysToWeeks/index.ts index 00cc14408f..b7b7efb456 100644 --- a/src/daysToWeeks/index.ts +++ b/src/daysToWeeks/index.ts @@ -1,25 +1,28 @@ import requiredArgs from '../_lib/requiredArgs/index' import { daysInWeek } from '../constants/index' -export default function daysToWeeks(days: number): number - /** * @name daysToWeeks * @category Conversion Helpers * @summary Convert days to weeks. * * @description - * Convert a number of days to a number of weeks. + * Convert a number of days to a full number of weeks. * - * @param { number } days - number of days to be converted. + * @param {number} days - number of days to be converted * * @returns {number} the number of days converted in weeks * @throws {TypeError} 1 argument required * * @example - * // Convert 14 days to weeks + * // Convert 14 days to weeks: * const result = daysToWeeks(14) * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = daysToWeeks(13) + * //=> 1 */ export default function daysToWeeks(days: number): number { requiredArgs(1, arguments) diff --git a/src/daysToWeeks/test.ts b/src/daysToWeeks/test.ts index 4594c2061c..e80370035c 100644 --- a/src/daysToWeeks/test.ts +++ b/src/daysToWeeks/test.ts @@ -6,21 +6,21 @@ import daysToWeeks from '.' describe('daysToWeeks', function () { it('converts 5 days to weeks', function () { const result = daysToWeeks(5) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 8 days to weeks', function () { const result = daysToWeeks(8) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 13 days to weeks', function () { const result = daysToWeeks(13) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 15 days to weeks', function () { const result = daysToWeeks(15) - assert.deepStrictEqual(result, 2) + assert(result === 2) }) }) diff --git a/src/hoursToMilliseconds/index.ts b/src/hoursToMilliseconds/index.ts index 3bbba906a8..a5f9c0633c 100644 --- a/src/hoursToMilliseconds/index.ts +++ b/src/hoursToMilliseconds/index.ts @@ -1,23 +1,21 @@ import requiredArgs from '../_lib/requiredArgs/index' import { millisecondsInHour } from '../constants/index' -export default function hoursToMilliseconds(hours: number): number - /** * @name hoursToMilliseconds * @category Conversion Helpers * @summary Convert hours to milliseconds. * * @description - * Convert a number of hours to a number of milliseconds . + * Convert a number of hours to a full number of milliseconds. * - * @param { number } hours - number of hours to be converted. + * @param {number} hours - number of hours to be converted * - * @returns {number} the number of hours converted in milliseconds + * @returns {number} the number of hours converted to milliseconds * @throws {TypeError} 1 argument required * * @example - * // Convert 2 hours to milliseconds + * // Convert 2 hours to milliseconds: * const result = hoursToMilliseconds(2) * //=> 7200000 */ diff --git a/src/hoursToMilliseconds/test.ts b/src/hoursToMilliseconds/test.ts index 5c0f27339e..f0690fa2f2 100644 --- a/src/hoursToMilliseconds/test.ts +++ b/src/hoursToMilliseconds/test.ts @@ -6,16 +6,16 @@ import hoursToMilliseconds from '.' describe('hoursToMilliseconds', function () { it('converts 1 hour to milliseconds', function () { const result = hoursToMilliseconds(1) - assert.deepStrictEqual(result, 3600000) + assert(result === 3600000) }) it('converts 2 hours to milliseconds', function () { const result = hoursToMilliseconds(2) - assert.deepStrictEqual(result, 7200000) + assert(result === 7200000) }) it('converts 5 hours to milliseconds', function () { const result = hoursToMilliseconds(5) - assert.deepStrictEqual(result, 18000000) + assert(result === 18000000) }) }) diff --git a/src/hoursToMinutes/index.ts b/src/hoursToMinutes/index.ts index b3ef623880..213bb53253 100644 --- a/src/hoursToMinutes/index.ts +++ b/src/hoursToMinutes/index.ts @@ -1,23 +1,21 @@ import requiredArgs from '../_lib/requiredArgs/index' import { minutesInHour } from '../constants/index' -export default function hoursToMinutes(hours: number): number - /** * @name hoursToMinutes * @category Conversion Helpers * @summary Convert hours to minutes. * * @description - * Convert a number of hours to a number of minutes. + * Convert a number of hours to a full number of minutes. * - * @param { number } hours - number of hours to be converted. + * @param {number} hours - number of hours to be converted * * @returns {number} the number of hours converted in minutes * @throws {TypeError} 1 argument required * * @example - * // Convert 2 hours to minutes + * // Convert 2 hours to minutes: * const result = hoursToMinutes(2) * //=> 120 */ diff --git a/src/hoursToMinutes/test.ts b/src/hoursToMinutes/test.ts index 1ac0971a3e..bdb535fdaf 100644 --- a/src/hoursToMinutes/test.ts +++ b/src/hoursToMinutes/test.ts @@ -6,16 +6,16 @@ import hoursToMinutes from '.' describe('hoursToMinutes', function () { it('converts 2 hours to minutes', function () { const result = hoursToMinutes(2) - assert.deepStrictEqual(result, 120) + assert(result === 120) }) it('converts 5 hours to minutes', function () { const result = hoursToMinutes(5) - assert.deepStrictEqual(result, 300) + assert(result === 300) }) it('converts 7 hours to minutes', function () { const result = hoursToMinutes(7) - assert.deepStrictEqual(result, 420) + assert(result === 420) }) }) diff --git a/src/hoursToSeconds/index.ts b/src/hoursToSeconds/index.ts index 9e83877ca6..5a942fb3ac 100644 --- a/src/hoursToSeconds/index.ts +++ b/src/hoursToSeconds/index.ts @@ -1,23 +1,21 @@ import requiredArgs from '../_lib/requiredArgs/index' import { secondsInHour } from '../constants/index' -export default function hoursToSeconds(hours: number): number - /** * @name hoursToSeconds * @category Conversion Helpers * @summary Convert hours to seconds. * * @description - * Convert a number of hours to a number of seconds. + * Convert a number of hours to a full number of seconds. * - * @param { number } hours - number of hours to be converted. + * @param {number} hours - number of hours to be converted * * @returns {number} the number of hours converted in seconds * @throws {TypeError} 1 argument required * * @example - * // Convert 2 hours to seconds + * // Convert 2 hours to seconds: * const result = hoursToSeconds(2) * //=> 7200 */ diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts index 593294d972..40b4027362 100644 --- a/src/hoursToSeconds/test.ts +++ b/src/hoursToSeconds/test.ts @@ -6,16 +6,16 @@ import hoursToSeconds from '.' describe('hoursToSeconds', function () { it('converts 2 hours to seconds', function () { const result = hoursToSeconds(2) - assert.deepStrictEqual(result, 7200) + assert(result === 7200) }) it('converts 5 hours to seconds', function () { const result = hoursToSeconds(5) - assert.deepStrictEqual(result, 18000) + assert(result === 18000) }) it('converts 7 hours to seconds', function () { const result = hoursToSeconds(7) - assert.deepStrictEqual(result, 25200) + assert(result === 25200) }) }) diff --git a/src/milliseconds/index.ts b/src/milliseconds/index.ts index ec9f7fdabe..65192295fe 100644 --- a/src/milliseconds/index.ts +++ b/src/milliseconds/index.ts @@ -3,7 +3,7 @@ import { Duration } from '../types' // Leap year occures every 4 years, except for years that are divisable by 100 and not divisable by 400. // 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days -const yearInDays = 365.2425 +const daysInYear = 365.2425 /** * @name milliseconds @@ -47,8 +47,8 @@ export default function milliseconds({ let totalDays = 0 - if (years) totalDays += years * yearInDays - if (months) totalDays += months * (yearInDays / 12) + if (years) totalDays += years * daysInYear + if (months) totalDays += months * (daysInYear / 12) if (weeks) totalDays += weeks * 7 if (days) totalDays += days diff --git a/src/millisecondsToHours/index.ts b/src/millisecondsToHours/index.ts index 2ae8342a5c..a843a4d526 100644 --- a/src/millisecondsToHours/index.ts +++ b/src/millisecondsToHours/index.ts @@ -1,25 +1,28 @@ import requiredArgs from '../_lib/requiredArgs/index' import { millisecondsInHour } from '../constants/index' -export default function millisecondsToHours(milliseconds: number): number - /** * @name millisecondsToHours * @category Conversion Helpers * @summary Convert milliseconds to hours. * * @description - * Convert a number of milliseconds to a number of hours. + * Convert a number of milliseconds to a full number of hours. * - * @param { number } milliseconds - number of milliseconds to be converted. + * @param {number} milliseconds - number of milliseconds to be converted * * @returns {number} the number of milliseconds converted in hours * @throws {TypeError} 1 argument required * * @example - * // Convert 720000 milliseconds to hours + * // Convert 7200000 milliseconds to hours: * const result = millisecondsToHours(7200000) * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = millisecondsToHours(7199999) + * //=> 1 */ export default function millisecondsToHours(milliseconds: number): number { requiredArgs(1, arguments) diff --git a/src/millisecondsToMinutes/index.ts b/src/millisecondsToMinutes/index.ts index 39c3ee46c1..b4529f2193 100644 --- a/src/millisecondsToMinutes/index.ts +++ b/src/millisecondsToMinutes/index.ts @@ -1,25 +1,28 @@ import requiredArgs from '../_lib/requiredArgs/index' import { millisecondsInMinute } from '../constants/index' -export default function millisecondsToMinutes(milliseconds: number): number - /** * @name millisecondsToMinutes * @category Conversion Helpers * @summary Convert milliseconds to minutes. * * @description - * Convert a number of milliseconds to a number of minutes. + * Convert a number of milliseconds to a full number of minutes. * - * @param { number } milliseconds - number of milliseconds to be converted. + * @param {number} milliseconds - number of milliseconds to be converted. * * @returns {number} the number of milliseconds converted in minutes * @throws {TypeError} 1 argument required * * @example - * // Convert 60000 milliseconds to minutes + * // Convert 60000 milliseconds to minutes: * const result = millisecondsToMinutes(60000) * //=> 1 + * + * @example + * // It uses floor rounding: + * const result = millisecondsToMinutes(119999) + * //=> 1 */ export default function millisecondsToMinutes(milliseconds: number): number { requiredArgs(1, arguments) diff --git a/src/millisecondsToMinutes/test.ts b/src/millisecondsToMinutes/test.ts index 8b8a1021f2..616a42156e 100644 --- a/src/millisecondsToMinutes/test.ts +++ b/src/millisecondsToMinutes/test.ts @@ -6,21 +6,21 @@ import millisecondsToMinutes from '.' describe('millisecondsToMinutes', function () { it('converts 50000 milliseconds to minutes', function () { const result = millisecondsToMinutes(50000) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 65000 milliseconds to minutes', function () { const result = millisecondsToMinutes(65000) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 190000 milliseconds to minutes', function () { const result = millisecondsToMinutes(190000) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 310000 milliseconds to minutes', function () { const result = millisecondsToMinutes(310000) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/millisecondsToSeconds/index.ts b/src/millisecondsToSeconds/index.ts index 99ed9d8684..ea353287c8 100644 --- a/src/millisecondsToSeconds/index.ts +++ b/src/millisecondsToSeconds/index.ts @@ -1,25 +1,28 @@ import requiredArgs from '../_lib/requiredArgs/index' import { millisecondsInSecond } from '../constants/index' -export default function millisecondsToSeconds(milliseconds: number): number - /** * @name millisecondsToSeconds * @category Conversion Helpers * @summary Convert milliseconds to seconds. * * @description - * Convert a number of milliseconds to a number of seconds. + * Convert a number of milliseconds to a full number of seconds. * - * @param { number } milliseconds - number of milliseconds to be converted. + * @param {number} milliseconds - number of milliseconds to be converted * * @returns {number} the number of milliseconds converted in seconds * @throws {TypeError} 1 argument required * * @example - * // Convert 1000 miliseconds to seconds + * // Convert 1000 miliseconds to seconds: * const result = millisecondsToSeconds(1000) * //=> 1 + * + * @example + * // It uses floor rounding: + * const result = millisecondsToSeconds(1999) + * //=> 1 */ export default function millisecondsToSeconds(milliseconds: number): number { requiredArgs(1, arguments) diff --git a/src/millisecondsToSeconds/test.ts b/src/millisecondsToSeconds/test.ts index d0ffd79f21..f2071d6ac8 100644 --- a/src/millisecondsToSeconds/test.ts +++ b/src/millisecondsToSeconds/test.ts @@ -6,21 +6,21 @@ import millisecondsToSeconds from '.' describe('millisecondsToSeconds', function () { it('converts 700 milliseconds to seconds', function () { const result = millisecondsToSeconds(700) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 1500 milliseconds to seconds', function () { const result = millisecondsToSeconds(1500) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 3500 milliseconds to seconds', function () { const result = millisecondsToSeconds(3500) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 5500 milliseconds to seconds', function () { const result = millisecondsToSeconds(5500) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/minutesToHours/index.ts b/src/minutesToHours/index.ts index 9897a73368..9fd8cbbb1f 100644 --- a/src/minutesToHours/index.ts +++ b/src/minutesToHours/index.ts @@ -1,24 +1,27 @@ import requiredArgs from '../_lib/requiredArgs/index' import { minutesInHour } from '../constants/index' -export default function minutesToHours(minutes: number): number - /** * @name minutesToHours * @category Conversion Helpers * @summary Convert minutes to hours. * * @description - * Convert a number of minutes to a number of hours. + * Convert a number of minutes to a full number of hours. * - * @param { number } minutes - number of minutes to be converted. + * @param {number} minutes - number of minutes to be converted * * @returns {number} the number of minutes converted in hours * @throws {TypeError} 1 argument required * * @example - * // Convert 140 minutes to hours - * const result = minutesToHours(140) + * // Convert 140 minutes to hours: + * const result = minutesToHours(120) + * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = minutesToHours(179) * //=> 2 */ export default function minutesToHours(minutes: number): number { diff --git a/src/minutesToHours/test.ts b/src/minutesToHours/test.ts index 9d50cc06b7..b4f5625f88 100644 --- a/src/minutesToHours/test.ts +++ b/src/minutesToHours/test.ts @@ -6,21 +6,21 @@ import minuteToHours from '.' describe('minuteToHours', function () { it('converts 50 minutes to hours', function () { const result = minuteToHours(50) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 90 minutes to hours', function () { const result = minuteToHours(90) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 140 minutes to hours', function () { const result = minuteToHours(140) - assert.deepStrictEqual(result, 2) + assert(result === 2) }) it('converts 310 minutes to hours', function () { const result = minuteToHours(310) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/minutesToMilliseconds/index.ts b/src/minutesToMilliseconds/index.ts index 07d2404977..d26a9df8d7 100644 --- a/src/minutesToMilliseconds/index.ts +++ b/src/minutesToMilliseconds/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { millisecondsInMinute } from '../constants/index' -export default function minutesToMilliseconds(minutes: number): number - /** * @name minutesToMilliseconds * @category Conversion Helpers * @summary Convert minutes to milliseconds. * * @description - * Convert a number of minutes to a number of milliseconds. + * Convert a number of minutes to a full number of milliseconds. * - * @param { number } minutes - number of minutes to be converted. + * @param {number} minutes - number of minutes to be converted * * @returns {number} the number of minutes converted in milliseconds * @throws {TypeError} 1 argument required diff --git a/src/minutesToMilliseconds/test.ts b/src/minutesToMilliseconds/test.ts index 0444b9aff6..17cc974008 100644 --- a/src/minutesToMilliseconds/test.ts +++ b/src/minutesToMilliseconds/test.ts @@ -6,16 +6,16 @@ import minutesToMilliseconds from '.' describe('minutesToMilliseconds', function () { it('converts 1 minute to milliseconds', function () { const result = minutesToMilliseconds(1) - assert.deepStrictEqual(result, 60000) + assert(result === 60000) }) it('converts 3 minutes to milliseconds', function () { const result = minutesToMilliseconds(3) - assert.deepStrictEqual(result, 180000) + assert(result === 180000) }) it('converts 5 minutes to milliseconds', function () { const result = minutesToMilliseconds(5) - assert.deepStrictEqual(result, 300000) + assert(result === 300000) }) }) diff --git a/src/minutesToSeconds/index.ts b/src/minutesToSeconds/index.ts index 41729eeb35..07226098d4 100644 --- a/src/minutesToSeconds/index.ts +++ b/src/minutesToSeconds/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { secondsInMinute } from '../constants/index' -export default function minutesToSeconds(minutes: number): number - /** * @name minutesToSeconds * @category Conversion Helpers * @summary Convert minutes to seconds. * * @description - * Convert a number of minutes to a number of seconds. + * Convert a number of minutes to a full number of seconds. * - * @param { number } minutes - number of minutes to be converted. + * @param { number } minutes - number of minutes to be converted * * @returns {number} the number of minutes converted in seconds * @throws {TypeError} 1 argument required diff --git a/src/minutesToSeconds/test.ts b/src/minutesToSeconds/test.ts index 01be3a2989..8297f0b628 100644 --- a/src/minutesToSeconds/test.ts +++ b/src/minutesToSeconds/test.ts @@ -6,16 +6,16 @@ import minutesToSeconds from '.' describe('minutesToSeconds', function () { it('converts 1 minute to seconds', function () { const result = minutesToSeconds(1) - assert.deepStrictEqual(result, 60) + assert(result === 60) }) it('converts 3 minutes to seconds', function () { const result = minutesToSeconds(3) - assert.deepStrictEqual(result, 180) + assert(result === 180) }) it('converts 5 minutes to seconds', function () { const result = minutesToSeconds(5) - assert.deepStrictEqual(result, 300) + assert(result === 300) }) }) diff --git a/src/monthsToQuarters/index.ts b/src/monthsToQuarters/index.ts index aafbb9f6c6..0e5bb5d33f 100644 --- a/src/monthsToQuarters/index.ts +++ b/src/monthsToQuarters/index.ts @@ -1,25 +1,28 @@ import requiredArgs from '../_lib/requiredArgs/index' import { monthsInQuarter } from '../constants/index' -export default function monthsToQuarters(months: number): number - /** * @name monthsToQuarters * @category Conversion Helpers * @summary Convert number of months to quarters. * * @description - * Convert a number of months to a number of quarters. + * Convert a number of months to a full number of quarters. * - * @param { number } months - number of months to be converted. + * @param {number} months - number of months to be converted. * * @returns {number} the number of months converted in quarters * @throws {TypeError} 1 argument required * * @example - * // Convert 6 months to quarters + * // Convert 6 months to quarters: * const result = monthsToQuarters(6) * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = monthsToQuarters(7) + * //=> 2 */ export default function monthsToQuarters(months: number): number { requiredArgs(1, arguments) diff --git a/src/monthsToQuarters/test.ts b/src/monthsToQuarters/test.ts index 163bf663d3..7e85069bff 100644 --- a/src/monthsToQuarters/test.ts +++ b/src/monthsToQuarters/test.ts @@ -6,21 +6,21 @@ import monthsToQuarters from '.' describe('monthsToQuarters', function () { it('converts 2 months to quarters', function () { const result = monthsToQuarters(2) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 4 months to quarters', function () { const result = monthsToQuarters(4) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 10 months to quarters', function () { const result = monthsToQuarters(10) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 15 months to quarters', function () { const result = monthsToQuarters(15) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/monthsToYears/index.ts b/src/monthsToYears/index.ts index 260eac9547..f1615a7ce1 100644 --- a/src/monthsToYears/index.ts +++ b/src/monthsToYears/index.ts @@ -1,23 +1,25 @@ import requiredArgs from '../_lib/requiredArgs/index' import { monthsInYear } from '../constants/index' -export default function monthsToYears(months: number): number - /** * @name monthsToYears * @category Conversion Helpers * @summary Convert number of months to years. * * @description - * Convert a number of months to a number of years. + * Convert a number of months to a full number of years. * - * @param { number } months - number of months to be converted. + * @param {number} months - number of months to be converted * * @returns {number} the number of months converted in years * @throws {TypeError} 1 argument required * * @example - * // Convert 40 months to years + * // Convert 36 months to years: + * const result = monthsToYears(36) + * //=> 3 + * + * // It uses floor rounding: * const result = monthsToYears(40) * //=> 3 */ diff --git a/src/monthsToYears/test.ts b/src/monthsToYears/test.ts index 8f2c73bfbf..c437514daf 100644 --- a/src/monthsToYears/test.ts +++ b/src/monthsToYears/test.ts @@ -6,21 +6,21 @@ import monthsToYears from '.' describe('monthsToYears', function () { it('converts 10 months to year', function () { const result = monthsToYears(10) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 15 months to year', function () { const result = monthsToYears(15) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) - it('converts 40 months to year', function () { + it('converts 40 months to year', function () { const result = monthsToYears(40) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 65 months to year', function () { const result = monthsToYears(65) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/quartersToMonths/index.ts b/src/quartersToMonths/index.ts index 584992a068..810383ebea 100644 --- a/src/quartersToMonths/index.ts +++ b/src/quartersToMonths/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { monthsInQuarter } from '../constants/index' -export default function quartersToMonths(quarters: number): number - /** * @name quartersToMonths * @category Conversion Helpers * @summary Convert number of quarters to months. * * @description - * Convert a number of quarters to a number of months. + * Convert a number of quarters to a full number of months. * - * @param { number } quarters - number of quarters to be converted. + * @param {number} quarters - number of quarters to be converted * * @returns {number} the number of quarters converted in months * @throws {TypeError} 1 argument required diff --git a/src/quartersToMonths/test.ts b/src/quartersToMonths/test.ts index b6e8b59182..5fc20a8021 100644 --- a/src/quartersToMonths/test.ts +++ b/src/quartersToMonths/test.ts @@ -6,16 +6,16 @@ import quartersToMonths from '.' describe('quartersToMonths', function () { it('converts 1 quarter to months', function () { const result = quartersToMonths(1) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 3 quarters to months', function () { const result = quartersToMonths(3) - assert.deepStrictEqual(result, 9) + assert(result === 9) }) it('converts 5 quarters to months', function () { const result = quartersToMonths(5) - assert.deepStrictEqual(result, 15) + assert(result === 15) }) }) diff --git a/src/quartersToYears/index.ts b/src/quartersToYears/index.ts index 3124dadaba..8f3d0e9b03 100644 --- a/src/quartersToYears/index.ts +++ b/src/quartersToYears/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { quartersInYear } from '../constants/index' -export default function quartersToYears(quarters: number): number - /** * @name quartersToYears * @category Conversion Helpers * @summary Convert number of quarters to years. * * @description - * Convert a number of quarters to a number of years. + * Convert a number of quarters to a full number of years. * - * @param { number } quarters - number of quarters to be converted. + * @param {number} quarters - number of quarters to be converted * * @returns {number} the number of quarters converted in years * @throws {TypeError} 1 argument required @@ -20,6 +18,11 @@ export default function quartersToYears(quarters: number): number * // Convert 8 quarters to years * const result = quartersToYears(8) * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = quartersToYears(11) + * //=> 2 */ export default function quartersToYears(quarters: number): number { requiredArgs(1, arguments) diff --git a/src/quartersToYears/test.ts b/src/quartersToYears/test.ts index 99440f2bff..7100a96e83 100644 --- a/src/quartersToYears/test.ts +++ b/src/quartersToYears/test.ts @@ -6,16 +6,16 @@ import quartersToYears from '.' describe('quartersToYears', function () { it('converts 3 quarters to years', function () { const result = quartersToYears(3) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 5 quarters to years', function () { const result = quartersToYears(5) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 13 quarters to years', function () { const result = quartersToYears(13) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) }) diff --git a/src/secondsToHours/index.ts b/src/secondsToHours/index.ts index 4181b6c7a0..ba87b10b3d 100644 --- a/src/secondsToHours/index.ts +++ b/src/secondsToHours/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { secondsInHour } from '../constants/index' -export default function secondsToHours(seconds: number): number - /** * @name secondsToHours * @category Conversion Helpers * @summary Convert seconds to hours. * * @description - * Convert a number of seconds to a number of hours. + * Convert a number of seconds to a full number of hours. * - * @param { number } seconds - number of seconds to be converted. + * @param {number} seconds - number of seconds to be converted * * @returns {number} the number of seconds converted in hours * @throws {TypeError} 1 argument required @@ -20,6 +18,11 @@ export default function secondsToHours(seconds: number): number * // Convert 7200 seconds into hours * const result = secondsToHours(7200) * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = secondsToHours(7199) + * //=> 1 */ export default function secondsToHours(seconds: number): number { requiredArgs(1, arguments) diff --git a/src/secondsToHours/test.ts b/src/secondsToHours/test.ts index 84caa119f5..dd194dce64 100644 --- a/src/secondsToHours/test.ts +++ b/src/secondsToHours/test.ts @@ -6,21 +6,21 @@ import secondsToHours from '.' describe('secondsToHours', function () { it('converts 3000 seconds to hours', function () { const result = secondsToHours(3000) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 3700 seconds to hours', function () { const result = secondsToHours(3700) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 11000 seconds to hours', function () { const result = secondsToHours(11000) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 19000 seconds to hours', function () { const result = secondsToHours(19000) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/secondsToMilliseconds/index.ts b/src/secondsToMilliseconds/index.ts index 52944c2bc0..2e4a663c86 100644 --- a/src/secondsToMilliseconds/index.ts +++ b/src/secondsToMilliseconds/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { millisecondsInSecond } from '../constants/index' -export default function secondsToMilliseconds(seconds: number): number - /** * @name secondsToMilliseconds * @category Conversion Helpers * @summary Convert seconds to milliseconds. * * @description - * Convert a number of seconds to a number of milliseconds. + * Convert a number of seconds to a full number of milliseconds. * - * @param { number } seconds - number of seconds to be converted. + * @param {number} seconds - number of seconds to be converted * * @returns {number} the number of seconds converted in milliseconds * @throws {TypeError} 1 argument required diff --git a/src/secondsToMilliseconds/test.ts b/src/secondsToMilliseconds/test.ts index fb865d015c..f47d8433e6 100644 --- a/src/secondsToMilliseconds/test.ts +++ b/src/secondsToMilliseconds/test.ts @@ -6,16 +6,16 @@ import secondsToMilliseconds from '.' describe('secondsToMilliseconds', function () { it('converts 1 second to milliseconds', function () { const result = secondsToMilliseconds(1) - assert.deepStrictEqual(result, 1000) + assert(result === 1000) }) it('converts 3 seconds to milliseconds', function () { const result = secondsToMilliseconds(3) - assert.deepStrictEqual(result, 3000) + assert(result === 3000) }) it('converts 5 seconds to milliseconds', function () { const result = secondsToMilliseconds(5) - assert.deepStrictEqual(result, 5000) + assert(result === 5000) }) }) diff --git a/src/secondsToMinutes/index.ts b/src/secondsToMinutes/index.ts index f280c29382..530c21e4a6 100644 --- a/src/secondsToMinutes/index.ts +++ b/src/secondsToMinutes/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { secondsInMinute } from '../constants/index' -export default function secondsToMinutes(seconds: number): number - /** * @name secondsToMinutes * @category Conversion Helpers * @summary Convert seconds to minutes. * * @description - * Convert a number of seconds to a number of minutes. + * Convert a number of seconds to a full number of minutes. * - * @param { number } seconds - number of seconds to be converted. + * @param {number} seconds - number of seconds to be converted * * @returns {number} the number of seconds converted in minutes * @throws {TypeError} 1 argument required @@ -20,6 +18,11 @@ export default function secondsToMinutes(seconds: number): number * // Convert 120 seconds into minutes * const result = secondsToMinutes(120) * //=> 2 + * + * @example + * // It uses floor rounding: + * const result = secondsToMinutes(119) + * //=> 1 */ export default function secondsToMinutes(seconds: number): number { requiredArgs(1, arguments) diff --git a/src/secondsToMinutes/test.ts b/src/secondsToMinutes/test.ts index f5ddb8cff8..daae992e03 100644 --- a/src/secondsToMinutes/test.ts +++ b/src/secondsToMinutes/test.ts @@ -6,21 +6,21 @@ import secondsToMinutes from '.' describe('secondsToMinutes', function () { it('converts 50 seconds to minutes', function () { const result = secondsToMinutes(50) - assert.deepStrictEqual(result, 0) + assert(result === 0) }) it('converts 70 seconds to minutes', function () { const result = secondsToMinutes(70) - assert.deepStrictEqual(result, 1) + assert(result === 1) }) it('converts 190 seconds to minutes', function () { const result = secondsToMinutes(190) - assert.deepStrictEqual(result, 3) + assert(result === 3) }) it('converts 310 seconds to minutes', function () { const result = secondsToMinutes(310) - assert.deepStrictEqual(result, 5) + assert(result === 5) }) }) diff --git a/src/weeksToDays/index.ts b/src/weeksToDays/index.ts index fb4f7c7d34..3db9b31576 100644 --- a/src/weeksToDays/index.ts +++ b/src/weeksToDays/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { daysInWeek } from '../constants/index' -export default function weeksToDays(weeks: number): number - /** * @name weeksToDays * @category Conversion Helpers * @summary Convert weeks to days. * * @description - * Convert a number of weeks to a number of days. + * Convert a number of weeks to a full number of days. * - * @param { number } weeks - number of weeks to be converted. + * @param {number} weeks - number of weeks to be converted * * @returns {number} the number of weeks converted in days * @throws {TypeError} 1 argument required diff --git a/src/weeksToDays/test.ts b/src/weeksToDays/test.ts index 030d06dba0..da62768ad2 100644 --- a/src/weeksToDays/test.ts +++ b/src/weeksToDays/test.ts @@ -6,16 +6,16 @@ import weeksToDays from '.' describe('weeksToDays', function () { it('converts 1 week to days', function () { const result = weeksToDays(1) - assert.deepStrictEqual(result, 7) + assert(result === 7) }) it('converts 3 weeks to days', function () { const result = weeksToDays(3) - assert.deepStrictEqual(result, 21) + assert(result === 21) }) it('converts 5 weeks to days', function () { const result = weeksToDays(5) - assert.deepStrictEqual(result, 35) + assert(result === 35) }) }) diff --git a/src/yearsToMonths/index.ts b/src/yearsToMonths/index.ts index 89f269c5c8..f847dcf8f6 100644 --- a/src/yearsToMonths/index.ts +++ b/src/yearsToMonths/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { monthsInYear } from '../constants/index' -export default function yearsToMonths(years: number): number - /** * @name yearsToMonths * @category Conversion Helpers * @summary Convert years to months. * * @description - * Convert a number of years to a number of months. + * Convert a number of years to a full number of months. * - * @param { number } years - number of years to be converted. + * @param {number} years - number of years to be converted * * @returns {number} the number of years converted in months * @throws {TypeError} 1 argument required diff --git a/src/yearsToMonths/test.ts b/src/yearsToMonths/test.ts index a0a720593b..4c739afab8 100644 --- a/src/yearsToMonths/test.ts +++ b/src/yearsToMonths/test.ts @@ -6,16 +6,16 @@ import yearsToMonths from '.' describe('yearsToMonths', function () { it('converts 1 year to months', function () { const result = yearsToMonths(1) - assert.deepStrictEqual(result, 12) + assert(result === 12) }) it('converts 3 years to months', function () { const result = yearsToMonths(3) - assert.deepStrictEqual(result, 36) + assert(result === 36) }) it('converts 5 years to months', function () { const result = yearsToMonths(5) - assert.deepStrictEqual(result, 60) + assert(result === 60) }) }) diff --git a/src/yearsToQuarters/index.ts b/src/yearsToQuarters/index.ts index ccc317156c..3438440b42 100644 --- a/src/yearsToQuarters/index.ts +++ b/src/yearsToQuarters/index.ts @@ -1,17 +1,15 @@ import requiredArgs from '../_lib/requiredArgs/index' import { quartersInYear } from '../constants/index' -export default function yearsToQuarters(years: number): number - /** * @name yearsToQuarters * @category Conversion Helpers * @summary Convert years to quarters. * * @description - * Convert a number of years to a number of quarters. + * Convert a number of years to a full number of quarters. * - * @param { number } years - number of years to be converted. + * @param {number} years - number of years to be converted * * @returns {number} the number of years converted in quarters * @throws {TypeError} 1 argument required diff --git a/src/yearsToQuarters/test.ts b/src/yearsToQuarters/test.ts index d5581a7ef2..e23eb2c2f7 100644 --- a/src/yearsToQuarters/test.ts +++ b/src/yearsToQuarters/test.ts @@ -6,16 +6,16 @@ import yearsToQuarters from '.' describe('yearsToQuarters', function () { it('converts 1 year to quarters', function () { const result = yearsToQuarters(1) - assert.deepStrictEqual(result, 4) + assert(result === 4) }) it('converts 3 years to quarters', function () { const result = yearsToQuarters(3) - assert.deepStrictEqual(result, 12) + assert(result === 12) }) it('converts 5 years to quarters', function () { const result = yearsToQuarters(5) - assert.deepStrictEqual(result, 20) + assert(result === 20) }) }) From 7da59cb2aaeea28c5e64d63e6e4d8755dab422c6 Mon Sep 17 00:00:00 2001 From: Sasha Koss Date: Fri, 14 May 2021 12:27:09 +0800 Subject: [PATCH 27/32] Write good test example --- src/millisecondsToMinutes/test.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/millisecondsToMinutes/test.ts b/src/millisecondsToMinutes/test.ts index 616a42156e..3d14345de0 100644 --- a/src/millisecondsToMinutes/test.ts +++ b/src/millisecondsToMinutes/test.ts @@ -3,24 +3,19 @@ import assert from 'assert' import millisecondsToMinutes from '.' -describe('millisecondsToMinutes', function () { - it('converts 50000 milliseconds to minutes', function () { - const result = millisecondsToMinutes(50000) - assert(result === 0) +describe('millisecondsToMinutes', () => { + it('converts milliseconds to minutes', function () { + assert(millisecondsToMinutes(60000) === 1) + assert(millisecondsToMinutes(120000) === 2) }) - it('converts 65000 milliseconds to minutes', function () { - const result = millisecondsToMinutes(65000) - assert(result === 1) + it('uses floor rounding', () => { + assert(millisecondsToMinutes(60001) === 1) + assert(millisecondsToMinutes(59999) === 0) }) - it('converts 190000 milliseconds to minutes', function () { - const result = millisecondsToMinutes(190000) - assert(result === 3) - }) - - it('converts 310000 milliseconds to minutes', function () { - const result = millisecondsToMinutes(310000) - assert(result === 5) + it('handles border values', () => { + assert(millisecondsToMinutes(60000.5) === 1) + assert(millisecondsToMinutes(0) === 0) }) }) From 5b216991666f5f5d07953f2cd95c4c6171a60542 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Mon, 24 May 2021 13:53:52 -0300 Subject: [PATCH 28/32] adding floor rounding --- src/quartersToMonths/index.ts | 2 +- src/weeksToDays/index.ts | 2 +- src/yearsToMonths/index.ts | 2 +- src/yearsToQuarters/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/quartersToMonths/index.ts b/src/quartersToMonths/index.ts index 810383ebea..1e52b8e4cc 100644 --- a/src/quartersToMonths/index.ts +++ b/src/quartersToMonths/index.ts @@ -21,5 +21,5 @@ import { monthsInQuarter } from '../constants/index' */ export default function quartersToMonths(quarters: number): number { requiredArgs(1, arguments) - return quarters * monthsInQuarter + return Math.floor(quarters * monthsInQuarter) } diff --git a/src/weeksToDays/index.ts b/src/weeksToDays/index.ts index 3db9b31576..6675186324 100644 --- a/src/weeksToDays/index.ts +++ b/src/weeksToDays/index.ts @@ -21,5 +21,5 @@ import { daysInWeek } from '../constants/index' */ export default function weeksToDays(weeks: number): number { requiredArgs(1, arguments) - return weeks * daysInWeek + return Math.floor(weeks * daysInWeek) } diff --git a/src/yearsToMonths/index.ts b/src/yearsToMonths/index.ts index f847dcf8f6..2e547bdb71 100644 --- a/src/yearsToMonths/index.ts +++ b/src/yearsToMonths/index.ts @@ -21,5 +21,5 @@ import { monthsInYear } from '../constants/index' */ export default function yearsToMonths(years: number): number { requiredArgs(1, arguments) - return years * monthsInYear + return Math.floor(years * monthsInYear) } diff --git a/src/yearsToQuarters/index.ts b/src/yearsToQuarters/index.ts index 3438440b42..223e7d5a8a 100644 --- a/src/yearsToQuarters/index.ts +++ b/src/yearsToQuarters/index.ts @@ -21,5 +21,5 @@ import { quartersInYear } from '../constants/index' */ export default function yearsToQuarters(years: number): number { requiredArgs(1, arguments) - return years * quartersInYear + return Math.floor(years * quartersInYear) } From d111b42f8ab5fba8bd543dfa4fc47bfbfc363c2d Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Mon, 24 May 2021 13:56:19 -0300 Subject: [PATCH 29/32] improving tests --- src/daysToWeeks/test.ts | 27 +++++++++++---------------- src/hoursToMilliseconds/test.ts | 17 ++++++----------- src/hoursToMinutes/test.ts | 16 ++++++---------- src/hoursToSeconds/test.ts | 17 ++++++----------- src/millisecondsToHours/test.ts | 22 +++++++++------------- src/millisecondsToSeconds/test.ts | 22 +++++++++------------- src/minutesToHours/test.ts | 23 +++++++++-------------- src/minutesToMilliseconds/test.ts | 17 ++++++----------- src/minutesToSeconds/test.ts | 17 ++++++----------- src/monthsToQuarters/test.ts | 23 +++++++++-------------- src/monthsToYears/test.ts | 23 +++++++++-------------- src/quartersToMonths/test.ts | 20 ++++++++++---------- src/quartersToYears/test.ts | 18 +++++++++--------- src/secondsToHours/test.ts | 23 +++++++++-------------- src/secondsToMilliseconds/test.ts | 17 ++++++----------- src/secondsToMinutes/test.ts | 23 +++++++++-------------- src/weeksToDays/test.ts | 18 +++++++++--------- src/yearsToMonths/test.ts | 18 +++++++++--------- src/yearsToQuarters/test.ts | 18 +++++++++--------- 19 files changed, 156 insertions(+), 223 deletions(-) diff --git a/src/daysToWeeks/test.ts b/src/daysToWeeks/test.ts index e80370035c..837d60c4c4 100644 --- a/src/daysToWeeks/test.ts +++ b/src/daysToWeeks/test.ts @@ -3,24 +3,19 @@ import assert from 'assert' import daysToWeeks from '.' -describe('daysToWeeks', function () { - it('converts 5 days to weeks', function () { - const result = daysToWeeks(5) - assert(result === 0) +describe('daysToWeeks', () => { + it('converts days to weeks', function () { + assert(daysToWeeks(7) === 1) + assert(daysToWeeks(14) === 2) }) - it('converts 8 days to weeks', function () { - const result = daysToWeeks(8) - assert(result === 1) + it('uses floor rounding', () => { + assert(daysToWeeks(8) === 1) + assert(daysToWeeks(6) === 0) }) - it('converts 13 days to weeks', function () { - const result = daysToWeeks(13) - assert(result === 1) + it('handles border values', () => { + assert(daysToWeeks(7.5) === 1) + assert(daysToWeeks(0) === 0) }) - - it('converts 15 days to weeks', function () { - const result = daysToWeeks(15) - assert(result === 2) - }) -}) +}) \ No newline at end of file diff --git a/src/hoursToMilliseconds/test.ts b/src/hoursToMilliseconds/test.ts index f0690fa2f2..de9441dff5 100644 --- a/src/hoursToMilliseconds/test.ts +++ b/src/hoursToMilliseconds/test.ts @@ -4,18 +4,13 @@ import assert from 'assert' import hoursToMilliseconds from '.' describe('hoursToMilliseconds', function () { - it('converts 1 hour to milliseconds', function () { - const result = hoursToMilliseconds(1) - assert(result === 3600000) + it('converts hours to milliseconds', function () { + assert(hoursToMilliseconds(1) === 3600000) + assert(hoursToMilliseconds(2) === 7200000) }) - it('converts 2 hours to milliseconds', function () { - const result = hoursToMilliseconds(2) - assert(result === 7200000) - }) - - it('converts 5 hours to milliseconds', function () { - const result = hoursToMilliseconds(5) - assert(result === 18000000) + it('handles border values', () => { + assert(hoursToMilliseconds(1.5) === 5400000) + assert(hoursToMilliseconds(0) === 0) }) }) diff --git a/src/hoursToMinutes/test.ts b/src/hoursToMinutes/test.ts index bdb535fdaf..17d2628392 100644 --- a/src/hoursToMinutes/test.ts +++ b/src/hoursToMinutes/test.ts @@ -4,18 +4,14 @@ import assert from 'assert' import hoursToMinutes from '.' describe('hoursToMinutes', function () { - it('converts 2 hours to minutes', function () { - const result = hoursToMinutes(2) - assert(result === 120) + it('converts hours to minutes', function () { + assert(hoursToMinutes(1) === 60) + assert(hoursToMinutes(2) === 120) }) - it('converts 5 hours to minutes', function () { - const result = hoursToMinutes(5) - assert(result === 300) + it('handles border values', () => { + assert(hoursToMinutes(1.5) === 90) + assert(hoursToMinutes(0) === 0) }) - it('converts 7 hours to minutes', function () { - const result = hoursToMinutes(7) - assert(result === 420) - }) }) diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts index 40b4027362..bfc0da5ce4 100644 --- a/src/hoursToSeconds/test.ts +++ b/src/hoursToSeconds/test.ts @@ -4,18 +4,13 @@ import assert from 'assert' import hoursToSeconds from '.' describe('hoursToSeconds', function () { - it('converts 2 hours to seconds', function () { - const result = hoursToSeconds(2) - assert(result === 7200) + it('converts hours to seconds', function () { + assert(hoursToSeconds(1) === 3600) + assert(hoursToSeconds(2) === 7200) }) - it('converts 5 hours to seconds', function () { - const result = hoursToSeconds(5) - assert(result === 18000) - }) - - it('converts 7 hours to seconds', function () { - const result = hoursToSeconds(7) - assert(result === 25200) + it('handles border values', () => { + assert(hoursToSeconds(1.5) === 5400) + assert(hoursToSeconds(0) === 0) }) }) diff --git a/src/millisecondsToHours/test.ts b/src/millisecondsToHours/test.ts index 3ebf993c20..5fed366fec 100644 --- a/src/millisecondsToHours/test.ts +++ b/src/millisecondsToHours/test.ts @@ -4,23 +4,19 @@ import assert from 'assert' import millisecondsToHours from '.' describe('millisecondsToHours', function () { - it('converts 3500000 milliseconds to hours', function () { - const result = millisecondsToHours(3500000) - assert.deepStrictEqual(result, 0) - }) - it('converts 7000000 milliseconds to hours', function () { - const result = millisecondsToHours(7000000) - assert.deepStrictEqual(result, 1) + it('converts milliseconds to hours', function () { + assert(millisecondsToHours(3600000) === 1) + assert(millisecondsToHours(7200000) === 2) }) - it('converts 7600000 milliseconds to hours', function () { - const result = millisecondsToHours(7600000) - assert.deepStrictEqual(result, 2) + it('uses floor rounding', () => { + assert(millisecondsToHours(3600001) === 1) + assert(millisecondsToHours(3599999) === 0) }) - it('converts 18000000 milliseconds to hours', function () { - const result = millisecondsToHours(18000000) - assert.deepStrictEqual(result, 5) + it('handles border values', () => { + assert(millisecondsToHours(3600000.5) === 1) + assert(millisecondsToHours(0) === 0) }) }) diff --git a/src/millisecondsToSeconds/test.ts b/src/millisecondsToSeconds/test.ts index f2071d6ac8..6e3c15bb11 100644 --- a/src/millisecondsToSeconds/test.ts +++ b/src/millisecondsToSeconds/test.ts @@ -4,23 +4,19 @@ import assert from 'assert' import millisecondsToSeconds from '.' describe('millisecondsToSeconds', function () { - it('converts 700 milliseconds to seconds', function () { - const result = millisecondsToSeconds(700) - assert(result === 0) - }) - it('converts 1500 milliseconds to seconds', function () { - const result = millisecondsToSeconds(1500) - assert(result === 1) + it('converts milliseconds to seconds', function () { + assert(millisecondsToSeconds(1000) === 1) + assert(millisecondsToSeconds(2000) === 2) }) - it('converts 3500 milliseconds to seconds', function () { - const result = millisecondsToSeconds(3500) - assert(result === 3) + it('uses floor rounding', () => { + assert(millisecondsToSeconds(1001) === 1) + assert(millisecondsToSeconds(999) === 0) }) - it('converts 5500 milliseconds to seconds', function () { - const result = millisecondsToSeconds(5500) - assert(result === 5) + it('handles border values', () => { + assert(millisecondsToSeconds(1000.5) === 1) + assert(millisecondsToSeconds(0) === 0) }) }) diff --git a/src/minutesToHours/test.ts b/src/minutesToHours/test.ts index b4f5625f88..be34522961 100644 --- a/src/minutesToHours/test.ts +++ b/src/minutesToHours/test.ts @@ -4,23 +4,18 @@ import assert from 'assert' import minuteToHours from '.' describe('minuteToHours', function () { - it('converts 50 minutes to hours', function () { - const result = minuteToHours(50) - assert(result === 0) + it('converts minutes to hours', function () { + assert(minuteToHours(60) === 1) + assert(minuteToHours(120) === 2) }) - it('converts 90 minutes to hours', function () { - const result = minuteToHours(90) - assert(result === 1) + it('uses floor rounding', () => { + assert(minuteToHours(61) === 1) + assert(minuteToHours(59) === 0) }) - it('converts 140 minutes to hours', function () { - const result = minuteToHours(140) - assert(result === 2) - }) - - it('converts 310 minutes to hours', function () { - const result = minuteToHours(310) - assert(result === 5) + it('handles border values', () => { + assert(minuteToHours(60.5) === 1) + assert(minuteToHours(0) === 0) }) }) diff --git a/src/minutesToMilliseconds/test.ts b/src/minutesToMilliseconds/test.ts index 17cc974008..3fb9afb391 100644 --- a/src/minutesToMilliseconds/test.ts +++ b/src/minutesToMilliseconds/test.ts @@ -4,18 +4,13 @@ import assert from 'assert' import minutesToMilliseconds from '.' describe('minutesToMilliseconds', function () { - it('converts 1 minute to milliseconds', function () { - const result = minutesToMilliseconds(1) - assert(result === 60000) + it('converts minutes to milliseconds', function () { + assert(minutesToMilliseconds(1) === 60000) + assert(minutesToMilliseconds(2) === 120000) }) - it('converts 3 minutes to milliseconds', function () { - const result = minutesToMilliseconds(3) - assert(result === 180000) - }) - - it('converts 5 minutes to milliseconds', function () { - const result = minutesToMilliseconds(5) - assert(result === 300000) + it('handles border values', () => { + assert(minutesToMilliseconds(1.5) === 90000) + assert(minutesToMilliseconds(0) === 0) }) }) diff --git a/src/minutesToSeconds/test.ts b/src/minutesToSeconds/test.ts index 8297f0b628..d5b887f799 100644 --- a/src/minutesToSeconds/test.ts +++ b/src/minutesToSeconds/test.ts @@ -4,18 +4,13 @@ import assert from 'assert' import minutesToSeconds from '.' describe('minutesToSeconds', function () { - it('converts 1 minute to seconds', function () { - const result = minutesToSeconds(1) - assert(result === 60) + it('converts minutes to seconds', function () { + assert(minutesToSeconds(1) === 60) + assert(minutesToSeconds(2) === 120) }) - it('converts 3 minutes to seconds', function () { - const result = minutesToSeconds(3) - assert(result === 180) - }) - - it('converts 5 minutes to seconds', function () { - const result = minutesToSeconds(5) - assert(result === 300) + it('handles border values', () => { + assert(minutesToSeconds(1.5) === 90) + assert(minutesToSeconds(0) === 0) }) }) diff --git a/src/monthsToQuarters/test.ts b/src/monthsToQuarters/test.ts index 7e85069bff..a1907d3299 100644 --- a/src/monthsToQuarters/test.ts +++ b/src/monthsToQuarters/test.ts @@ -4,23 +4,18 @@ import assert from 'assert' import monthsToQuarters from '.' describe('monthsToQuarters', function () { - it('converts 2 months to quarters', function () { - const result = monthsToQuarters(2) - assert(result === 0) + it('converts months to quarters', function () { + assert(monthsToQuarters(3) === 1) + assert(monthsToQuarters(6) === 2) }) - it('converts 4 months to quarters', function () { - const result = monthsToQuarters(4) - assert(result === 1) + it('uses floor rounding', () => { + assert(monthsToQuarters(4) === 1) + assert(monthsToQuarters(2) === 0) }) - it('converts 10 months to quarters', function () { - const result = monthsToQuarters(10) - assert(result === 3) - }) - - it('converts 15 months to quarters', function () { - const result = monthsToQuarters(15) - assert(result === 5) + it('handles border values', () => { + assert(monthsToQuarters(3.5) === 1) + assert(monthsToQuarters(0) === 0) }) }) diff --git a/src/monthsToYears/test.ts b/src/monthsToYears/test.ts index c437514daf..5aa86c9769 100644 --- a/src/monthsToYears/test.ts +++ b/src/monthsToYears/test.ts @@ -4,23 +4,18 @@ import assert from 'assert' import monthsToYears from '.' describe('monthsToYears', function () { - it('converts 10 months to year', function () { - const result = monthsToYears(10) - assert(result === 0) + it('converts months to years', function () { + assert(monthsToYears(12) === 1) + assert(monthsToYears(24) === 2) }) - it('converts 15 months to year', function () { - const result = monthsToYears(15) - assert(result === 1) + it('uses floor rounding', () => { + assert(monthsToYears(13) === 1) + assert(monthsToYears(11) === 0) }) - it('converts 40 months to year', function () { - const result = monthsToYears(40) - assert(result === 3) - }) - - it('converts 65 months to year', function () { - const result = monthsToYears(65) - assert(result === 5) + it('handles border values', () => { + assert(monthsToYears(12.5) === 1) + assert(monthsToYears(0) === 0) }) }) diff --git a/src/quartersToMonths/test.ts b/src/quartersToMonths/test.ts index 5fc20a8021..8fb7f41fde 100644 --- a/src/quartersToMonths/test.ts +++ b/src/quartersToMonths/test.ts @@ -4,18 +4,18 @@ import assert from 'assert' import quartersToMonths from '.' describe('quartersToMonths', function () { - it('converts 1 quarter to months', function () { - const result = quartersToMonths(1) - assert(result === 3) + it('converts quarters to months', function () { + assert(quartersToMonths(1) === 3) + assert(quartersToMonths(2) === 6) }) - - it('converts 3 quarters to months', function () { - const result = quartersToMonths(3) - assert(result === 9) + + it('uses floor rounding', () => { + assert(quartersToMonths(1.5) === 4) + assert(quartersToMonths(0.3) === 0) }) - it('converts 5 quarters to months', function () { - const result = quartersToMonths(5) - assert(result === 15) + it('handles border values', () => { + assert(quartersToMonths(0.4) === 1) + assert(quartersToMonths(0) === 0) }) }) diff --git a/src/quartersToYears/test.ts b/src/quartersToYears/test.ts index 7100a96e83..7fe9f6f090 100644 --- a/src/quartersToYears/test.ts +++ b/src/quartersToYears/test.ts @@ -4,18 +4,18 @@ import assert from 'assert' import quartersToYears from '.' describe('quartersToYears', function () { - it('converts 3 quarters to years', function () { - const result = quartersToYears(3) - assert(result === 0) + it('converts quarters to years', function () { + assert(quartersToYears(4) === 1) + assert(quartersToYears(8) === 2) }) - it('converts 5 quarters to years', function () { - const result = quartersToYears(5) - assert(result === 1) + it('uses floor rounding', () => { + assert(quartersToYears(5) === 1) + assert(quartersToYears(3) === 0) }) - it('converts 13 quarters to years', function () { - const result = quartersToYears(13) - assert(result === 3) + it('handles border values', () => { + assert(quartersToYears(4.5) === 1) + assert(quartersToYears(0) === 0) }) }) diff --git a/src/secondsToHours/test.ts b/src/secondsToHours/test.ts index dd194dce64..12b3ecfdeb 100644 --- a/src/secondsToHours/test.ts +++ b/src/secondsToHours/test.ts @@ -4,23 +4,18 @@ import assert from 'assert' import secondsToHours from '.' describe('secondsToHours', function () { - it('converts 3000 seconds to hours', function () { - const result = secondsToHours(3000) - assert(result === 0) + it('converts seconds to hours', function () { + assert(secondsToHours(3600) === 1) + assert(secondsToHours(7200) === 2) }) - it('converts 3700 seconds to hours', function () { - const result = secondsToHours(3700) - assert(result === 1) + it('uses floor rounding', () => { + assert(secondsToHours(3601) === 1) + assert(secondsToHours(3599) === 0) }) - it('converts 11000 seconds to hours', function () { - const result = secondsToHours(11000) - assert(result === 3) - }) - - it('converts 19000 seconds to hours', function () { - const result = secondsToHours(19000) - assert(result === 5) + it('handles border values', () => { + assert(secondsToHours(3600.5) === 1) + assert(secondsToHours(0) === 0) }) }) diff --git a/src/secondsToMilliseconds/test.ts b/src/secondsToMilliseconds/test.ts index f47d8433e6..26bc2eb50c 100644 --- a/src/secondsToMilliseconds/test.ts +++ b/src/secondsToMilliseconds/test.ts @@ -4,18 +4,13 @@ import assert from 'assert' import secondsToMilliseconds from '.' describe('secondsToMilliseconds', function () { - it('converts 1 second to milliseconds', function () { - const result = secondsToMilliseconds(1) - assert(result === 1000) + it('converts seconds to milliseconds', function () { + assert(secondsToMilliseconds(1) === 1000) + assert(secondsToMilliseconds(2) === 2000) }) - it('converts 3 seconds to milliseconds', function () { - const result = secondsToMilliseconds(3) - assert(result === 3000) - }) - - it('converts 5 seconds to milliseconds', function () { - const result = secondsToMilliseconds(5) - assert(result === 5000) + it('handles border values', () => { + assert(secondsToMilliseconds(1.5) === 1500) + assert(secondsToMilliseconds(0) === 0) }) }) diff --git a/src/secondsToMinutes/test.ts b/src/secondsToMinutes/test.ts index daae992e03..3cf59e9518 100644 --- a/src/secondsToMinutes/test.ts +++ b/src/secondsToMinutes/test.ts @@ -4,23 +4,18 @@ import assert from 'assert' import secondsToMinutes from '.' describe('secondsToMinutes', function () { - it('converts 50 seconds to minutes', function () { - const result = secondsToMinutes(50) - assert(result === 0) + it('converts seconds to minutes', function () { + assert(secondsToMinutes(60) === 1) + assert(secondsToMinutes(120) === 2) }) - it('converts 70 seconds to minutes', function () { - const result = secondsToMinutes(70) - assert(result === 1) + it('uses floor rounding', () => { + assert(secondsToMinutes(61) === 1) + assert(secondsToMinutes(59) === 0) }) - it('converts 190 seconds to minutes', function () { - const result = secondsToMinutes(190) - assert(result === 3) - }) - - it('converts 310 seconds to minutes', function () { - const result = secondsToMinutes(310) - assert(result === 5) + it('handles border values', () => { + assert(secondsToMinutes(60.5) === 1) + assert(secondsToMinutes(0) === 0) }) }) diff --git a/src/weeksToDays/test.ts b/src/weeksToDays/test.ts index da62768ad2..bece726117 100644 --- a/src/weeksToDays/test.ts +++ b/src/weeksToDays/test.ts @@ -4,18 +4,18 @@ import assert from 'assert' import weeksToDays from '.' describe('weeksToDays', function () { - it('converts 1 week to days', function () { - const result = weeksToDays(1) - assert(result === 7) + it('converts weeks to days', function () { + assert(weeksToDays(1) === 7) + assert(weeksToDays(2) === 14) }) - it('converts 3 weeks to days', function () { - const result = weeksToDays(3) - assert(result === 21) + it('uses floor rounding', () => { + assert(weeksToDays(1.5) === 10) + assert(weeksToDays(0.1) === 0) }) - it('converts 5 weeks to days', function () { - const result = weeksToDays(5) - assert(result === 35) + it('handles border values', () => { + assert(weeksToDays(1.5) === 1) + assert(weeksToDays(0) === 0) }) }) diff --git a/src/yearsToMonths/test.ts b/src/yearsToMonths/test.ts index 4c739afab8..e91231cfc2 100644 --- a/src/yearsToMonths/test.ts +++ b/src/yearsToMonths/test.ts @@ -4,18 +4,18 @@ import assert from 'assert' import yearsToMonths from '.' describe('yearsToMonths', function () { - it('converts 1 year to months', function () { - const result = yearsToMonths(1) - assert(result === 12) + it('converts years to months', function () { + assert(yearsToMonths(1) === 12) + assert(yearsToMonths(2) === 24) }) - it('converts 3 years to months', function () { - const result = yearsToMonths(3) - assert(result === 36) + it('uses floor rounding', () => { + assert(yearsToMonths(1.7) === 20) + assert(yearsToMonths(0.1) === 1) }) - it('converts 5 years to months', function () { - const result = yearsToMonths(5) - assert(result === 60) + it('handles border values', () => { + assert(yearsToMonths(1.5) === 18) + assert(yearsToMonths(0) === 0) }) }) diff --git a/src/yearsToQuarters/test.ts b/src/yearsToQuarters/test.ts index e23eb2c2f7..a08ef68062 100644 --- a/src/yearsToQuarters/test.ts +++ b/src/yearsToQuarters/test.ts @@ -4,18 +4,18 @@ import assert from 'assert' import yearsToQuarters from '.' describe('yearsToQuarters', function () { - it('converts 1 year to quarters', function () { - const result = yearsToQuarters(1) - assert(result === 4) + it('converts years to quarters', function () { + assert(yearsToQuarters(1) === 4) + assert(yearsToQuarters(2) === 8) }) - it('converts 3 years to quarters', function () { - const result = yearsToQuarters(3) - assert(result === 12) + it('uses floor rounding', () => { + assert(yearsToQuarters(1.3) === 5) + assert(yearsToQuarters(0.2) === 0) }) - it('converts 5 years to quarters', function () { - const result = yearsToQuarters(5) - assert(result === 20) + it('handles border values', () => { + assert(yearsToQuarters(1.5) === 6) + assert(yearsToQuarters(0) === 0) }) }) From d4a64725862e204d7b36412689b8ffbdb0737729 Mon Sep 17 00:00:00 2001 From: Tetiana Date: Tue, 25 May 2021 16:37:44 +0100 Subject: [PATCH 30/32] Fix test --- src/weeksToDays/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/weeksToDays/test.ts b/src/weeksToDays/test.ts index bece726117..46bbab1609 100644 --- a/src/weeksToDays/test.ts +++ b/src/weeksToDays/test.ts @@ -15,7 +15,7 @@ describe('weeksToDays', function () { }) it('handles border values', () => { - assert(weeksToDays(1.5) === 1) + assert(weeksToDays(1.5) === 10) assert(weeksToDays(0) === 0) }) }) From 27f1bd1a9c6ba5aed956909cf8e51d0db3fc136e Mon Sep 17 00:00:00 2001 From: Tetiana Date: Tue, 25 May 2021 16:48:50 +0100 Subject: [PATCH 31/32] Order constants by name asc, fix docs --- src/constants/index.ts | 51 +++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index bc7b7a38a8..8774764232 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,5 +1,6 @@ /** * Days in 1 week. + * * @constant * @type {number} * @default @@ -7,31 +8,54 @@ export const daysInWeek = 7 /** - * Milliseconds in 1 hour + * Maximum allowed time. + * * @constant * @type {number} * @default */ -export const millisecondsInHour = 3600000 +export const maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000 /** * Milliseconds in 1 minute + * * @constant * @type {number} * @default */ export const millisecondsInMinute = 60000 +/** + * Milliseconds in 1 hour + * + * @constant + * @type {number} + * @default + */ +export const millisecondsInHour = 3600000 + /** * Milliseconds in 1 second + * * @constant * @type {number} * @default */ export const millisecondsInSecond = 1000 +/** + * Minimum allowed time. + * + * @name minTime + * @constant + * @type {number} + * @default + */ +export const minTime = -maxTime + /** * Minutes in 1 hour + * * @constant * @type {number} * @default @@ -40,6 +64,7 @@ export const minutesInHour = 60 /** * Months in 1 quarter + * * @constant * @type {number} * @default @@ -48,6 +73,7 @@ export const monthsInQuarter = 3 /** * Months in 1 year + * * @constant * @type {number} * @default @@ -56,6 +82,7 @@ export const monthsInYear = 12 /** * Quarters in 1 year + * * @constant * @type {number} * @default @@ -64,6 +91,7 @@ export const quartersInYear = 4 /** * Seconds in 1 hour + * * @constant * @type {number} * @default @@ -72,26 +100,9 @@ export const secondsInHour = 3600 /** * Seconds in 1 minute + * * @constant * @type {number} * @default */ export const secondsInMinute = 60 - -/** - * Maximum allowed time. - * @constant - * @type {number} - * @default - */ -export const maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000 - -/** - * Minimum allowed time. - * - * @name minTime - * @constant - * @type {number} - * @default - */ -export const minTime = -maxTime From dc4b0599612142e4b01be2b14ef118c14632d5cb Mon Sep 17 00:00:00 2001 From: Sasha Koss Date: Fri, 28 May 2021 13:11:34 +0800 Subject: [PATCH 32/32] Add missing floor to conversion functions --- deno | 1 + src/hoursToMilliseconds/index.ts | 2 +- src/hoursToMilliseconds/test.ts | 4 ++++ src/hoursToMinutes/index.ts | 2 +- src/hoursToMinutes/test.ts | 5 ++++- src/hoursToSeconds/index.ts | 2 +- src/hoursToSeconds/test.ts | 4 ++++ src/minutesToMilliseconds/index.ts | 2 +- src/minutesToMilliseconds/test.ts | 4 ++++ src/minutesToSeconds/index.ts | 2 +- src/minutesToSeconds/test.ts | 4 ++++ 11 files changed, 26 insertions(+), 6 deletions(-) create mode 160000 deno diff --git a/deno b/deno new file mode 160000 index 0000000000..e5bc4fec20 --- /dev/null +++ b/deno @@ -0,0 +1 @@ +Subproject commit e5bc4fec20722aae2cc133284fdcc17ad366a95c diff --git a/src/hoursToMilliseconds/index.ts b/src/hoursToMilliseconds/index.ts index a5f9c0633c..e87c7a30bc 100644 --- a/src/hoursToMilliseconds/index.ts +++ b/src/hoursToMilliseconds/index.ts @@ -21,5 +21,5 @@ import { millisecondsInHour } from '../constants/index' */ export default function hoursToMilliseconds(hours: number): number { requiredArgs(1, arguments) - return hours * millisecondsInHour + return Math.floor(hours * millisecondsInHour) } diff --git a/src/hoursToMilliseconds/test.ts b/src/hoursToMilliseconds/test.ts index de9441dff5..fdc426cdcd 100644 --- a/src/hoursToMilliseconds/test.ts +++ b/src/hoursToMilliseconds/test.ts @@ -9,6 +9,10 @@ describe('hoursToMilliseconds', function () { assert(hoursToMilliseconds(2) === 7200000) }) + it('uses floor rounding', () => { + assert(hoursToMilliseconds(0.123456) === 444441) + }) + it('handles border values', () => { assert(hoursToMilliseconds(1.5) === 5400000) assert(hoursToMilliseconds(0) === 0) diff --git a/src/hoursToMinutes/index.ts b/src/hoursToMinutes/index.ts index 213bb53253..dcf61de474 100644 --- a/src/hoursToMinutes/index.ts +++ b/src/hoursToMinutes/index.ts @@ -21,5 +21,5 @@ import { minutesInHour } from '../constants/index' */ export default function hoursToMinutes(hours: number): number { requiredArgs(1, arguments) - return hours * minutesInHour + return Math.floor(hours * minutesInHour) } diff --git a/src/hoursToMinutes/test.ts b/src/hoursToMinutes/test.ts index 17d2628392..ead8b2160d 100644 --- a/src/hoursToMinutes/test.ts +++ b/src/hoursToMinutes/test.ts @@ -9,9 +9,12 @@ describe('hoursToMinutes', function () { assert(hoursToMinutes(2) === 120) }) + it('uses floor rounding', () => { + assert(hoursToMinutes(0.123) === 7) + }) + it('handles border values', () => { assert(hoursToMinutes(1.5) === 90) assert(hoursToMinutes(0) === 0) }) - }) diff --git a/src/hoursToSeconds/index.ts b/src/hoursToSeconds/index.ts index 5a942fb3ac..36298808bc 100644 --- a/src/hoursToSeconds/index.ts +++ b/src/hoursToSeconds/index.ts @@ -21,5 +21,5 @@ import { secondsInHour } from '../constants/index' */ export default function hoursToSeconds(hours: number): number { requiredArgs(1, arguments) - return hours * secondsInHour + return Math.floor(hours * secondsInHour) } diff --git a/src/hoursToSeconds/test.ts b/src/hoursToSeconds/test.ts index bfc0da5ce4..b2e129bdc1 100644 --- a/src/hoursToSeconds/test.ts +++ b/src/hoursToSeconds/test.ts @@ -9,6 +9,10 @@ describe('hoursToSeconds', function () { assert(hoursToSeconds(2) === 7200) }) + it('uses floor rounding', () => { + assert(hoursToSeconds(0.123) === 442) + }) + it('handles border values', () => { assert(hoursToSeconds(1.5) === 5400) assert(hoursToSeconds(0) === 0) diff --git a/src/minutesToMilliseconds/index.ts b/src/minutesToMilliseconds/index.ts index d26a9df8d7..dd95314550 100644 --- a/src/minutesToMilliseconds/index.ts +++ b/src/minutesToMilliseconds/index.ts @@ -21,5 +21,5 @@ import { millisecondsInMinute } from '../constants/index' */ export default function minutesToMilliseconds(minutes: number): number { requiredArgs(1, arguments) - return minutes * millisecondsInMinute + return Math.floor(minutes * millisecondsInMinute) } diff --git a/src/minutesToMilliseconds/test.ts b/src/minutesToMilliseconds/test.ts index 3fb9afb391..4864a2b76b 100644 --- a/src/minutesToMilliseconds/test.ts +++ b/src/minutesToMilliseconds/test.ts @@ -9,6 +9,10 @@ describe('minutesToMilliseconds', function () { assert(minutesToMilliseconds(2) === 120000) }) + it('uses floor rounding', () => { + assert(minutesToMilliseconds(0.123456) === 7407) + }) + it('handles border values', () => { assert(minutesToMilliseconds(1.5) === 90000) assert(minutesToMilliseconds(0) === 0) diff --git a/src/minutesToSeconds/index.ts b/src/minutesToSeconds/index.ts index 07226098d4..d4b5c4c53e 100644 --- a/src/minutesToSeconds/index.ts +++ b/src/minutesToSeconds/index.ts @@ -21,5 +21,5 @@ import { secondsInMinute } from '../constants/index' */ export default function minutesToSeconds(minutes: number): number { requiredArgs(1, arguments) - return minutes * secondsInMinute + return Math.floor(minutes * secondsInMinute) } diff --git a/src/minutesToSeconds/test.ts b/src/minutesToSeconds/test.ts index d5b887f799..9cdd4c28b6 100644 --- a/src/minutesToSeconds/test.ts +++ b/src/minutesToSeconds/test.ts @@ -9,6 +9,10 @@ describe('minutesToSeconds', function () { assert(minutesToSeconds(2) === 120) }) + it('uses floor rounding', () => { + assert(minutesToSeconds(0.123456) === 7) + }) + it('handles border values', () => { assert(minutesToSeconds(1.5) === 90) assert(minutesToSeconds(0) === 0)