cc03f1d002164b52ce4bda088f03ea1d5c8144a6f693ad67c23b656918458d356ba9c9480ebbc31eef04b3bb4df3431fc2f5d54a63eccd98a1ee0139c22f32 750 B

12345678910111213141516171819202122
  1. /* eslint-disable import/prefer-default-export */
  2. /**
  3. * Get normalized Date object for the ISO formatted date strings.
  4. * Natively, the date object parsed from a ISO 8601 string will be offsetted by the timezone difference, which may result in returning a wrong date.
  5. * See: Github issue #3338.
  6. *
  7. * @param {String} dateString String representing the date.
  8. * @returns {Date} The proper Date object.
  9. */
  10. export function getNormalizedDate(dateString) {
  11. let nativeDate = new Date(dateString);
  12. // NaN if dateString is not in ISO format
  13. if (!isNaN(new Date(`${dateString}T00:00`).getDate())) {
  14. // Compensate timezone offset
  15. return new Date(nativeDate.getTime() + (nativeDate.getTimezoneOffset() * 60000));
  16. }
  17. return nativeDate;
  18. }