UNPKG

cpui-components

Version:

71 lines (57 loc) 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateTime = undefined; var _react = require("react"); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var DateTime = exports.DateTime = function (_Component) { _inherits(DateTime, _Component); function DateTime(props) { _classCallCheck(this, DateTime); var _this = _possibleConstructorReturn(this, (DateTime.__proto__ || Object.getPrototypeOf(DateTime)).call(this, props)); _this.render = function () { if (!_this.date) { return null; } var locale = "en-us"; var monthShort = _this.date.toLocaleString(locale, { month: "short" }); var monthFull = _this.date.toLocaleString(locale, { month: "long" }); var timeString = void 0; if (_this.displayTime) { timeString = _react2.default.createElement( "span", null, _react2.default.createElement("br", null), _this.date.toLocaleString(locale, { hour: "numeric", minute: "numeric" }).toLowerCase() ); } return _react2.default.createElement( "span", null, _react2.default.createElement( "abbr", { title: monthFull }, monthShort ), " ", _this.date.getDate(), ", ", _this.date.getFullYear(), " ", timeString ); }; if (_this.props.date) { _this.date = new Date(_this.props.date); _this.displayTime = _this.props.displayTime || false; } return _this; } return DateTime; }(_react.Component); exports.default = DateTime;