Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Format Date Advanced
Time flies, standards change. Let's get rid of the routine of changing the date format.
Create a formatDate function that accepts the date string, the old fromFormat array and the new toFormat array. Function returns given date in new format.
The function can change a separator, reorder the date parts of convert a year from 4 digits to 2 digits and back.
When converting from YYYY to YY just use 2 last digit (1997 -> 97).
When converting from YY to YYYY use 20YY if YY < 30 and 19YY otherwise.
Examples:
formatDate(
'2020-02-18',
['YYYY', 'MM', 'DD', '-'],
['YYYY', 'MM', 'DD', '.'],
); // '2020.02.18'
formatDate(
'2020-02-18',
['YYYY', 'MM', 'DD', '-'],
['DD', 'MM', 'YYYY', '.'],
); // '18.02.2020'
formatDate(
'18-02-2020',
['DD', 'MM', 'YYYY', '-'],
['DD', 'MM', 'YY', '/'],
); // '18/02/20'
formatDate(
'20/02/18',
['YY', 'MM', 'DD', '/'],
['YYYY', 'MM', 'DD', '.'],
); // '2020.02.18'
formatDate(
'97/02/18',
['YY', 'MM', 'DD', '/'],
['DD', 'MM', 'YYYY', '.'],
); // '18.02.1997'