Created
November 16, 2019 22:15
-
-
Save naugtur/962a4b4e008268d49d2476ad170141f3 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 locales = ['en', 'pl'] | |
export function likelyContainsTodaysDate(text: string): number { | |
text = text.toLocaleLowerCase() | |
const today = new Date() | |
const numDay = today.getDate() | |
const numMonth = today.getUTCMonth() + 1 | |
const separators = ['.', '/', '-'] | |
const vocabulary = [ | |
...locales.map(loc => today.toLocaleString(loc, { month: 'long' })), | |
...locales.map(loc => today.toLocaleString(loc, { month: 'short' })), | |
...separators.map(se => numDay + se + numMonth), | |
...separators.map(se => numMonth + se + numDay), | |
'' + numMonth, | |
'' + numDay | |
] | |
return vocabulary.reduce((score, bit) => { | |
if (text.includes(bit)) { | |
score++ | |
} | |
return score; | |
}, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment