-
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.
feat: changed multiple commands to be used directly with console.log
- Loading branch information
1 parent
8a816a5
commit dc5176b
Showing
6 changed files
with
100 additions
and
51 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,31 @@ | ||
/** | ||
* @file src/getTimeString.test.ts | ||
* @author dworac <mail@dworac.com> | ||
* | ||
* This file contains the tests for the getTimeString function. | ||
*/ | ||
|
||
import getTimeString from "./getTimeString"; | ||
|
||
describe("getTimeString", () => { | ||
test("should return a string", () => { | ||
const result = getTimeString(); | ||
expect(typeof result).toBe("string"); | ||
}); | ||
|
||
test("should return a string formatted as [hh:mm:ss]", () => { | ||
const result = getTimeString(); | ||
const timeRegex = /\[\d{2}:\d{2}:\d{2}\]/; | ||
expect(timeRegex.test(result)).toBeTruthy(); | ||
}); | ||
|
||
test("should return a string that starts with a [", () => { | ||
const result = getTimeString(); | ||
expect(result.charAt(0)).toBe("["); | ||
}); | ||
|
||
test("should return a string that ends with a ]", () => { | ||
const result = getTimeString(); | ||
expect(result.charAt(result.length - 1)).toBe("]"); | ||
}); | ||
}); |
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,39 @@ | ||
/** | ||
* @file src/getTimeString.ts | ||
* @author dworac <mail@dworac.com> | ||
* | ||
* This file contains the getTimeString function. | ||
*/ | ||
|
||
/** | ||
* Pads a date part with a leading zero if necessary. | ||
* | ||
* @param {number} datePart - The date part to pad. | ||
* @returns {string} The padded date part. | ||
*/ | ||
export const padDatePart = (datePart: number) => { | ||
const { length } = datePart.toString(); | ||
const padding = 2 - length; | ||
return `${"0".repeat(padding)}${datePart.toString()}`; | ||
}; | ||
|
||
/** | ||
* Returns a string containing the current time in the format [hh:mm:ss]. | ||
* | ||
* @returns {string} The current time. | ||
* @example | ||
* const time = getTimeString(); | ||
* console.log(time); // [12:34:56] | ||
*/ | ||
const getTimeString = () => { | ||
const date = new Date(); | ||
const hours = padDatePart(date.getHours()); | ||
const minutes = padDatePart(date.getMinutes()); | ||
const seconds = padDatePart(date.getSeconds()); | ||
|
||
const time = `${hours}:${minutes}:${seconds}`; | ||
|
||
return `[${time}]`; | ||
}; | ||
|
||
export default getTimeString; |
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
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