77*/
88
99import { isLeapYear } from '../Maths/LeapYear'
10+ import { parseDate } from '../Timing-Functions/ParseDate'
1011
1112const DateToDay = ( dd , mm , yyyy ) => {
1213 return (
@@ -20,32 +21,13 @@ const DateToDay = (dd, mm, yyyy) => {
2021 )
2122}
2223
23- const CheckDayAndMonth = ( inDay , inMonth ) => {
24- if ( inDay <= 0 || inDay > 31 || inMonth <= 0 || inMonth > 12 ) {
25- throw new TypeError ( 'Date is not valid.' )
26- }
27- }
28-
2924const DateDayDifference = ( date1 , date2 ) => {
30- // firstly, check that both input are string or not.
31- if ( typeof date1 !== 'string' || typeof date2 !== 'string' ) {
32- throw new TypeError ( 'Argument is not a string.' )
33- }
34- // extract the first date
35- const [ firstDateDay , firstDateMonth , firstDateYear ] = date1
36- . split ( '/' )
37- . map ( ( ele ) => Number ( ele ) )
38- // extract the second date
39- const [ secondDateDay , secondDateMonth , secondDateYear ] = date2
40- . split ( '/' )
41- . map ( ( ele ) => Number ( ele ) )
42- // check the both data are valid or not.
43- CheckDayAndMonth ( firstDateDay , firstDateMonth )
44- CheckDayAndMonth ( secondDateDay , secondDateMonth )
25+ const firstDate = parseDate ( date1 )
26+ const secondDate = parseDate ( date2 )
4527
4628 return Math . abs (
47- DateToDay ( secondDateDay , secondDateMonth , secondDateYear ) -
48- DateToDay ( firstDateDay , firstDateMonth , firstDateYear )
29+ DateToDay ( secondDate . day , secondDate . month , secondDate . year ) -
30+ DateToDay ( firstDate . day , firstDate . month , firstDate . year )
4931 )
5032}
5133
0 commit comments