Created
June 27, 2019 09:50
-
-
Save andrewborisov/eb8439368b0aa2547bdce31ad418808b to your computer and use it in GitHub Desktop.
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
const CompareDatesEnumType = 'equal' | 'first' | 'invalid' | 'second'; | |
const CompareDatesEnum = { | |
equal: 'equal', | |
first: 'first', | |
invalid: 'invalid', | |
second: 'second', | |
}; | |
const compareDates = (firstDate: string = '01.01.1970', secondDate: string = '01.01.1970'): CompareDatesEnumType => { | |
const firstDateObject = new Date(dmyToMdyFormatter(firstDate)); | |
const secondDateObject = new Date(dmyToMdyFormatter(secondDate)); | |
if (isNaN(firstDateObject.getTime()) || isNaN(secondDateObject.getTime())) { | |
return CompareDatesEnum.invalid; | |
} | |
if (firstDateObject > secondDateObject) { | |
return CompareDatesEnum.first; | |
} | |
if (firstDateObject < secondDateObject) { | |
return CompareDatesEnum.second; | |
} | |
return CompareDatesEnum.equal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment