Skip to content

Instantly share code, notes, and snippets.

@gapurov
Last active May 22, 2019 08:11
Show Gist options
  • Save gapurov/f9c0f2437431bb3908c9bebe8b9a27af to your computer and use it in GitHub Desktop.
Save gapurov/f9c0f2437431bb3908c9bebe8b9a27af to your computer and use it in GitHub Desktop.
parseDateDINToISO
parseDateDINToISO = str => {
if (/^(\d{4})-(\d{1,2})-(\d{1,2})$/.test(str)) return str;
const m = str.match(/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/);
// return m ? new Date(m[3], m[2] - 1, m[1]) : undefined;
return m ? `${m[3]}-${m[2]}-${m[1]}` : undefined;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment