MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / parseDate

Function parseDate

Timing-Functions/ParseDate.js:9–25  ·  view source on GitHub ↗
(dateString)

Source from the content-addressed store, hash-verified

7}
8
9function parseDate(dateString) {
10 const regex = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/
11
12 const match = dateString.match(regex)
13
14 if (!match) {
15 throw new Error("Invalid date format. Please use 'dd/mm/yyyy'.")
16 }
17
18 const res = {
19 day: parseInt(match[1], 10),
20 month: parseInt(match[2], 10),
21 year: parseInt(match[3], 10)
22 }
23 checkDate(res)
24 return res
25}
26
27export { parseDate }

Callers 3

DateDayDifferenceFunction · 0.90
DateToDayFunction · 0.90
ParseDate.test.jsFile · 0.90

Calls 1

checkDateFunction · 0.85

Tested by

no test coverage detected