From 54eebf4e6d88b13d361ef1f376bbd7d639ed7203 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Sat, 16 Oct 2021 16:16:42 +0200 Subject: [PATCH 1/2] Remove pad-zero util --- src/utils/date-stringify.ts | 14 ++++++++------ test/unit/utils-pad-zero.js | 27 --------------------------- 2 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 test/unit/utils-pad-zero.js diff --git a/src/utils/date-stringify.ts b/src/utils/date-stringify.ts index 5020e5b92..a5f76dbf2 100644 --- a/src/utils/date-stringify.ts +++ b/src/utils/date-stringify.ts @@ -1,19 +1,21 @@ -import padZero from './pad-zero'; +function padTwoDigits(data: number): string { + return String(data).padStart(2, '0'); +} export default function dateStringify(date: unknown): string { if (date instanceof Date) { return ( date.getFullYear() + '/' + - padZero(2, date.getMonth() + 1) + + padTwoDigits(date.getMonth() + 1) + '/' + - padZero(2, date.getDate()) + + padTwoDigits(date.getDate()) + ' ' + - padZero(2, date.getHours()) + + padTwoDigits(date.getHours()) + ':' + - padZero(2, date.getMinutes()) + + padTwoDigits(date.getMinutes()) + ':' + - padZero(2, date.getSeconds()) + padTwoDigits(date.getSeconds()) ); } diff --git a/test/unit/utils-pad-zero.js b/test/unit/utils-pad-zero.js deleted file mode 100644 index e9e29cffc..000000000 --- a/test/unit/utils-pad-zero.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -const expect = require('chai').expect; - -describe('utils : padZero', () => { - const padZero = require('../../dist/utils/pad-zero').default; - - describe('when the correct parameters are provided', () => { - const anyData = 3; - const anyValidStringLength = 5; - const paddedValue = padZero(anyValidStringLength, anyData); - - it('should return the correct padded string', () => { - expect(paddedValue).to.equal('00003'); - }); - }); - - describe('when the provided string length is shorter/equal than the length of the data', () => { - const anyData = 3; - const anyToShortStringLength = 1; - const paddedValue = padZero(anyToShortStringLength, anyData); - - it('should return original data as a string', () => { - expect(paddedValue).to.be.equal(anyData.toString()); - }); - }); -}); From 8d202b5c3773c7e002d8344cb00f35f70d88de27 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Sat, 16 Oct 2021 16:17:54 +0200 Subject: [PATCH 2/2] remove pad-zero --- src/utils/pad-zero.ts | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/utils/pad-zero.ts diff --git a/src/utils/pad-zero.ts b/src/utils/pad-zero.ts deleted file mode 100644 index 368abd323..000000000 --- a/src/utils/pad-zero.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default function padZero(length: number, data: number): string { - return Array(length - String(data).length + 1).join('0') + data; -}