-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from akhilome/bg-fix-date-160341907
#160341907 Fix Date Utility
- Loading branch information
Showing
4 changed files
with
35 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const padding = (number) => { | ||
if (Number.isNaN(Number(number)) || Number(number) < 1) return -1; | ||
if (`${number}`.length > 1 || number > 10) { | ||
return `${number}`; | ||
} | ||
return `0${number}`; | ||
}; | ||
|
||
export default padding; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'chai/register-should'; | ||
import padding from '../../server/utils/padding'; | ||
|
||
describe('Padding Function', () => { | ||
it('should return a padded number as string given a single digit', () => { | ||
padding(2).should.be.a('string').that.has.lengthOf(2); | ||
}); | ||
|
||
it('should not pad numbers which are not single digits', () => { | ||
padding(200).should.be.eql('200'); | ||
padding('01').should.be.eql('01'); | ||
}); | ||
|
||
it('should only pad numbers', () => { | ||
padding('Hey!').should.be.eql(-1); | ||
padding('22').should.be.eql('22'); | ||
padding('1').should.be.eql('01'); | ||
}); | ||
}); |