parseDate.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  3. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  4. _Object$defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.default = parseDate;
  8. var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/parse-int"));
  9. /**
  10. * Copyright (c) 2015-present, Parse, LLC.
  11. * All rights reserved.
  12. *
  13. * This source code is licensed under the BSD-style license found in the
  14. * LICENSE file in the root directory of this source tree. An additional grant
  15. * of patent rights can be found in the PATENTS file in the same directory.
  16. *
  17. * @flow
  18. */
  19. function parseDate(iso8601
  20. /*: string*/
  21. )
  22. /*: ?Date*/
  23. {
  24. var regexp = new RegExp('^([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2})' + 'T' + '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})' + '(.([0-9]+))?' + 'Z$');
  25. var match = regexp.exec(iso8601);
  26. if (!match) {
  27. return null;
  28. }
  29. var year = (0, _parseInt2.default)(match[1]) || 0;
  30. var month = ((0, _parseInt2.default)(match[2]) || 1) - 1;
  31. var day = (0, _parseInt2.default)(match[3]) || 0;
  32. var hour = (0, _parseInt2.default)(match[4]) || 0;
  33. var minute = (0, _parseInt2.default)(match[5]) || 0;
  34. var second = (0, _parseInt2.default)(match[6]) || 0;
  35. var milli = (0, _parseInt2.default)(match[8]) || 0;
  36. return new Date(Date.UTC(year, month, day, hour, minute, second, milli));
  37. }