diff --git a/index.js b/index.js index 9a6683a9c..b00cda0ac 100644 --- a/index.js +++ b/index.js @@ -172,7 +172,7 @@ var pathToImage = function pathToImage(derivative, domain, policy_id, width) { var w = width || 1000; var r = domain || 'https://costanorte.com.br'; var d = derivative || '2x1'; - var id = policy_id.split("."); + var id = policy_id.split('.'); var string = id.length > 2 ? "".concat(policy_id, ":").concat(id[2]) : "".concat(policy_id); var path = "".concat(r, "/image/policy:").concat(string, "/image.jpg?f=").concat(d, "&w=").concat(w); return path; @@ -190,7 +190,7 @@ var Image = function Image(_ref) { if (content['image-contentId']) { var policy_id = content['image-contentId']; - var derivative = "2x1"; + var derivative = '2x1'; var width = 1000; content['image-path'] = pathToImage(derivative, domain, policy_id, width); img_placeholder = img_placeholder || pathToImage(derivative, domain, policy_id, 10); @@ -236,10 +236,10 @@ var ColumnHeader = function ColumnHeader(_ref) { var domain = _ref.domain, item = _ref.item; if (!item) return null; - var path = ""; - var image = item["column-image"] && item["column-image"]["image-contentId"] && item["column-image"]; - var column_name = item["column-name"]; - var column_description = item["column-desc"]; + var path = ''; + var image = item['column-image'] && item['column-image']['image-contentId'] && item['column-image']; + var column_name = item['column-name']; + var column_description = item['column-desc']; return /*#__PURE__*/React__default.createElement(Block, { align: "row", custom: "column-header", @@ -264,6 +264,7 @@ var ColumnHeader = function ColumnHeader(_ref) { }; ColumnHeader.propTypes = { + domain: PropTypes.string, item: PropTypes.object }; ColumnHeader.defaultProps = { @@ -467,7 +468,7 @@ var Image$1 = function Image(_ref) { if (content['image-contentId']) { var policy_id = content['image-contentId']; - var derivative = "2x1"; + var derivative = '2x1'; var width = 1000; content['image-path'] = pathToImage(derivative, domain, policy_id, width); img_placeholder = img_placeholder || pathToImage(derivative, domain, policy_id, 10); @@ -475,7 +476,7 @@ var Image$1 = function Image(_ref) { if (content['image-legacy']) { content['image-path'] = content['image-legacy']; - content['image-subtitle'] = "Imagem importada do sistema legado / Reprodução"; + content['image-subtitle'] = 'Imagem importada do sistema legado / Reprodução'; img_placeholder = ''; } @@ -486,13 +487,13 @@ var Image$1 = function Image(_ref) { content_path = lazy(content_path, img_placeholder); } - var byline = !content['image-byline'] || content['image-byline'] == "undefined" ? null : content['image-byline']; - var caption_byline = content['image-subtitle'] ? "".concat(content['image-subtitle']).concat(byline ? " (".concat(byline, ")") : "") : "".concat(content['image-subtitle-original']).concat(byline ? " (".concat(byline, ")") : ""); + var byline = !content['image-byline'] || content['image-byline'] == 'undefined' ? null : content['image-byline']; + var caption_byline = content['image-subtitle'] ? "".concat(content['image-subtitle']).concat(byline ? " (".concat(byline, ")") : '') : "".concat(content['image-subtitle-original']).concat(byline ? " (".concat(byline, ")") : ''); return /*#__PURE__*/React__default.createElement(Block, { custom: "image-box ".concat(custom), w: "100p" }, /*#__PURE__*/React__default.createElement("img", { - alt: caption_byline ? caption_byline : "Reprodu\xE7\xE3o", + alt: caption_byline ? '$Legenda da imagem: {caption_byline}' : 'Legenda da imagem: Reprodução', src: content_path }), /*#__PURE__*/React__default.createElement(Block, { custom: "label" @@ -539,46 +540,46 @@ function SvgIcArrowForward(props) { })); } -var ImageGallery = function ImageGallery(_ref) { - var items = _ref.items, +var RenderItem = function RenderItem(_ref) { + var linkurl = _ref.linkurl, + name = _ref.name, + lead = _ref.lead, selected = _ref.selected, on = _ref.on; - if (!items || items.length === 0) return false; - var item_selected = selected ? selected : items[0]; - - var RenderItem = function RenderItem(_ref2) { - var linkurl = _ref2.linkurl, - name = _ref2.name, - lead = _ref2.lead, - selected = _ref2.selected; - var propsGallerySelected = { - custom: "gallery-selected", - w: "100p", - mb: "2" - }; - var propsGalleryItem = { - custom: "gallery-item", - mr: "2", - onClick: function onClick() { - return on({ - linkurl: linkurl, - name: name, - lead: lead - }); - } - }; - var propsGallery = selected ? propsGallerySelected : propsGalleryItem; - return /*#__PURE__*/React__default.createElement(Block, propsGallery, /*#__PURE__*/React__default.createElement("img", { - className: "image-file", - src: linkurl, - alt: "".concat(name) - }), /*#__PURE__*/React__default.createElement(Block, { - custom: "image-name" - }, name), /*#__PURE__*/React__default.createElement(Block, { - custom: "image-lead" - }, lead)); + var propsGallerySelected = { + custom: 'gallery-selected', + w: '100p', + mb: '2' + }; + var propsGalleryItem = { + custom: 'gallery-item', + mr: '2', + onClick: function onClick() { + return on({ + linkurl: linkurl, + name: name, + lead: lead + }); + } }; + var propsGallery = selected ? propsGallerySelected : propsGalleryItem; + return /*#__PURE__*/React__default.createElement(Block, propsGallery, /*#__PURE__*/React__default.createElement("img", { + className: "image-file", + src: linkurl, + alt: "".concat(name) + }), /*#__PURE__*/React__default.createElement(Block, { + custom: "image-name" + }, name), /*#__PURE__*/React__default.createElement(Block, { + custom: "image-lead" + }, lead)); +}; +var ImageGallery = function ImageGallery(_ref2) { + var items = _ref2.items, + selected = _ref2.selected, + on = _ref2.on; + if (!items || items.length === 0) return false; + var item_selected = selected ? selected : items[0]; return /*#__PURE__*/React__default.createElement(Block, { custom: "article-image-gallery", w: "100p" @@ -587,7 +588,8 @@ var ImageGallery = function ImageGallery(_ref) { custom: "image-selected", w: "100p" }, /*#__PURE__*/React__default.createElement(RenderItem, _extends({}, item_selected, { - selected: true + selected: true, + on: on }))), items.length > 1 && /*#__PURE__*/React__default.createElement(Block, { align: "row", custom: "box-list", @@ -601,7 +603,8 @@ var ImageGallery = function ImageGallery(_ref) { w: "100p" }, lodash.map(items, function (item, key) { return /*#__PURE__*/React__default.createElement(RenderItem, _extends({}, item, { - key: key + key: key, + on: on })); })), /*#__PURE__*/React__default.createElement(Block, { align: "row center middle", @@ -610,9 +613,23 @@ var ImageGallery = function ImageGallery(_ref) { }; ImageGallery.propTypes = { - items: PropTypes.array + items: PropTypes.array, + selected: PropTypes.shape({ + lead: PropTypes.string, + linkUrl: PropTypes.string, + name: PropTypes.string + }), + on: PropTypes.func +}; +RenderItem.propTypes = { + linkurl: PropTypes.string, + name: PropTypes.string, + lead: PropTypes.string, + selected: PropTypes.bool, + on: PropTypes.func.isRequired }; ImageGallery.defaultProps = { + selected: false, items: [] }; @@ -1094,34 +1111,35 @@ var parseBody = function parseBody(content) { tag = obj.tag, text = obj.text; - if (tag === "p" || tag === "br") { + if (tag === 'p' || tag === 'br') { tagItems.push({ - "type": "p", - "value": "" + 'type': 'p', + 'value': '' }); - } + } // if(tag === 'span') {} - if (tag === "strong") { + + if (tag === 'strong') { tagItems.push({ - "type": "text", - "value": "".concat(renderChildValue(child), "") + 'type': 'text', + 'value': "".concat(renderChildValue(child), "") }); return true; } - if (tag === "em") { + if (tag === 'em') { tagItems.push({ - "type": "text", - "value": "".concat(renderChildValue(child), "") + 'type': 'text', + 'value': "".concat(renderChildValue(child), "") }); return true; } - if (node === "text") { - if (text && text != "") { + if (node === 'text') { + if (text && text != '') { tagItems.push({ - "type": "text", - "value": text + 'type': 'text', + 'value': text }); } } // render image @@ -1133,8 +1151,8 @@ var parseBody = function parseBody(content) { }); if (childImage) { - var subtitle = childImage && childImage.attr && childImage.attr['alt'] ? childImage.attr['alt'].toString() : ""; - subtitle = subtitle && subtitle !== undefined && subtitle !== "undefined" ? subtitle : "Reprodu\xE7\xE3o"; + var subtitle = childImage && childImage.attr && childImage.attr['alt'] ? childImage.attr['alt'].toString() : ''; + subtitle = subtitle && subtitle !== undefined && subtitle !== 'undefined' ? subtitle : 'Reprodução'; var propsImage = { 'image-contentId': attr['data-onecms-id'].replace('policy:', ''), 'image-subtitle': subtitle, @@ -1185,8 +1203,8 @@ var parseBody = function parseBody(content) { } else { var child_string = renderChildValue(child) || attr.href; tagItems.push({ - "type": "text", - "value": "").concat(child_string, "") + 'type': 'text', + 'value': "").concat(child_string, "") }); return true; } @@ -1195,7 +1213,7 @@ var parseBody = function parseBody(content) { var child_len = child && child.length; if (child && child_len > 0) { - lodash.map(child, function (item, key) { + lodash.map(child, function (item) { switchNode(item); }); } @@ -1210,25 +1228,25 @@ var parseBody = function parseBody(content) { lodash.map(elements, function (item) { return switchNode(item); }); - var p_text = ""; + var p_text = ''; lodash.map(tagItems, function (_ref) { var type = _ref.type, value = _ref.value; switch (type) { - case "p": + case 'p': // insert if exist and clean - if (p_text && p_text !== "") { + if (p_text && p_text !== '') { bodyItems.push({ type: 'Paragraph', value: p_text }); - p_text = ""; + p_text = ''; } break; - case "text": + case 'text': p_text = "".concat(p_text).concat(value); break; @@ -1241,12 +1259,12 @@ var parseBody = function parseBody(content) { } }); - if (p_text && p_text !== "") { + if (p_text && p_text !== '') { bodyItems.push({ type: 'Paragraph', value: p_text }); - p_text = ""; + p_text = ''; } return bodyItems; @@ -1273,8 +1291,21 @@ var TextBody = function TextBody(_ref) { }); }; - var RenderParagraph = function RenderParagraph(_ref2) { + var RenderImage = function RenderImage(_ref2) { var value = _ref2.value; + return /*#__PURE__*/React__default.createElement(Block, { + custom: "article-image-embed", + mb: "3" + }, /*#__PURE__*/React__default.createElement(Image$1, { + custom: "image-article", + content: value, + domain: domain, + lazy: lazy + })); + }; + + var RenderParagraph = function RenderParagraph(_ref3) { + var value = _ref3.value; var has_ads = false; count_p++; @@ -1288,9 +1319,9 @@ var TextBody = function TextBody(_ref) { }), has_ads && /*#__PURE__*/React__default.createElement(RenderAds, null)); }; - return lodash.map(bodyItems, function (_ref3, key) { - var type = _ref3.type, - value = _ref3.value; + return lodash.map(bodyItems, function (_ref4, key) { + var type = _ref4.type, + value = _ref4.value; switch (type) { case 'Paragraph': @@ -1307,16 +1338,10 @@ var TextBody = function TextBody(_ref) { case 'Image': case 'ImageLegacy': - return /*#__PURE__*/React__default.createElement(Block, { - custom: "article-image-embed", + return /*#__PURE__*/React__default.createElement(RenderImage, { key: key, - mb: "3" - }, /*#__PURE__*/React__default.createElement(Image$1, { - custom: "image-article", - content: value, - domain: domain, - lazy: lazy - })); + value: value + }); case 'Instagram': return embeds && embeds.Instagram && /*#__PURE__*/React__default.createElement(embeds.Instagram, { @@ -1350,129 +1375,6 @@ TextBody.defaultProps = { content: {} }; -function buildFormatLongFn(args) { - return function (dirtyOptions) { - var options = dirtyOptions || {}; - var width = options.width ? String(options.width) : args.defaultWidth; - var format = args.formats[width] || args.formats[args.defaultWidth]; - return format; - }; -} - -function buildLocalizeFn(args) { - return function (dirtyIndex, dirtyOptions) { - var options = dirtyOptions || {}; - var context = options.context ? String(options.context) : 'standalone'; - var valuesArray; - - if (context === 'formatting' && args.formattingValues) { - var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; - var width = options.width ? String(options.width) : defaultWidth; - valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; - } else { - var _defaultWidth = args.defaultWidth; - - var _width = options.width ? String(options.width) : args.defaultWidth; - - valuesArray = args.values[_width] || args.values[_defaultWidth]; - } - - var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; - return valuesArray[index]; - }; -} - -function buildMatchPatternFn(args) { - return function (dirtyString, dirtyOptions) { - var string = String(dirtyString); - var options = dirtyOptions || {}; - var matchResult = string.match(args.matchPattern); - - if (!matchResult) { - return null; - } - - var matchedString = matchResult[0]; - var parseResult = string.match(args.parsePattern); - - if (!parseResult) { - return null; - } - - var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; - value = options.valueCallback ? options.valueCallback(value) : value; - return { - value: value, - rest: string.slice(matchedString.length) - }; - }; -} - -function buildMatchFn(args) { - return function (dirtyString, dirtyOptions) { - var string = String(dirtyString); - var options = dirtyOptions || {}; - var width = options.width; - var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; - var matchResult = string.match(matchPattern); - - if (!matchResult) { - return null; - } - - var matchedString = matchResult[0]; - var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; - var value; - - if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { - value = findIndex(parsePatterns, function (pattern) { - return pattern.test(matchedString); - }); - } else { - value = findKey(parsePatterns, function (pattern) { - return pattern.test(matchedString); - }); - } - - value = args.valueCallback ? args.valueCallback(value) : value; - value = options.valueCallback ? options.valueCallback(value) : value; - return { - value: value, - rest: string.slice(matchedString.length) - }; - }; -} - -function findKey(object, predicate) { - for (var key in object) { - if (object.hasOwnProperty(key) && predicate(object[key])) { - return key; - } - } -} - -function findIndex(array, predicate) { - for (var key = 0; key < array.length; key++) { - if (predicate(array[key])) { - return key; - } - } -} - -function toInteger(dirtyNumber) { - if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { - return NaN; - } - - var number = Number(dirtyNumber); - - if (isNaN(number)) { - return number; - } - - return number < 0 ? Math.ceil(number) : Math.floor(number); -} - function requiredArgs(required, args) { if (args.length < required) { throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); @@ -1522,7 +1424,7 @@ function toDate(argument) { } else { if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { // eslint-disable-next-line no-console - console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console + console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console console.warn(new Error().stack); } @@ -1531,52 +1433,255 @@ function toDate(argument) { } } -// See issue: https://github.com/date-fns/date-fns/issues/376 +/** + * @name differenceInMilliseconds + * @category Millisecond Helpers + * @summary Get the number of milliseconds between the given dates. + * + * @description + * Get the number of milliseconds between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of milliseconds + * @throws {TypeError} 2 arguments required + * + * @example + * // How many milliseconds are between + * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? + * var result = differenceInMilliseconds( + * new Date(2014, 6, 2, 12, 30, 21, 700), + * new Date(2014, 6, 2, 12, 30, 20, 600) + * ) + * //=> 1100 + */ -function startOfUTCWeek(dirtyDate, dirtyOptions) { - requiredArgs(1, arguments); - var options = dirtyOptions || {}; - var locale = options.locale; - var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; - var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); - var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN +function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + return dateLeft.getTime() - dateRight.getTime(); +} - if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { - throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); - } +var MILLISECONDS_IN_HOUR = 3600000; +/** + * @name differenceInHours + * @category Hour Helpers + * @summary Get the number of hours between the given dates. + * + * @description + * Get the number of hours between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of hours + * @throws {TypeError} 2 arguments required + * + * @example + * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? + * var result = differenceInHours( + * new Date(2014, 6, 2, 19, 0), + * new Date(2014, 6, 2, 6, 50) + * ) + * //=> 12 + */ - var date = toDate(dirtyDate); - var day = date.getUTCDay(); - var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; - date.setUTCDate(date.getUTCDate() - diff); - date.setUTCHours(0, 0, 0, 0); - return date; +function differenceInHours(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR; + return diff > 0 ? Math.floor(diff) : Math.ceil(diff); } -var formatDistanceLocale = { - lessThanXSeconds: { - one: 'less than a second', - other: 'less than {{count}} seconds' - }, - xSeconds: { - one: '1 second', - other: '{{count}} seconds' - }, - halfAMinute: 'half a minute', - lessThanXMinutes: { - one: 'less than a minute', - other: 'less than {{count}} minutes' - }, - xMinutes: { - one: '1 minute', - other: '{{count}} minutes' - }, - aboutXHours: { - one: 'about 1 hour', - other: 'about {{count}} hours' - }, - xHours: { - one: '1 hour', +/** + * @name compareAsc + * @category Common Helpers + * @summary Compare the two dates and return -1, 0 or 1. + * + * @description + * Compare the two dates and return 1 if the first date is after the second, + * -1 if the first date is before the second or 0 if dates are equal. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the first date to compare + * @param {Date|Number} dateRight - the second date to compare + * @returns {Number} the result of the comparison + * @throws {TypeError} 2 arguments required + * + * @example + * // Compare 11 February 1987 and 10 July 1989: + * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) + * //=> -1 + * + * @example + * // Sort the array of dates: + * var result = [ + * new Date(1995, 6, 2), + * new Date(1987, 1, 11), + * new Date(1989, 6, 10) + * ].sort(compareAsc) + * //=> [ + * // Wed Feb 11 1987 00:00:00, + * // Mon Jul 10 1989 00:00:00, + * // Sun Jul 02 1995 00:00:00 + * // ] + */ + +function compareAsc(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var diff = dateLeft.getTime() - dateRight.getTime(); + + if (diff < 0) { + return -1; + } else if (diff > 0) { + return 1; // Return 0 if diff is 0; return NaN if diff is NaN + } else { + return diff; + } +} + +/** + * @name differenceInCalendarMonths + * @category Month Helpers + * @summary Get the number of calendar months between the given dates. + * + * @description + * Get the number of calendar months between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of calendar months + * @throws {TypeError} 2 arguments required + * + * @example + * // How many calendar months are between 31 January 2014 and 1 September 2014? + * var result = differenceInCalendarMonths( + * new Date(2014, 8, 1), + * new Date(2014, 0, 31) + * ) + * //=> 8 + */ + +function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); + var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); + return yearDiff * 12 + monthDiff; +} + +/** + * @name differenceInMonths + * @category Month Helpers + * @summary Get the number of full months between the given dates. + * + * @description + * Get the number of full months between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of full months + * @throws {TypeError} 2 arguments required + * + * @example + * // How many full months are between 31 January 2014 and 1 September 2014? + * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) + * //=> 7 + */ + +function differenceInMonths(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var sign = compareAsc(dateLeft, dateRight); + var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); + dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full + // If so, result must be decreased by 1 in absolute value + + var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; + var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero + + return result === 0 ? 0 : result; +} + +/** + * @name differenceInSeconds + * @category Second Helpers + * @summary Get the number of seconds between the given dates. + * + * @description + * Get the number of seconds between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of seconds + * @throws {TypeError} 2 arguments required + * + * @example + * // How many seconds are between + * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? + * var result = differenceInSeconds( + * new Date(2014, 6, 2, 12, 30, 20, 0), + * new Date(2014, 6, 2, 12, 30, 7, 999) + * ) + * //=> 12 + */ + +function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; + return diff > 0 ? Math.floor(diff) : Math.ceil(diff); +} + +var formatDistanceLocale = { + lessThanXSeconds: { + one: 'less than a second', + other: 'less than {{count}} seconds' + }, + xSeconds: { + one: '1 second', + other: '{{count}} seconds' + }, + halfAMinute: 'half a minute', + lessThanXMinutes: { + one: 'less than a minute', + other: 'less than {{count}} minutes' + }, + xMinutes: { + one: '1 minute', + other: '{{count}} minutes' + }, + aboutXHours: { + one: 'about 1 hour', + other: 'about {{count}} hours' + }, + xHours: { + one: '1 hour', other: '{{count}} hours' }, xDays: { @@ -1639,6 +1744,48 @@ function formatDistance(token, count, options) { return result; } +function buildFormatLongFn(args) { + return function (dirtyOptions) { + var options = dirtyOptions || {}; + var width = options.width ? String(options.width) : args.defaultWidth; + var format = args.formats[width] || args.formats[args.defaultWidth]; + return format; + }; +} + +var dateFormats = { + full: 'EEEE, MMMM do, y', + long: 'MMMM do, y', + medium: 'MMM d, y', + short: 'MM/dd/yyyy' +}; +var timeFormats = { + full: 'h:mm:ss a zzzz', + long: 'h:mm:ss a z', + medium: 'h:mm:ss a', + short: 'h:mm a' +}; +var dateTimeFormats = { + full: "{{date}} 'at' {{time}}", + long: "{{date}} 'at' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +}; +var formatLong = { + date: buildFormatLongFn({ + formats: dateFormats, + defaultWidth: 'full' + }), + time: buildFormatLongFn({ + formats: timeFormats, + defaultWidth: 'full' + }), + dateTime: buildFormatLongFn({ + formats: dateTimeFormats, + defaultWidth: 'full' + }) +}; + var formatRelativeLocale = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", @@ -1651,6 +1798,29 @@ function formatRelative(token, _date, _baseDate, _options) { return formatRelativeLocale[token]; } +function buildLocalizeFn(args) { + return function (dirtyIndex, dirtyOptions) { + var options = dirtyOptions || {}; + var context = options.context ? String(options.context) : 'standalone'; + var valuesArray; + + if (context === 'formatting' && args.formattingValues) { + var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; + var width = options.width ? String(options.width) : defaultWidth; + valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; + } else { + var _defaultWidth = args.defaultWidth; + + var _width = options.width ? String(options.width) : args.defaultWidth; + + valuesArray = args.values[_width] || args.values[_defaultWidth]; + } + + var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; + return valuesArray[index]; + }; +} + var eraValues = { narrow: ['B', 'A'], abbreviated: ['BC', 'AD'], @@ -1799,15 +1969,92 @@ var localize = { }) }; -var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; -var parseOrdinalNumberPattern = /\d+/i; -var matchEraPatterns = { - narrow: /^(b|a)/i, - abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, - wide: /^(before christ|before common era|anno domini|common era)/i -}; -var parseEraPatterns = { - any: [/^b/i, /^(a|c)/i] +function buildMatchPatternFn(args) { + return function (dirtyString, dirtyOptions) { + var string = String(dirtyString); + var options = dirtyOptions || {}; + var matchResult = string.match(args.matchPattern); + + if (!matchResult) { + return null; + } + + var matchedString = matchResult[0]; + var parseResult = string.match(args.parsePattern); + + if (!parseResult) { + return null; + } + + var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; + value = options.valueCallback ? options.valueCallback(value) : value; + return { + value: value, + rest: string.slice(matchedString.length) + }; + }; +} + +function buildMatchFn(args) { + return function (dirtyString, dirtyOptions) { + var string = String(dirtyString); + var options = dirtyOptions || {}; + var width = options.width; + var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; + var matchResult = string.match(matchPattern); + + if (!matchResult) { + return null; + } + + var matchedString = matchResult[0]; + var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; + var value; + + if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { + value = findIndex(parsePatterns, function (pattern) { + return pattern.test(matchedString); + }); + } else { + value = findKey(parsePatterns, function (pattern) { + return pattern.test(matchedString); + }); + } + + value = args.valueCallback ? args.valueCallback(value) : value; + value = options.valueCallback ? options.valueCallback(value) : value; + return { + value: value, + rest: string.slice(matchedString.length) + }; + }; +} + +function findKey(object, predicate) { + for (var key in object) { + if (object.hasOwnProperty(key) && predicate(object[key])) { + return key; + } + } +} + +function findIndex(array, predicate) { + for (var key = 0; key < array.length; key++) { + if (predicate(array[key])) { + return key; + } + } +} + +var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; +var parseOrdinalNumberPattern = /\d+/i; +var matchEraPatterns = { + narrow: /^(b|a)/i, + abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, + wide: /^(before christ|before common era|anno domini|common era)/i +}; +var parseEraPatterns = { + any: [/^b/i, /^(a|c)/i] }; var matchQuarterPatterns = { narrow: /^[1234]/i, @@ -1895,39 +2142,6 @@ var match = { }) }; -var dateFormats = { - full: 'EEEE, MMMM do, y', - long: 'MMMM do, y', - medium: 'MMM d, y', - short: 'MM/dd/yyyy' -}; -var timeFormats = { - full: 'h:mm:ss a zzzz', - long: 'h:mm:ss a z', - medium: 'h:mm:ss a', - short: 'h:mm a' -}; -var dateTimeFormats = { - full: "{{date}} 'at' {{time}}", - long: "{{date}} 'at' {{time}}", - medium: '{{date}}, {{time}}', - short: '{{date}}, {{time}}' -}; -var formatLong = { - date: buildFormatLongFn({ - formats: dateFormats, - defaultWidth: 'full' - }), - time: buildFormatLongFn({ - formats: timeFormats, - defaultWidth: 'full' - }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats, - defaultWidth: 'full' - }) -}; - /** * @type {Locale} * @category Locales @@ -1953,592 +2167,24 @@ var locale = { } }; -var formatDistanceLocale$1 = { - lessThanXSeconds: { - one: 'menos de um segundo', - other: 'menos de {{count}} segundos' - }, - xSeconds: { - one: '1 segundo', - other: '{{count}} segundos' - }, - halfAMinute: 'meio minuto', - lessThanXMinutes: { - one: 'menos de um minuto', - other: 'menos de {{count}} minutos' - }, - xMinutes: { - one: '1 minuto', - other: '{{count}} minutos' - }, - aboutXHours: { - one: 'aproximadamente 1 hora', - other: 'aproximadamente {{count}} horas' - }, - xHours: { - one: '1 hora', - other: '{{count}} horas' - }, - xDays: { - one: '1 dia', - other: '{{count}} dias' - }, - aboutXWeeks: { - one: 'aproximadamente 1 mês', - // TODO - other: 'aproximadamente {{count}} meses' // TODO - - }, - xWeeks: { - one: '1 mês', - // TODO - other: '{{count}} meses' // TODO - - }, - aboutXMonths: { - one: 'aproximadamente 1 mês', - other: 'aproximadamente {{count}} meses' - }, - xMonths: { - one: '1 mês', - other: '{{count}} meses' - }, - aboutXYears: { - one: 'aproximadamente 1 ano', - other: 'aproximadamente {{count}} anos' - }, - xYears: { - one: '1 ano', - other: '{{count}} anos' - }, - overXYears: { - one: 'mais de 1 ano', - other: 'mais de {{count}} anos' - }, - almostXYears: { - one: 'quase 1 ano', - other: 'quase {{count}} anos' +function assign(target, dirtyObject) { + if (target == null) { + throw new TypeError('assign requires that input parameter not be null or undefined'); } -}; -function formatDistance$1(token, count, options) { - options = options || {}; - var result; - if (typeof formatDistanceLocale$1[token] === 'string') { - result = formatDistanceLocale$1[token]; - } else if (count === 1) { - result = formatDistanceLocale$1[token].one; - } else { - result = formatDistanceLocale$1[token].other.replace('{{count}}', count); - } + dirtyObject = dirtyObject || {}; - if (options.addSuffix) { - if (options.comparison > 0) { - return 'daqui a ' + result; - } else { - return 'há ' + result; + for (var property in dirtyObject) { + if (dirtyObject.hasOwnProperty(property)) { + target[property] = dirtyObject[property]; } } - return result; + return target; } -var dateFormats$1 = { - full: "EEEE, d 'de' MMMM 'de' y", - long: "d 'de' MMMM 'de' y", - medium: "d 'de' MMM 'de' y", - short: 'dd/MM/y' -}; -var timeFormats$1 = { - full: 'HH:mm:ss zzzz', - long: 'HH:mm:ss z', - medium: 'HH:mm:ss', - short: 'HH:mm' -}; -var dateTimeFormats$1 = { - full: "{{date}} 'às' {{time}}", - long: "{{date}} 'às' {{time}}", - medium: '{{date}}, {{time}}', - short: '{{date}}, {{time}}' -}; -var formatLong$1 = { - date: buildFormatLongFn({ - formats: dateFormats$1, - defaultWidth: 'full' - }), - time: buildFormatLongFn({ - formats: timeFormats$1, - defaultWidth: 'full' - }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats$1, - defaultWidth: 'full' - }) -}; - -var formatRelativeLocale$1 = { - lastWeek: "'na última' eeee 'às' p", - yesterday: "'ontem às' p", - today: "'hoje às' p", - tomorrow: "'amanhã às' p", - nextWeek: "eeee 'às' p", - other: 'P' -}; -function formatRelative$1(token, _date, _baseDate, _options) { - return formatRelativeLocale$1[token]; -} - -function ordinalNumber$1(dirtyNumber) { - var number = Number(dirtyNumber); - return number + 'º'; -} - -var eraValues$1 = { - narrow: ['aC', 'dC'], - abbreviated: ['a.C.', 'd.C.'], - wide: ['antes de Cristo', 'depois de Cristo'] -}; -var quarterValues$1 = { - narrow: ['1', '2', '3', '4'], - abbreviated: ['T1', 'T2', 'T3', 'T4'], - wide: ['1º trimestre', '2º trimestre', '3º trimestre', '4º trimestre'] -}; -var monthValues$1 = { - narrow: ['j', 'f', 'm', 'a', 'm', 'j', 'j', 'a', 's', 'o', 'n', 'd'], - abbreviated: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], - wide: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] -}; -var dayValues$1 = { - narrow: ['d', 's', 't', 'q', 'q', 's', 's'], - short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], - abbreviated: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], - wide: ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'] -}; -var dayPeriodValues$1 = { - narrow: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - }, - abbreviated: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - }, - wide: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - } -}; -var formattingDayPeriodValues$1 = { - narrow: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - }, - abbreviated: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - }, - wide: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - } -}; -var localize$1 = { - ordinalNumber: ordinalNumber$1, - era: buildLocalizeFn({ - values: eraValues$1, - defaultWidth: 'wide' - }), - quarter: buildLocalizeFn({ - values: quarterValues$1, - defaultWidth: 'wide', - argumentCallback: function (quarter) { - return Number(quarter) - 1; - } - }), - month: buildLocalizeFn({ - values: monthValues$1, - defaultWidth: 'wide' - }), - day: buildLocalizeFn({ - values: dayValues$1, - defaultWidth: 'wide' - }), - dayPeriod: buildLocalizeFn({ - values: dayPeriodValues$1, - defaultWidth: 'wide', - formattingValues: formattingDayPeriodValues$1, - defaultFormattingWidth: 'wide' - }) -}; - -var matchOrdinalNumberPattern$1 = /^(\d+)(º|ª)?/i; -var parseOrdinalNumberPattern$1 = /\d+/i; -var matchEraPatterns$1 = { - narrow: /^(ac|dc|a|d)/i, - abbreviated: /^(a\.?\s?c\.?|a\.?\s?e\.?\s?c\.?|d\.?\s?c\.?|e\.?\s?c\.?)/i, - wide: /^(antes de cristo|antes da era comum|depois de cristo|era comum)/i -}; -var parseEraPatterns$1 = { - any: [/^ac/i, /^dc/i], - wide: [/^(antes de cristo|antes da era comum)/i, /^(depois de cristo|era comum)/i] -}; -var matchQuarterPatterns$1 = { - narrow: /^[1234]/i, - abbreviated: /^T[1234]/i, - wide: /^[1234](º|ª)? trimestre/i -}; -var parseQuarterPatterns$1 = { - any: [/1/i, /2/i, /3/i, /4/i] -}; -var matchMonthPatterns$1 = { - narrow: /^[jfmasond]/i, - abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i, - wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i -}; -var parseMonthPatterns$1 = { - narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], - any: [/^ja/i, /^f/i, /^mar/i, /^ab/i, /^mai/i, /^jun/i, /^jul/i, /^ag/i, /^s/i, /^o/i, /^n/i, /^d/i] -}; -var matchDayPatterns$1 = { - narrow: /^[dstq]/i, - short: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, - abbreviated: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, - wide: /^(domingo|segunda-?\s?feira|terça-?\s?feira|quarta-?\s?feira|quinta-?\s?feira|sexta-?\s?feira|s[áa]bado)/i -}; -var parseDayPatterns$1 = { - narrow: [/^d/i, /^s/i, /^t/i, /^q/i, /^q/i, /^s/i, /^s/i], - any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[áa]/i] -}; -var matchDayPeriodPatterns$1 = { - narrow: /^(a|p|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i, - any: /^([ap]\.?\s?m\.?|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i -}; -var parseDayPeriodPatterns$1 = { - any: { - am: /^a/i, - pm: /^p/i, - midnight: /^meia/i, - noon: /^meio/i, - morning: /manh[ãa]/i, - afternoon: /tarde/i, - evening: /noite/i, - night: /madrugada/i - } -}; -var match$1 = { - ordinalNumber: buildMatchPatternFn({ - matchPattern: matchOrdinalNumberPattern$1, - parsePattern: parseOrdinalNumberPattern$1, - valueCallback: function (value) { - return parseInt(value, 10); - } - }), - era: buildMatchFn({ - matchPatterns: matchEraPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseEraPatterns$1, - defaultParseWidth: 'any' - }), - quarter: buildMatchFn({ - matchPatterns: matchQuarterPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseQuarterPatterns$1, - defaultParseWidth: 'any', - valueCallback: function (index) { - return index + 1; - } - }), - month: buildMatchFn({ - matchPatterns: matchMonthPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseMonthPatterns$1, - defaultParseWidth: 'any' - }), - day: buildMatchFn({ - matchPatterns: matchDayPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseDayPatterns$1, - defaultParseWidth: 'any' - }), - dayPeriod: buildMatchFn({ - matchPatterns: matchDayPeriodPatterns$1, - defaultMatchWidth: 'any', - parsePatterns: parseDayPeriodPatterns$1, - defaultParseWidth: 'any' - }) -}; - -/** - * @type {Locale} - * @category Locales - * @summary Portuguese locale. - * @language Portuguese - * @iso-639-2 por - * @author Dário Freire [@dfreire]{@link https://github.com/dfreire} - * @author Adrián de la Rosa [@adrm]{@link https://github.com/adrm} - */ - -var locale$1 = { - code: 'pt', - formatDistance: formatDistance$1, - formatLong: formatLong$1, - formatRelative: formatRelative$1, - localize: localize$1, - match: match$1, - options: { - weekStartsOn: 1 - /* Monday */ - , - firstWeekContainsDate: 4 - } -}; - -/** - * @name compareAsc - * @category Common Helpers - * @summary Compare the two dates and return -1, 0 or 1. - * - * @description - * Compare the two dates and return 1 if the first date is after the second, - * -1 if the first date is before the second or 0 if dates are equal. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the first date to compare - * @param {Date|Number} dateRight - the second date to compare - * @returns {Number} the result of the comparison - * @throws {TypeError} 2 arguments required - * - * @example - * // Compare 11 February 1987 and 10 July 1989: - * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) - * //=> -1 - * - * @example - * // Sort the array of dates: - * var result = [ - * new Date(1995, 6, 2), - * new Date(1987, 1, 11), - * new Date(1989, 6, 10) - * ].sort(compareAsc) - * //=> [ - * // Wed Feb 11 1987 00:00:00, - * // Mon Jul 10 1989 00:00:00, - * // Sun Jul 02 1995 00:00:00 - * // ] - */ - -function compareAsc(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var diff = dateLeft.getTime() - dateRight.getTime(); - - if (diff < 0) { - return -1; - } else if (diff > 0) { - return 1; // Return 0 if diff is 0; return NaN if diff is NaN - } else { - return diff; - } -} - -/** - * @name differenceInCalendarMonths - * @category Month Helpers - * @summary Get the number of calendar months between the given dates. - * - * @description - * Get the number of calendar months between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of calendar months - * @throws {TypeError} 2 arguments required - * - * @example - * // How many calendar months are between 31 January 2014 and 1 September 2014? - * var result = differenceInCalendarMonths( - * new Date(2014, 8, 1), - * new Date(2014, 0, 31) - * ) - * //=> 8 - */ - -function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); - var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); - return yearDiff * 12 + monthDiff; -} - -/** - * @name differenceInMonths - * @category Month Helpers - * @summary Get the number of full months between the given dates. - * - * @description - * Get the number of full months between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of full months - * @throws {TypeError} 2 arguments required - * - * @example - * // How many full months are between 31 January 2014 and 1 September 2014? - * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) - * //=> 7 - */ - -function differenceInMonths(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var sign = compareAsc(dateLeft, dateRight); - var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); - dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full - // If so, result must be decreased by 1 in absolute value - - var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; - var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero - - return result === 0 ? 0 : result; -} - -/** - * @name differenceInMilliseconds - * @category Millisecond Helpers - * @summary Get the number of milliseconds between the given dates. - * - * @description - * Get the number of milliseconds between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of milliseconds - * @throws {TypeError} 2 arguments required - * - * @example - * // How many milliseconds are between - * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? - * var result = differenceInMilliseconds( - * new Date(2014, 6, 2, 12, 30, 21, 700), - * new Date(2014, 6, 2, 12, 30, 20, 600) - * ) - * //=> 1100 - */ - -function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - return dateLeft.getTime() - dateRight.getTime(); -} - -/** - * @name differenceInSeconds - * @category Second Helpers - * @summary Get the number of seconds between the given dates. - * - * @description - * Get the number of seconds between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of seconds - * @throws {TypeError} 2 arguments required - * - * @example - * // How many seconds are between - * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? - * var result = differenceInSeconds( - * new Date(2014, 6, 2, 12, 30, 20, 0), - * new Date(2014, 6, 2, 12, 30, 7, 999) - * ) - * //=> 12 - */ - -function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; - return diff > 0 ? Math.floor(diff) : Math.ceil(diff); -} - -function assign(target, dirtyObject) { - if (target == null) { - throw new TypeError('assign requires that input parameter not be null or undefined'); - } - - dirtyObject = dirtyObject || {}; - - for (var property in dirtyObject) { - if (dirtyObject.hasOwnProperty(property)) { - target[property] = dirtyObject[property]; - } - } - - return target; -} - -function cloneObject(dirtyObject) { - return assign({}, dirtyObject); +function cloneObject(dirtyObject) { + return assign({}, dirtyObject); } var MILLISECONDS_IN_MINUTE = 60000; @@ -2681,131 +2327,510 @@ var MINUTES_IN_TWO_MONTHS = 86400; * //=> 'pli ol 1 jaro' */ -function formatDistance$2(dirtyDate, dirtyBaseDate, dirtyOptions) { - requiredArgs(2, arguments); - var options = dirtyOptions || {}; - var locale$1 = options.locale || locale; +function formatDistance$1(dirtyDate, dirtyBaseDate, dirtyOptions) { + requiredArgs(2, arguments); + var options = dirtyOptions || {}; + var locale$1 = options.locale || locale; + + if (!locale$1.formatDistance) { + throw new RangeError('locale must contain formatDistance property'); + } + + var comparison = compareAsc(dirtyDate, dirtyBaseDate); + + if (isNaN(comparison)) { + throw new RangeError('Invalid time value'); + } + + var localizeOptions = cloneObject(options); + localizeOptions.addSuffix = Boolean(options.addSuffix); + localizeOptions.comparison = comparison; + var dateLeft; + var dateRight; + + if (comparison > 0) { + dateLeft = toDate(dirtyBaseDate); + dateRight = toDate(dirtyDate); + } else { + dateLeft = toDate(dirtyDate); + dateRight = toDate(dirtyBaseDate); + } + + var seconds = differenceInSeconds(dateRight, dateLeft); + var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; + var minutes = Math.round((seconds - offsetInSeconds) / 60); + var months; // 0 up to 2 mins + + if (minutes < 2) { + if (options.includeSeconds) { + if (seconds < 5) { + return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); + } else if (seconds < 10) { + return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); + } else if (seconds < 20) { + return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); + } else if (seconds < 40) { + return locale$1.formatDistance('halfAMinute', null, localizeOptions); + } else if (seconds < 60) { + return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); + } else { + return locale$1.formatDistance('xMinutes', 1, localizeOptions); + } + } else { + if (minutes === 0) { + return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); + } else { + return locale$1.formatDistance('xMinutes', minutes, localizeOptions); + } + } // 2 mins up to 0.75 hrs + + } else if (minutes < 45) { + return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs + } else if (minutes < 90) { + return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs + } else if (minutes < MINUTES_IN_DAY) { + var hours = Math.round(minutes / 60); + return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days + } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { + return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days + } else if (minutes < MINUTES_IN_MONTH) { + var days = Math.round(minutes / MINUTES_IN_DAY); + return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months + } else if (minutes < MINUTES_IN_TWO_MONTHS) { + months = Math.round(minutes / MINUTES_IN_MONTH); + return locale$1.formatDistance('aboutXMonths', months, localizeOptions); + } + + months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months + + if (months < 12) { + var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); + return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date + } else { + var monthsSinceStartOfYear = months % 12; + var years = Math.floor(months / 12); // N years up to 1 years 3 months + + if (monthsSinceStartOfYear < 3) { + return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months + } else if (monthsSinceStartOfYear < 9) { + return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months + } else { + return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); + } + } +} - if (!locale$1.formatDistance) { - throw new RangeError('locale must contain formatDistance property'); +function toInteger(dirtyNumber) { + if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { + return NaN; } - var comparison = compareAsc(dirtyDate, dirtyBaseDate); + var number = Number(dirtyNumber); - if (isNaN(comparison)) { - throw new RangeError('Invalid time value'); + if (isNaN(number)) { + return number; } - var localizeOptions = cloneObject(options); - localizeOptions.addSuffix = Boolean(options.addSuffix); - localizeOptions.comparison = comparison; - var dateLeft; - var dateRight; + return number < 0 ? Math.ceil(number) : Math.floor(number); +} - if (comparison > 0) { - dateLeft = toDate(dirtyBaseDate); - dateRight = toDate(dirtyDate); +// See issue: https://github.com/date-fns/date-fns/issues/376 + +function startOfUTCWeek(dirtyDate, dirtyOptions) { + requiredArgs(1, arguments); + var options = dirtyOptions || {}; + var locale = options.locale; + var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; + var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); + var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN + + if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { + throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); + } + + var date = toDate(dirtyDate); + var day = date.getUTCDay(); + var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; + date.setUTCDate(date.getUTCDate() - diff); + date.setUTCHours(0, 0, 0, 0); + return date; +} + +var formatDistanceLocale$1 = { + lessThanXSeconds: { + one: 'menos de um segundo', + other: 'menos de {{count}} segundos' + }, + xSeconds: { + one: '1 segundo', + other: '{{count}} segundos' + }, + halfAMinute: 'meio minuto', + lessThanXMinutes: { + one: 'menos de um minuto', + other: 'menos de {{count}} minutos' + }, + xMinutes: { + one: '1 minuto', + other: '{{count}} minutos' + }, + aboutXHours: { + one: 'aproximadamente 1 hora', + other: 'aproximadamente {{count}} horas' + }, + xHours: { + one: '1 hora', + other: '{{count}} horas' + }, + xDays: { + one: '1 dia', + other: '{{count}} dias' + }, + aboutXWeeks: { + one: 'aproximadamente 1 mês', + // TODO + other: 'aproximadamente {{count}} meses' // TODO + + }, + xWeeks: { + one: '1 mês', + // TODO + other: '{{count}} meses' // TODO + + }, + aboutXMonths: { + one: 'aproximadamente 1 mês', + other: 'aproximadamente {{count}} meses' + }, + xMonths: { + one: '1 mês', + other: '{{count}} meses' + }, + aboutXYears: { + one: 'aproximadamente 1 ano', + other: 'aproximadamente {{count}} anos' + }, + xYears: { + one: '1 ano', + other: '{{count}} anos' + }, + overXYears: { + one: 'mais de 1 ano', + other: 'mais de {{count}} anos' + }, + almostXYears: { + one: 'quase 1 ano', + other: 'quase {{count}} anos' + } +}; +function formatDistance$2(token, count, options) { + options = options || {}; + var result; + + if (typeof formatDistanceLocale$1[token] === 'string') { + result = formatDistanceLocale$1[token]; + } else if (count === 1) { + result = formatDistanceLocale$1[token].one; } else { - dateLeft = toDate(dirtyDate); - dateRight = toDate(dirtyBaseDate); + result = formatDistanceLocale$1[token].other.replace('{{count}}', count); + } + + if (options.addSuffix) { + if (options.comparison > 0) { + return 'daqui a ' + result; + } else { + return 'há ' + result; + } + } + + return result; +} + +var dateFormats$1 = { + full: "EEEE, d 'de' MMMM 'de' y", + long: "d 'de' MMMM 'de' y", + medium: "d 'de' MMM 'de' y", + short: 'dd/MM/y' +}; +var timeFormats$1 = { + full: 'HH:mm:ss zzzz', + long: 'HH:mm:ss z', + medium: 'HH:mm:ss', + short: 'HH:mm' +}; +var dateTimeFormats$1 = { + full: "{{date}} 'às' {{time}}", + long: "{{date}} 'às' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +}; +var formatLong$1 = { + date: buildFormatLongFn({ + formats: dateFormats$1, + defaultWidth: 'full' + }), + time: buildFormatLongFn({ + formats: timeFormats$1, + defaultWidth: 'full' + }), + dateTime: buildFormatLongFn({ + formats: dateTimeFormats$1, + defaultWidth: 'full' + }) +}; + +var formatRelativeLocale$1 = { + lastWeek: "'na última' eeee 'às' p", + yesterday: "'ontem às' p", + today: "'hoje às' p", + tomorrow: "'amanhã às' p", + nextWeek: "eeee 'às' p", + other: 'P' +}; +function formatRelative$1(token, _date, _baseDate, _options) { + return formatRelativeLocale$1[token]; +} + +function ordinalNumber$1(dirtyNumber) { + var number = Number(dirtyNumber); + return number + 'º'; +} + +var eraValues$1 = { + narrow: ['aC', 'dC'], + abbreviated: ['a.C.', 'd.C.'], + wide: ['antes de Cristo', 'depois de Cristo'] +}; +var quarterValues$1 = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['T1', 'T2', 'T3', 'T4'], + wide: ['1º trimestre', '2º trimestre', '3º trimestre', '4º trimestre'] +}; +var monthValues$1 = { + narrow: ['j', 'f', 'm', 'a', 'm', 'j', 'j', 'a', 's', 'o', 'n', 'd'], + abbreviated: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], + wide: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] +}; +var dayValues$1 = { + narrow: ['d', 's', 't', 'q', 'q', 's', 's'], + short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], + abbreviated: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], + wide: ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'] +}; +var dayPeriodValues$1 = { + narrow: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + }, + abbreviated: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + }, + wide: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + } +}; +var formattingDayPeriodValues$1 = { + narrow: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' + }, + abbreviated: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' + }, + wide: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' } +}; +var localize$1 = { + ordinalNumber: ordinalNumber$1, + era: buildLocalizeFn({ + values: eraValues$1, + defaultWidth: 'wide' + }), + quarter: buildLocalizeFn({ + values: quarterValues$1, + defaultWidth: 'wide', + argumentCallback: function (quarter) { + return Number(quarter) - 1; + } + }), + month: buildLocalizeFn({ + values: monthValues$1, + defaultWidth: 'wide' + }), + day: buildLocalizeFn({ + values: dayValues$1, + defaultWidth: 'wide' + }), + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues$1, + defaultWidth: 'wide', + formattingValues: formattingDayPeriodValues$1, + defaultFormattingWidth: 'wide' + }) +}; - var seconds = differenceInSeconds(dateRight, dateLeft); - var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; - var minutes = Math.round((seconds - offsetInSeconds) / 60); - var months; // 0 up to 2 mins - - if (minutes < 2) { - if (options.includeSeconds) { - if (seconds < 5) { - return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); - } else if (seconds < 10) { - return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); - } else if (seconds < 20) { - return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); - } else if (seconds < 40) { - return locale$1.formatDistance('halfAMinute', null, localizeOptions); - } else if (seconds < 60) { - return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); - } else { - return locale$1.formatDistance('xMinutes', 1, localizeOptions); - } - } else { - if (minutes === 0) { - return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); - } else { - return locale$1.formatDistance('xMinutes', minutes, localizeOptions); - } - } // 2 mins up to 0.75 hrs - - } else if (minutes < 45) { - return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs - } else if (minutes < 90) { - return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs - } else if (minutes < MINUTES_IN_DAY) { - var hours = Math.round(minutes / 60); - return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days - } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { - return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days - } else if (minutes < MINUTES_IN_MONTH) { - var days = Math.round(minutes / MINUTES_IN_DAY); - return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months - } else if (minutes < MINUTES_IN_TWO_MONTHS) { - months = Math.round(minutes / MINUTES_IN_MONTH); - return locale$1.formatDistance('aboutXMonths', months, localizeOptions); +var matchOrdinalNumberPattern$1 = /^(\d+)(º|ª)?/i; +var parseOrdinalNumberPattern$1 = /\d+/i; +var matchEraPatterns$1 = { + narrow: /^(ac|dc|a|d)/i, + abbreviated: /^(a\.?\s?c\.?|a\.?\s?e\.?\s?c\.?|d\.?\s?c\.?|e\.?\s?c\.?)/i, + wide: /^(antes de cristo|antes da era comum|depois de cristo|era comum)/i +}; +var parseEraPatterns$1 = { + any: [/^ac/i, /^dc/i], + wide: [/^(antes de cristo|antes da era comum)/i, /^(depois de cristo|era comum)/i] +}; +var matchQuarterPatterns$1 = { + narrow: /^[1234]/i, + abbreviated: /^T[1234]/i, + wide: /^[1234](º|ª)? trimestre/i +}; +var parseQuarterPatterns$1 = { + any: [/1/i, /2/i, /3/i, /4/i] +}; +var matchMonthPatterns$1 = { + narrow: /^[jfmasond]/i, + abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i, + wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i +}; +var parseMonthPatterns$1 = { + narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], + any: [/^ja/i, /^f/i, /^mar/i, /^ab/i, /^mai/i, /^jun/i, /^jul/i, /^ag/i, /^s/i, /^o/i, /^n/i, /^d/i] +}; +var matchDayPatterns$1 = { + narrow: /^[dstq]/i, + short: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, + abbreviated: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, + wide: /^(domingo|segunda-?\s?feira|terça-?\s?feira|quarta-?\s?feira|quinta-?\s?feira|sexta-?\s?feira|s[áa]bado)/i +}; +var parseDayPatterns$1 = { + narrow: [/^d/i, /^s/i, /^t/i, /^q/i, /^q/i, /^s/i, /^s/i], + any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[áa]/i] +}; +var matchDayPeriodPatterns$1 = { + narrow: /^(a|p|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i, + any: /^([ap]\.?\s?m\.?|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i +}; +var parseDayPeriodPatterns$1 = { + any: { + am: /^a/i, + pm: /^p/i, + midnight: /^meia/i, + noon: /^meio/i, + morning: /manh[ãa]/i, + afternoon: /tarde/i, + evening: /noite/i, + night: /madrugada/i } - - months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months - - if (months < 12) { - var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); - return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date - } else { - var monthsSinceStartOfYear = months % 12; - var years = Math.floor(months / 12); // N years up to 1 years 3 months - - if (monthsSinceStartOfYear < 3) { - return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months - } else if (monthsSinceStartOfYear < 9) { - return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months - } else { - return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); +}; +var match$1 = { + ordinalNumber: buildMatchPatternFn({ + matchPattern: matchOrdinalNumberPattern$1, + parsePattern: parseOrdinalNumberPattern$1, + valueCallback: function (value) { + return parseInt(value, 10); } - } -} + }), + era: buildMatchFn({ + matchPatterns: matchEraPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseEraPatterns$1, + defaultParseWidth: 'any' + }), + quarter: buildMatchFn({ + matchPatterns: matchQuarterPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseQuarterPatterns$1, + defaultParseWidth: 'any', + valueCallback: function (index) { + return index + 1; + } + }), + month: buildMatchFn({ + matchPatterns: matchMonthPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseMonthPatterns$1, + defaultParseWidth: 'any' + }), + day: buildMatchFn({ + matchPatterns: matchDayPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseDayPatterns$1, + defaultParseWidth: 'any' + }), + dayPeriod: buildMatchFn({ + matchPatterns: matchDayPeriodPatterns$1, + defaultMatchWidth: 'any', + parsePatterns: parseDayPeriodPatterns$1, + defaultParseWidth: 'any' + }) +}; -var MILLISECONDS_IN_HOUR = 3600000; /** - * @name differenceInHours - * @category Hour Helpers - * @summary Get the number of hours between the given dates. - * - * @description - * Get the number of hours between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of hours - * @throws {TypeError} 2 arguments required - * - * @example - * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? - * var result = differenceInHours( - * new Date(2014, 6, 2, 19, 0), - * new Date(2014, 6, 2, 6, 50) - * ) - * //=> 12 + * @type {Locale} + * @category Locales + * @summary Portuguese locale. + * @language Portuguese + * @iso-639-2 por + * @author Dário Freire [@dfreire]{@link https://github.com/dfreire} + * @author Adrián de la Rosa [@adrm]{@link https://github.com/adrm} */ -function differenceInHours(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR; - return diff > 0 ? Math.floor(diff) : Math.ceil(diff); -} +var locale$1 = { + code: 'pt', + formatDistance: formatDistance$2, + formatLong: formatLong$1, + formatRelative: formatRelative$1, + localize: localize$1, + match: match$1, + options: { + weekStartsOn: 1 + /* Monday */ + , + firstWeekContainsDate: 4 + } +}; /** * @name isValid @@ -4550,7 +4575,7 @@ function cleanEscapedString(input) { var datePtBrFull = function datePtBrFull(date) { if (!date) return false; - var d = date.replace("T", " "); + var d = date.replace('T', ' '); var _y = d.split('-'); @@ -4561,12 +4586,12 @@ var datePtBrFull = function datePtBrFull(date) { var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]); if (!(_date instanceof Date)) return false; - return "".concat(format(_date, "dd/MM/yyyy"), " \xE0s ").concat(format(_date, "HH:mm")); + return "".concat(format(_date, 'dd/MM/yyyy'), " \xE0s ").concat(format(_date, 'HH:mm')); }; var dateDistance = function dateDistance(date, limit) { if (!date) return false; - var d = date.replace("T", " "); + var d = date.replace('T', ' '); var _y = d.split('-'); @@ -4578,16 +4603,16 @@ var dateDistance = function dateDistance(date, limit) { var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime(); - var distanteInWords = formatDistance$2(_now, _date, { + var distanteInWords = formatDistance$1(_now, _date, { locale: locale$1 }); var diffHours = differenceInHours(_now, _date, { locale: locale$1 }); if (diffHours > limit) return datePtBrFull(date); - var replaces = [["aproximadamente ", ""]]; + var replaces = [['aproximadamente ', '']]; var date_string = distanteInWords; - lodash.map(replaces, function (r, k) { + lodash.map(replaces, function (r) { date_string = date_string.replace(r[0], r[1]); }); return "H\xE1 ".concat(date_string); diff --git a/package.json b/package.json index d419851bc..128643181 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xprog-ds", - "version": "1.3.2", + "version": "1.3.3", "description": "XPROG Design System", "main": "/", "author": "XPROG", diff --git a/teasers.js b/teasers.js index 41b1385eb..91e6a2078 100644 --- a/teasers.js +++ b/teasers.js @@ -2,8 +2,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } -var React = _interopDefault(require('react')); var PropTypes = _interopDefault(require('prop-types')); +var React = _interopDefault(require('react')); var classnames = _interopDefault(require('classnames')); var lodash = require('lodash'); @@ -90,7 +90,7 @@ var pathToImage = function pathToImage(derivative, domain, policy_id, width) { var w = width || 1000; var r = domain || 'https://costanorte.com.br'; var d = derivative || '2x1'; - var id = policy_id.split("."); + var id = policy_id.split('.'); var string = id.length > 2 ? "".concat(policy_id, ":").concat(id[2]) : "".concat(policy_id); var path = "".concat(r, "/image/policy:").concat(string, "/image.jpg?f=").concat(d, "&w=").concat(w); return path; @@ -108,7 +108,7 @@ var Image = function Image(_ref) { if (content['image-contentId']) { var policy_id = content['image-contentId']; - var derivative = "2x1"; + var derivative = '2x1'; var width = 1000; content['image-path'] = pathToImage(derivative, domain, policy_id, width); img_placeholder = img_placeholder || pathToImage(derivative, domain, policy_id, 10); @@ -274,129 +274,6 @@ Subject.propTypes = { }; -function buildFormatLongFn(args) { - return function (dirtyOptions) { - var options = dirtyOptions || {}; - var width = options.width ? String(options.width) : args.defaultWidth; - var format = args.formats[width] || args.formats[args.defaultWidth]; - return format; - }; -} - -function buildLocalizeFn(args) { - return function (dirtyIndex, dirtyOptions) { - var options = dirtyOptions || {}; - var context = options.context ? String(options.context) : 'standalone'; - var valuesArray; - - if (context === 'formatting' && args.formattingValues) { - var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; - var width = options.width ? String(options.width) : defaultWidth; - valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; - } else { - var _defaultWidth = args.defaultWidth; - - var _width = options.width ? String(options.width) : args.defaultWidth; - - valuesArray = args.values[_width] || args.values[_defaultWidth]; - } - - var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; - return valuesArray[index]; - }; -} - -function buildMatchPatternFn(args) { - return function (dirtyString, dirtyOptions) { - var string = String(dirtyString); - var options = dirtyOptions || {}; - var matchResult = string.match(args.matchPattern); - - if (!matchResult) { - return null; - } - - var matchedString = matchResult[0]; - var parseResult = string.match(args.parsePattern); - - if (!parseResult) { - return null; - } - - var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; - value = options.valueCallback ? options.valueCallback(value) : value; - return { - value: value, - rest: string.slice(matchedString.length) - }; - }; -} - -function buildMatchFn(args) { - return function (dirtyString, dirtyOptions) { - var string = String(dirtyString); - var options = dirtyOptions || {}; - var width = options.width; - var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; - var matchResult = string.match(matchPattern); - - if (!matchResult) { - return null; - } - - var matchedString = matchResult[0]; - var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; - var value; - - if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { - value = findIndex(parsePatterns, function (pattern) { - return pattern.test(matchedString); - }); - } else { - value = findKey(parsePatterns, function (pattern) { - return pattern.test(matchedString); - }); - } - - value = args.valueCallback ? args.valueCallback(value) : value; - value = options.valueCallback ? options.valueCallback(value) : value; - return { - value: value, - rest: string.slice(matchedString.length) - }; - }; -} - -function findKey(object, predicate) { - for (var key in object) { - if (object.hasOwnProperty(key) && predicate(object[key])) { - return key; - } - } -} - -function findIndex(array, predicate) { - for (var key = 0; key < array.length; key++) { - if (predicate(array[key])) { - return key; - } - } -} - -function toInteger(dirtyNumber) { - if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { - return NaN; - } - - var number = Number(dirtyNumber); - - if (isNaN(number)) { - return number; - } - - return number < 0 ? Math.ceil(number) : Math.floor(number); -} - function requiredArgs(required, args) { if (args.length < required) { throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); @@ -446,7 +323,7 @@ function toDate(argument) { } else { if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { // eslint-disable-next-line no-console - console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console + console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console console.warn(new Error().stack); } @@ -455,80 +332,283 @@ function toDate(argument) { } } -// See issue: https://github.com/date-fns/date-fns/issues/376 +/** + * @name differenceInMilliseconds + * @category Millisecond Helpers + * @summary Get the number of milliseconds between the given dates. + * + * @description + * Get the number of milliseconds between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of milliseconds + * @throws {TypeError} 2 arguments required + * + * @example + * // How many milliseconds are between + * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? + * var result = differenceInMilliseconds( + * new Date(2014, 6, 2, 12, 30, 21, 700), + * new Date(2014, 6, 2, 12, 30, 20, 600) + * ) + * //=> 1100 + */ -function startOfUTCWeek(dirtyDate, dirtyOptions) { - requiredArgs(1, arguments); - var options = dirtyOptions || {}; - var locale = options.locale; - var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; - var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); - var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN +function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + return dateLeft.getTime() - dateRight.getTime(); +} - if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { - throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); - } +var MILLISECONDS_IN_HOUR = 3600000; +/** + * @name differenceInHours + * @category Hour Helpers + * @summary Get the number of hours between the given dates. + * + * @description + * Get the number of hours between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of hours + * @throws {TypeError} 2 arguments required + * + * @example + * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? + * var result = differenceInHours( + * new Date(2014, 6, 2, 19, 0), + * new Date(2014, 6, 2, 6, 50) + * ) + * //=> 12 + */ - var date = toDate(dirtyDate); - var day = date.getUTCDay(); - var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; - date.setUTCDate(date.getUTCDate() - diff); - date.setUTCHours(0, 0, 0, 0); - return date; +function differenceInHours(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR; + return diff > 0 ? Math.floor(diff) : Math.ceil(diff); } -var formatDistanceLocale = { - lessThanXSeconds: { - one: 'less than a second', - other: 'less than {{count}} seconds' - }, - xSeconds: { - one: '1 second', - other: '{{count}} seconds' - }, - halfAMinute: 'half a minute', - lessThanXMinutes: { - one: 'less than a minute', - other: 'less than {{count}} minutes' - }, - xMinutes: { - one: '1 minute', - other: '{{count}} minutes' - }, - aboutXHours: { - one: 'about 1 hour', - other: 'about {{count}} hours' - }, - xHours: { - one: '1 hour', - other: '{{count}} hours' - }, - xDays: { - one: '1 day', - other: '{{count}} days' - }, - aboutXWeeks: { - one: 'about 1 week', - other: 'about {{count}} weeks' - }, - xWeeks: { - one: '1 week', - other: '{{count}} weeks' - }, - aboutXMonths: { - one: 'about 1 month', - other: 'about {{count}} months' - }, - xMonths: { - one: '1 month', - other: '{{count}} months' - }, - aboutXYears: { - one: 'about 1 year', - other: 'about {{count}} years' - }, - xYears: { - one: '1 year', +/** + * @name compareAsc + * @category Common Helpers + * @summary Compare the two dates and return -1, 0 or 1. + * + * @description + * Compare the two dates and return 1 if the first date is after the second, + * -1 if the first date is before the second or 0 if dates are equal. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the first date to compare + * @param {Date|Number} dateRight - the second date to compare + * @returns {Number} the result of the comparison + * @throws {TypeError} 2 arguments required + * + * @example + * // Compare 11 February 1987 and 10 July 1989: + * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) + * //=> -1 + * + * @example + * // Sort the array of dates: + * var result = [ + * new Date(1995, 6, 2), + * new Date(1987, 1, 11), + * new Date(1989, 6, 10) + * ].sort(compareAsc) + * //=> [ + * // Wed Feb 11 1987 00:00:00, + * // Mon Jul 10 1989 00:00:00, + * // Sun Jul 02 1995 00:00:00 + * // ] + */ + +function compareAsc(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var diff = dateLeft.getTime() - dateRight.getTime(); + + if (diff < 0) { + return -1; + } else if (diff > 0) { + return 1; // Return 0 if diff is 0; return NaN if diff is NaN + } else { + return diff; + } +} + +/** + * @name differenceInCalendarMonths + * @category Month Helpers + * @summary Get the number of calendar months between the given dates. + * + * @description + * Get the number of calendar months between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of calendar months + * @throws {TypeError} 2 arguments required + * + * @example + * // How many calendar months are between 31 January 2014 and 1 September 2014? + * var result = differenceInCalendarMonths( + * new Date(2014, 8, 1), + * new Date(2014, 0, 31) + * ) + * //=> 8 + */ + +function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); + var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); + return yearDiff * 12 + monthDiff; +} + +/** + * @name differenceInMonths + * @category Month Helpers + * @summary Get the number of full months between the given dates. + * + * @description + * Get the number of full months between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of full months + * @throws {TypeError} 2 arguments required + * + * @example + * // How many full months are between 31 January 2014 and 1 September 2014? + * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) + * //=> 7 + */ + +function differenceInMonths(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var sign = compareAsc(dateLeft, dateRight); + var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); + dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full + // If so, result must be decreased by 1 in absolute value + + var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; + var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero + + return result === 0 ? 0 : result; +} + +/** + * @name differenceInSeconds + * @category Second Helpers + * @summary Get the number of seconds between the given dates. + * + * @description + * Get the number of seconds between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of seconds + * @throws {TypeError} 2 arguments required + * + * @example + * // How many seconds are between + * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? + * var result = differenceInSeconds( + * new Date(2014, 6, 2, 12, 30, 20, 0), + * new Date(2014, 6, 2, 12, 30, 7, 999) + * ) + * //=> 12 + */ + +function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; + return diff > 0 ? Math.floor(diff) : Math.ceil(diff); +} + +var formatDistanceLocale = { + lessThanXSeconds: { + one: 'less than a second', + other: 'less than {{count}} seconds' + }, + xSeconds: { + one: '1 second', + other: '{{count}} seconds' + }, + halfAMinute: 'half a minute', + lessThanXMinutes: { + one: 'less than a minute', + other: 'less than {{count}} minutes' + }, + xMinutes: { + one: '1 minute', + other: '{{count}} minutes' + }, + aboutXHours: { + one: 'about 1 hour', + other: 'about {{count}} hours' + }, + xHours: { + one: '1 hour', + other: '{{count}} hours' + }, + xDays: { + one: '1 day', + other: '{{count}} days' + }, + aboutXWeeks: { + one: 'about 1 week', + other: 'about {{count}} weeks' + }, + xWeeks: { + one: '1 week', + other: '{{count}} weeks' + }, + aboutXMonths: { + one: 'about 1 month', + other: 'about {{count}} months' + }, + xMonths: { + one: '1 month', + other: '{{count}} months' + }, + aboutXYears: { + one: 'about 1 year', + other: 'about {{count}} years' + }, + xYears: { + one: '1 year', other: '{{count}} years' }, overXYears: { @@ -563,6 +643,48 @@ function formatDistance(token, count, options) { return result; } +function buildFormatLongFn(args) { + return function (dirtyOptions) { + var options = dirtyOptions || {}; + var width = options.width ? String(options.width) : args.defaultWidth; + var format = args.formats[width] || args.formats[args.defaultWidth]; + return format; + }; +} + +var dateFormats = { + full: 'EEEE, MMMM do, y', + long: 'MMMM do, y', + medium: 'MMM d, y', + short: 'MM/dd/yyyy' +}; +var timeFormats = { + full: 'h:mm:ss a zzzz', + long: 'h:mm:ss a z', + medium: 'h:mm:ss a', + short: 'h:mm a' +}; +var dateTimeFormats = { + full: "{{date}} 'at' {{time}}", + long: "{{date}} 'at' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +}; +var formatLong = { + date: buildFormatLongFn({ + formats: dateFormats, + defaultWidth: 'full' + }), + time: buildFormatLongFn({ + formats: timeFormats, + defaultWidth: 'full' + }), + dateTime: buildFormatLongFn({ + formats: dateTimeFormats, + defaultWidth: 'full' + }) +}; + var formatRelativeLocale = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", @@ -575,10 +697,33 @@ function formatRelative(token, _date, _baseDate, _options) { return formatRelativeLocale[token]; } -var eraValues = { - narrow: ['B', 'A'], - abbreviated: ['BC', 'AD'], - wide: ['Before Christ', 'Anno Domini'] +function buildLocalizeFn(args) { + return function (dirtyIndex, dirtyOptions) { + var options = dirtyOptions || {}; + var context = options.context ? String(options.context) : 'standalone'; + var valuesArray; + + if (context === 'formatting' && args.formattingValues) { + var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; + var width = options.width ? String(options.width) : defaultWidth; + valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; + } else { + var _defaultWidth = args.defaultWidth; + + var _width = options.width ? String(options.width) : args.defaultWidth; + + valuesArray = args.values[_width] || args.values[_defaultWidth]; + } + + var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; + return valuesArray[index]; + }; +} + +var eraValues = { + narrow: ['B', 'A'], + abbreviated: ['BC', 'AD'], + wide: ['Before Christ', 'Anno Domini'] }; var quarterValues = { narrow: ['1', '2', '3', '4'], @@ -723,6 +868,83 @@ var localize = { }) }; +function buildMatchPatternFn(args) { + return function (dirtyString, dirtyOptions) { + var string = String(dirtyString); + var options = dirtyOptions || {}; + var matchResult = string.match(args.matchPattern); + + if (!matchResult) { + return null; + } + + var matchedString = matchResult[0]; + var parseResult = string.match(args.parsePattern); + + if (!parseResult) { + return null; + } + + var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; + value = options.valueCallback ? options.valueCallback(value) : value; + return { + value: value, + rest: string.slice(matchedString.length) + }; + }; +} + +function buildMatchFn(args) { + return function (dirtyString, dirtyOptions) { + var string = String(dirtyString); + var options = dirtyOptions || {}; + var width = options.width; + var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; + var matchResult = string.match(matchPattern); + + if (!matchResult) { + return null; + } + + var matchedString = matchResult[0]; + var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; + var value; + + if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { + value = findIndex(parsePatterns, function (pattern) { + return pattern.test(matchedString); + }); + } else { + value = findKey(parsePatterns, function (pattern) { + return pattern.test(matchedString); + }); + } + + value = args.valueCallback ? args.valueCallback(value) : value; + value = options.valueCallback ? options.valueCallback(value) : value; + return { + value: value, + rest: string.slice(matchedString.length) + }; + }; +} + +function findKey(object, predicate) { + for (var key in object) { + if (object.hasOwnProperty(key) && predicate(object[key])) { + return key; + } + } +} + +function findIndex(array, predicate) { + for (var key = 0; key < array.length; key++) { + if (predicate(array[key])) { + return key; + } + } +} + var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; var parseOrdinalNumberPattern = /\d+/i; var matchEraPatterns = { @@ -819,39 +1041,6 @@ var match = { }) }; -var dateFormats = { - full: 'EEEE, MMMM do, y', - long: 'MMMM do, y', - medium: 'MMM d, y', - short: 'MM/dd/yyyy' -}; -var timeFormats = { - full: 'h:mm:ss a zzzz', - long: 'h:mm:ss a z', - medium: 'h:mm:ss a', - short: 'h:mm a' -}; -var dateTimeFormats = { - full: "{{date}} 'at' {{time}}", - long: "{{date}} 'at' {{time}}", - medium: '{{date}}, {{time}}', - short: '{{date}}, {{time}}' -}; -var formatLong = { - date: buildFormatLongFn({ - formats: dateFormats, - defaultWidth: 'full' - }), - time: buildFormatLongFn({ - formats: timeFormats, - defaultWidth: 'full' - }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats, - defaultWidth: 'full' - }) -}; - /** * @type {Locale} * @category Locales @@ -877,588 +1066,20 @@ var locale = { } }; -var formatDistanceLocale$1 = { - lessThanXSeconds: { - one: 'menos de um segundo', - other: 'menos de {{count}} segundos' - }, - xSeconds: { - one: '1 segundo', - other: '{{count}} segundos' - }, - halfAMinute: 'meio minuto', - lessThanXMinutes: { - one: 'menos de um minuto', - other: 'menos de {{count}} minutos' - }, - xMinutes: { - one: '1 minuto', - other: '{{count}} minutos' - }, - aboutXHours: { - one: 'aproximadamente 1 hora', - other: 'aproximadamente {{count}} horas' - }, - xHours: { - one: '1 hora', - other: '{{count}} horas' - }, - xDays: { - one: '1 dia', - other: '{{count}} dias' - }, - aboutXWeeks: { - one: 'aproximadamente 1 mês', - // TODO - other: 'aproximadamente {{count}} meses' // TODO - - }, - xWeeks: { - one: '1 mês', - // TODO - other: '{{count}} meses' // TODO - - }, - aboutXMonths: { - one: 'aproximadamente 1 mês', - other: 'aproximadamente {{count}} meses' - }, - xMonths: { - one: '1 mês', - other: '{{count}} meses' - }, - aboutXYears: { - one: 'aproximadamente 1 ano', - other: 'aproximadamente {{count}} anos' - }, - xYears: { - one: '1 ano', - other: '{{count}} anos' - }, - overXYears: { - one: 'mais de 1 ano', - other: 'mais de {{count}} anos' - }, - almostXYears: { - one: 'quase 1 ano', - other: 'quase {{count}} anos' +function assign(target, dirtyObject) { + if (target == null) { + throw new TypeError('assign requires that input parameter not be null or undefined'); } -}; -function formatDistance$1(token, count, options) { - options = options || {}; - var result; - if (typeof formatDistanceLocale$1[token] === 'string') { - result = formatDistanceLocale$1[token]; - } else if (count === 1) { - result = formatDistanceLocale$1[token].one; - } else { - result = formatDistanceLocale$1[token].other.replace('{{count}}', count); - } + dirtyObject = dirtyObject || {}; - if (options.addSuffix) { - if (options.comparison > 0) { - return 'daqui a ' + result; - } else { - return 'há ' + result; + for (var property in dirtyObject) { + if (dirtyObject.hasOwnProperty(property)) { + target[property] = dirtyObject[property]; } } - return result; -} - -var dateFormats$1 = { - full: "EEEE, d 'de' MMMM 'de' y", - long: "d 'de' MMMM 'de' y", - medium: "d 'de' MMM 'de' y", - short: 'dd/MM/y' -}; -var timeFormats$1 = { - full: 'HH:mm:ss zzzz', - long: 'HH:mm:ss z', - medium: 'HH:mm:ss', - short: 'HH:mm' -}; -var dateTimeFormats$1 = { - full: "{{date}} 'às' {{time}}", - long: "{{date}} 'às' {{time}}", - medium: '{{date}}, {{time}}', - short: '{{date}}, {{time}}' -}; -var formatLong$1 = { - date: buildFormatLongFn({ - formats: dateFormats$1, - defaultWidth: 'full' - }), - time: buildFormatLongFn({ - formats: timeFormats$1, - defaultWidth: 'full' - }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats$1, - defaultWidth: 'full' - }) -}; - -var formatRelativeLocale$1 = { - lastWeek: "'na última' eeee 'às' p", - yesterday: "'ontem às' p", - today: "'hoje às' p", - tomorrow: "'amanhã às' p", - nextWeek: "eeee 'às' p", - other: 'P' -}; -function formatRelative$1(token, _date, _baseDate, _options) { - return formatRelativeLocale$1[token]; -} - -function ordinalNumber$1(dirtyNumber) { - var number = Number(dirtyNumber); - return number + 'º'; -} - -var eraValues$1 = { - narrow: ['aC', 'dC'], - abbreviated: ['a.C.', 'd.C.'], - wide: ['antes de Cristo', 'depois de Cristo'] -}; -var quarterValues$1 = { - narrow: ['1', '2', '3', '4'], - abbreviated: ['T1', 'T2', 'T3', 'T4'], - wide: ['1º trimestre', '2º trimestre', '3º trimestre', '4º trimestre'] -}; -var monthValues$1 = { - narrow: ['j', 'f', 'm', 'a', 'm', 'j', 'j', 'a', 's', 'o', 'n', 'd'], - abbreviated: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], - wide: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] -}; -var dayValues$1 = { - narrow: ['d', 's', 't', 'q', 'q', 's', 's'], - short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], - abbreviated: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], - wide: ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'] -}; -var dayPeriodValues$1 = { - narrow: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - }, - abbreviated: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - }, - wide: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - } -}; -var formattingDayPeriodValues$1 = { - narrow: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - }, - abbreviated: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - }, - wide: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - } -}; -var localize$1 = { - ordinalNumber: ordinalNumber$1, - era: buildLocalizeFn({ - values: eraValues$1, - defaultWidth: 'wide' - }), - quarter: buildLocalizeFn({ - values: quarterValues$1, - defaultWidth: 'wide', - argumentCallback: function (quarter) { - return Number(quarter) - 1; - } - }), - month: buildLocalizeFn({ - values: monthValues$1, - defaultWidth: 'wide' - }), - day: buildLocalizeFn({ - values: dayValues$1, - defaultWidth: 'wide' - }), - dayPeriod: buildLocalizeFn({ - values: dayPeriodValues$1, - defaultWidth: 'wide', - formattingValues: formattingDayPeriodValues$1, - defaultFormattingWidth: 'wide' - }) -}; - -var matchOrdinalNumberPattern$1 = /^(\d+)(º|ª)?/i; -var parseOrdinalNumberPattern$1 = /\d+/i; -var matchEraPatterns$1 = { - narrow: /^(ac|dc|a|d)/i, - abbreviated: /^(a\.?\s?c\.?|a\.?\s?e\.?\s?c\.?|d\.?\s?c\.?|e\.?\s?c\.?)/i, - wide: /^(antes de cristo|antes da era comum|depois de cristo|era comum)/i -}; -var parseEraPatterns$1 = { - any: [/^ac/i, /^dc/i], - wide: [/^(antes de cristo|antes da era comum)/i, /^(depois de cristo|era comum)/i] -}; -var matchQuarterPatterns$1 = { - narrow: /^[1234]/i, - abbreviated: /^T[1234]/i, - wide: /^[1234](º|ª)? trimestre/i -}; -var parseQuarterPatterns$1 = { - any: [/1/i, /2/i, /3/i, /4/i] -}; -var matchMonthPatterns$1 = { - narrow: /^[jfmasond]/i, - abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i, - wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i -}; -var parseMonthPatterns$1 = { - narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], - any: [/^ja/i, /^f/i, /^mar/i, /^ab/i, /^mai/i, /^jun/i, /^jul/i, /^ag/i, /^s/i, /^o/i, /^n/i, /^d/i] -}; -var matchDayPatterns$1 = { - narrow: /^[dstq]/i, - short: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, - abbreviated: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, - wide: /^(domingo|segunda-?\s?feira|terça-?\s?feira|quarta-?\s?feira|quinta-?\s?feira|sexta-?\s?feira|s[áa]bado)/i -}; -var parseDayPatterns$1 = { - narrow: [/^d/i, /^s/i, /^t/i, /^q/i, /^q/i, /^s/i, /^s/i], - any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[áa]/i] -}; -var matchDayPeriodPatterns$1 = { - narrow: /^(a|p|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i, - any: /^([ap]\.?\s?m\.?|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i -}; -var parseDayPeriodPatterns$1 = { - any: { - am: /^a/i, - pm: /^p/i, - midnight: /^meia/i, - noon: /^meio/i, - morning: /manh[ãa]/i, - afternoon: /tarde/i, - evening: /noite/i, - night: /madrugada/i - } -}; -var match$1 = { - ordinalNumber: buildMatchPatternFn({ - matchPattern: matchOrdinalNumberPattern$1, - parsePattern: parseOrdinalNumberPattern$1, - valueCallback: function (value) { - return parseInt(value, 10); - } - }), - era: buildMatchFn({ - matchPatterns: matchEraPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseEraPatterns$1, - defaultParseWidth: 'any' - }), - quarter: buildMatchFn({ - matchPatterns: matchQuarterPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseQuarterPatterns$1, - defaultParseWidth: 'any', - valueCallback: function (index) { - return index + 1; - } - }), - month: buildMatchFn({ - matchPatterns: matchMonthPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseMonthPatterns$1, - defaultParseWidth: 'any' - }), - day: buildMatchFn({ - matchPatterns: matchDayPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseDayPatterns$1, - defaultParseWidth: 'any' - }), - dayPeriod: buildMatchFn({ - matchPatterns: matchDayPeriodPatterns$1, - defaultMatchWidth: 'any', - parsePatterns: parseDayPeriodPatterns$1, - defaultParseWidth: 'any' - }) -}; - -/** - * @type {Locale} - * @category Locales - * @summary Portuguese locale. - * @language Portuguese - * @iso-639-2 por - * @author Dário Freire [@dfreire]{@link https://github.com/dfreire} - * @author Adrián de la Rosa [@adrm]{@link https://github.com/adrm} - */ - -var locale$1 = { - code: 'pt', - formatDistance: formatDistance$1, - formatLong: formatLong$1, - formatRelative: formatRelative$1, - localize: localize$1, - match: match$1, - options: { - weekStartsOn: 1 - /* Monday */ - , - firstWeekContainsDate: 4 - } -}; - -/** - * @name compareAsc - * @category Common Helpers - * @summary Compare the two dates and return -1, 0 or 1. - * - * @description - * Compare the two dates and return 1 if the first date is after the second, - * -1 if the first date is before the second or 0 if dates are equal. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the first date to compare - * @param {Date|Number} dateRight - the second date to compare - * @returns {Number} the result of the comparison - * @throws {TypeError} 2 arguments required - * - * @example - * // Compare 11 February 1987 and 10 July 1989: - * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) - * //=> -1 - * - * @example - * // Sort the array of dates: - * var result = [ - * new Date(1995, 6, 2), - * new Date(1987, 1, 11), - * new Date(1989, 6, 10) - * ].sort(compareAsc) - * //=> [ - * // Wed Feb 11 1987 00:00:00, - * // Mon Jul 10 1989 00:00:00, - * // Sun Jul 02 1995 00:00:00 - * // ] - */ - -function compareAsc(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var diff = dateLeft.getTime() - dateRight.getTime(); - - if (diff < 0) { - return -1; - } else if (diff > 0) { - return 1; // Return 0 if diff is 0; return NaN if diff is NaN - } else { - return diff; - } -} - -/** - * @name differenceInCalendarMonths - * @category Month Helpers - * @summary Get the number of calendar months between the given dates. - * - * @description - * Get the number of calendar months between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of calendar months - * @throws {TypeError} 2 arguments required - * - * @example - * // How many calendar months are between 31 January 2014 and 1 September 2014? - * var result = differenceInCalendarMonths( - * new Date(2014, 8, 1), - * new Date(2014, 0, 31) - * ) - * //=> 8 - */ - -function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); - var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); - return yearDiff * 12 + monthDiff; -} - -/** - * @name differenceInMonths - * @category Month Helpers - * @summary Get the number of full months between the given dates. - * - * @description - * Get the number of full months between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of full months - * @throws {TypeError} 2 arguments required - * - * @example - * // How many full months are between 31 January 2014 and 1 September 2014? - * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) - * //=> 7 - */ - -function differenceInMonths(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var sign = compareAsc(dateLeft, dateRight); - var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); - dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full - // If so, result must be decreased by 1 in absolute value - - var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; - var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero - - return result === 0 ? 0 : result; -} - -/** - * @name differenceInMilliseconds - * @category Millisecond Helpers - * @summary Get the number of milliseconds between the given dates. - * - * @description - * Get the number of milliseconds between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of milliseconds - * @throws {TypeError} 2 arguments required - * - * @example - * // How many milliseconds are between - * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? - * var result = differenceInMilliseconds( - * new Date(2014, 6, 2, 12, 30, 21, 700), - * new Date(2014, 6, 2, 12, 30, 20, 600) - * ) - * //=> 1100 - */ - -function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - return dateLeft.getTime() - dateRight.getTime(); -} - -/** - * @name differenceInSeconds - * @category Second Helpers - * @summary Get the number of seconds between the given dates. - * - * @description - * Get the number of seconds between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of seconds - * @throws {TypeError} 2 arguments required - * - * @example - * // How many seconds are between - * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? - * var result = differenceInSeconds( - * new Date(2014, 6, 2, 12, 30, 20, 0), - * new Date(2014, 6, 2, 12, 30, 7, 999) - * ) - * //=> 12 - */ - -function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; - return diff > 0 ? Math.floor(diff) : Math.ceil(diff); -} - -function assign(target, dirtyObject) { - if (target == null) { - throw new TypeError('assign requires that input parameter not be null or undefined'); - } - - dirtyObject = dirtyObject || {}; - - for (var property in dirtyObject) { - if (dirtyObject.hasOwnProperty(property)) { - target[property] = dirtyObject[property]; - } - } - - return target; + return target; } function cloneObject(dirtyObject) { @@ -1605,131 +1226,510 @@ var MINUTES_IN_TWO_MONTHS = 86400; * //=> 'pli ol 1 jaro' */ -function formatDistance$2(dirtyDate, dirtyBaseDate, dirtyOptions) { - requiredArgs(2, arguments); - var options = dirtyOptions || {}; - var locale$1 = options.locale || locale; +function formatDistance$1(dirtyDate, dirtyBaseDate, dirtyOptions) { + requiredArgs(2, arguments); + var options = dirtyOptions || {}; + var locale$1 = options.locale || locale; + + if (!locale$1.formatDistance) { + throw new RangeError('locale must contain formatDistance property'); + } + + var comparison = compareAsc(dirtyDate, dirtyBaseDate); + + if (isNaN(comparison)) { + throw new RangeError('Invalid time value'); + } + + var localizeOptions = cloneObject(options); + localizeOptions.addSuffix = Boolean(options.addSuffix); + localizeOptions.comparison = comparison; + var dateLeft; + var dateRight; + + if (comparison > 0) { + dateLeft = toDate(dirtyBaseDate); + dateRight = toDate(dirtyDate); + } else { + dateLeft = toDate(dirtyDate); + dateRight = toDate(dirtyBaseDate); + } + + var seconds = differenceInSeconds(dateRight, dateLeft); + var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; + var minutes = Math.round((seconds - offsetInSeconds) / 60); + var months; // 0 up to 2 mins + + if (minutes < 2) { + if (options.includeSeconds) { + if (seconds < 5) { + return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); + } else if (seconds < 10) { + return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); + } else if (seconds < 20) { + return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); + } else if (seconds < 40) { + return locale$1.formatDistance('halfAMinute', null, localizeOptions); + } else if (seconds < 60) { + return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); + } else { + return locale$1.formatDistance('xMinutes', 1, localizeOptions); + } + } else { + if (minutes === 0) { + return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); + } else { + return locale$1.formatDistance('xMinutes', minutes, localizeOptions); + } + } // 2 mins up to 0.75 hrs + + } else if (minutes < 45) { + return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs + } else if (minutes < 90) { + return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs + } else if (minutes < MINUTES_IN_DAY) { + var hours = Math.round(minutes / 60); + return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days + } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { + return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days + } else if (minutes < MINUTES_IN_MONTH) { + var days = Math.round(minutes / MINUTES_IN_DAY); + return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months + } else if (minutes < MINUTES_IN_TWO_MONTHS) { + months = Math.round(minutes / MINUTES_IN_MONTH); + return locale$1.formatDistance('aboutXMonths', months, localizeOptions); + } + + months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months + + if (months < 12) { + var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); + return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date + } else { + var monthsSinceStartOfYear = months % 12; + var years = Math.floor(months / 12); // N years up to 1 years 3 months + + if (monthsSinceStartOfYear < 3) { + return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months + } else if (monthsSinceStartOfYear < 9) { + return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months + } else { + return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); + } + } +} + +function toInteger(dirtyNumber) { + if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { + return NaN; + } - if (!locale$1.formatDistance) { - throw new RangeError('locale must contain formatDistance property'); + var number = Number(dirtyNumber); + + if (isNaN(number)) { + return number; } - var comparison = compareAsc(dirtyDate, dirtyBaseDate); + return number < 0 ? Math.ceil(number) : Math.floor(number); +} - if (isNaN(comparison)) { - throw new RangeError('Invalid time value'); +// See issue: https://github.com/date-fns/date-fns/issues/376 + +function startOfUTCWeek(dirtyDate, dirtyOptions) { + requiredArgs(1, arguments); + var options = dirtyOptions || {}; + var locale = options.locale; + var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; + var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); + var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN + + if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { + throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); } - var localizeOptions = cloneObject(options); - localizeOptions.addSuffix = Boolean(options.addSuffix); - localizeOptions.comparison = comparison; - var dateLeft; - var dateRight; + var date = toDate(dirtyDate); + var day = date.getUTCDay(); + var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; + date.setUTCDate(date.getUTCDate() - diff); + date.setUTCHours(0, 0, 0, 0); + return date; +} - if (comparison > 0) { - dateLeft = toDate(dirtyBaseDate); - dateRight = toDate(dirtyDate); +var formatDistanceLocale$1 = { + lessThanXSeconds: { + one: 'menos de um segundo', + other: 'menos de {{count}} segundos' + }, + xSeconds: { + one: '1 segundo', + other: '{{count}} segundos' + }, + halfAMinute: 'meio minuto', + lessThanXMinutes: { + one: 'menos de um minuto', + other: 'menos de {{count}} minutos' + }, + xMinutes: { + one: '1 minuto', + other: '{{count}} minutos' + }, + aboutXHours: { + one: 'aproximadamente 1 hora', + other: 'aproximadamente {{count}} horas' + }, + xHours: { + one: '1 hora', + other: '{{count}} horas' + }, + xDays: { + one: '1 dia', + other: '{{count}} dias' + }, + aboutXWeeks: { + one: 'aproximadamente 1 mês', + // TODO + other: 'aproximadamente {{count}} meses' // TODO + + }, + xWeeks: { + one: '1 mês', + // TODO + other: '{{count}} meses' // TODO + + }, + aboutXMonths: { + one: 'aproximadamente 1 mês', + other: 'aproximadamente {{count}} meses' + }, + xMonths: { + one: '1 mês', + other: '{{count}} meses' + }, + aboutXYears: { + one: 'aproximadamente 1 ano', + other: 'aproximadamente {{count}} anos' + }, + xYears: { + one: '1 ano', + other: '{{count}} anos' + }, + overXYears: { + one: 'mais de 1 ano', + other: 'mais de {{count}} anos' + }, + almostXYears: { + one: 'quase 1 ano', + other: 'quase {{count}} anos' + } +}; +function formatDistance$2(token, count, options) { + options = options || {}; + var result; + + if (typeof formatDistanceLocale$1[token] === 'string') { + result = formatDistanceLocale$1[token]; + } else if (count === 1) { + result = formatDistanceLocale$1[token].one; } else { - dateLeft = toDate(dirtyDate); - dateRight = toDate(dirtyBaseDate); + result = formatDistanceLocale$1[token].other.replace('{{count}}', count); + } + + if (options.addSuffix) { + if (options.comparison > 0) { + return 'daqui a ' + result; + } else { + return 'há ' + result; + } + } + + return result; +} + +var dateFormats$1 = { + full: "EEEE, d 'de' MMMM 'de' y", + long: "d 'de' MMMM 'de' y", + medium: "d 'de' MMM 'de' y", + short: 'dd/MM/y' +}; +var timeFormats$1 = { + full: 'HH:mm:ss zzzz', + long: 'HH:mm:ss z', + medium: 'HH:mm:ss', + short: 'HH:mm' +}; +var dateTimeFormats$1 = { + full: "{{date}} 'às' {{time}}", + long: "{{date}} 'às' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +}; +var formatLong$1 = { + date: buildFormatLongFn({ + formats: dateFormats$1, + defaultWidth: 'full' + }), + time: buildFormatLongFn({ + formats: timeFormats$1, + defaultWidth: 'full' + }), + dateTime: buildFormatLongFn({ + formats: dateTimeFormats$1, + defaultWidth: 'full' + }) +}; + +var formatRelativeLocale$1 = { + lastWeek: "'na última' eeee 'às' p", + yesterday: "'ontem às' p", + today: "'hoje às' p", + tomorrow: "'amanhã às' p", + nextWeek: "eeee 'às' p", + other: 'P' +}; +function formatRelative$1(token, _date, _baseDate, _options) { + return formatRelativeLocale$1[token]; +} + +function ordinalNumber$1(dirtyNumber) { + var number = Number(dirtyNumber); + return number + 'º'; +} + +var eraValues$1 = { + narrow: ['aC', 'dC'], + abbreviated: ['a.C.', 'd.C.'], + wide: ['antes de Cristo', 'depois de Cristo'] +}; +var quarterValues$1 = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['T1', 'T2', 'T3', 'T4'], + wide: ['1º trimestre', '2º trimestre', '3º trimestre', '4º trimestre'] +}; +var monthValues$1 = { + narrow: ['j', 'f', 'm', 'a', 'm', 'j', 'j', 'a', 's', 'o', 'n', 'd'], + abbreviated: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], + wide: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] +}; +var dayValues$1 = { + narrow: ['d', 's', 't', 'q', 'q', 's', 's'], + short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], + abbreviated: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], + wide: ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'] +}; +var dayPeriodValues$1 = { + narrow: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + }, + abbreviated: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + }, + wide: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + } +}; +var formattingDayPeriodValues$1 = { + narrow: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' + }, + abbreviated: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' + }, + wide: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' } +}; +var localize$1 = { + ordinalNumber: ordinalNumber$1, + era: buildLocalizeFn({ + values: eraValues$1, + defaultWidth: 'wide' + }), + quarter: buildLocalizeFn({ + values: quarterValues$1, + defaultWidth: 'wide', + argumentCallback: function (quarter) { + return Number(quarter) - 1; + } + }), + month: buildLocalizeFn({ + values: monthValues$1, + defaultWidth: 'wide' + }), + day: buildLocalizeFn({ + values: dayValues$1, + defaultWidth: 'wide' + }), + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues$1, + defaultWidth: 'wide', + formattingValues: formattingDayPeriodValues$1, + defaultFormattingWidth: 'wide' + }) +}; - var seconds = differenceInSeconds(dateRight, dateLeft); - var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; - var minutes = Math.round((seconds - offsetInSeconds) / 60); - var months; // 0 up to 2 mins - - if (minutes < 2) { - if (options.includeSeconds) { - if (seconds < 5) { - return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); - } else if (seconds < 10) { - return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); - } else if (seconds < 20) { - return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); - } else if (seconds < 40) { - return locale$1.formatDistance('halfAMinute', null, localizeOptions); - } else if (seconds < 60) { - return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); - } else { - return locale$1.formatDistance('xMinutes', 1, localizeOptions); - } - } else { - if (minutes === 0) { - return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); - } else { - return locale$1.formatDistance('xMinutes', minutes, localizeOptions); - } - } // 2 mins up to 0.75 hrs - - } else if (minutes < 45) { - return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs - } else if (minutes < 90) { - return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs - } else if (minutes < MINUTES_IN_DAY) { - var hours = Math.round(minutes / 60); - return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days - } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { - return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days - } else if (minutes < MINUTES_IN_MONTH) { - var days = Math.round(minutes / MINUTES_IN_DAY); - return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months - } else if (minutes < MINUTES_IN_TWO_MONTHS) { - months = Math.round(minutes / MINUTES_IN_MONTH); - return locale$1.formatDistance('aboutXMonths', months, localizeOptions); +var matchOrdinalNumberPattern$1 = /^(\d+)(º|ª)?/i; +var parseOrdinalNumberPattern$1 = /\d+/i; +var matchEraPatterns$1 = { + narrow: /^(ac|dc|a|d)/i, + abbreviated: /^(a\.?\s?c\.?|a\.?\s?e\.?\s?c\.?|d\.?\s?c\.?|e\.?\s?c\.?)/i, + wide: /^(antes de cristo|antes da era comum|depois de cristo|era comum)/i +}; +var parseEraPatterns$1 = { + any: [/^ac/i, /^dc/i], + wide: [/^(antes de cristo|antes da era comum)/i, /^(depois de cristo|era comum)/i] +}; +var matchQuarterPatterns$1 = { + narrow: /^[1234]/i, + abbreviated: /^T[1234]/i, + wide: /^[1234](º|ª)? trimestre/i +}; +var parseQuarterPatterns$1 = { + any: [/1/i, /2/i, /3/i, /4/i] +}; +var matchMonthPatterns$1 = { + narrow: /^[jfmasond]/i, + abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i, + wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i +}; +var parseMonthPatterns$1 = { + narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], + any: [/^ja/i, /^f/i, /^mar/i, /^ab/i, /^mai/i, /^jun/i, /^jul/i, /^ag/i, /^s/i, /^o/i, /^n/i, /^d/i] +}; +var matchDayPatterns$1 = { + narrow: /^[dstq]/i, + short: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, + abbreviated: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, + wide: /^(domingo|segunda-?\s?feira|terça-?\s?feira|quarta-?\s?feira|quinta-?\s?feira|sexta-?\s?feira|s[áa]bado)/i +}; +var parseDayPatterns$1 = { + narrow: [/^d/i, /^s/i, /^t/i, /^q/i, /^q/i, /^s/i, /^s/i], + any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[áa]/i] +}; +var matchDayPeriodPatterns$1 = { + narrow: /^(a|p|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i, + any: /^([ap]\.?\s?m\.?|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i +}; +var parseDayPeriodPatterns$1 = { + any: { + am: /^a/i, + pm: /^p/i, + midnight: /^meia/i, + noon: /^meio/i, + morning: /manh[ãa]/i, + afternoon: /tarde/i, + evening: /noite/i, + night: /madrugada/i } - - months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months - - if (months < 12) { - var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); - return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date - } else { - var monthsSinceStartOfYear = months % 12; - var years = Math.floor(months / 12); // N years up to 1 years 3 months - - if (monthsSinceStartOfYear < 3) { - return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months - } else if (monthsSinceStartOfYear < 9) { - return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months - } else { - return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); +}; +var match$1 = { + ordinalNumber: buildMatchPatternFn({ + matchPattern: matchOrdinalNumberPattern$1, + parsePattern: parseOrdinalNumberPattern$1, + valueCallback: function (value) { + return parseInt(value, 10); } - } -} + }), + era: buildMatchFn({ + matchPatterns: matchEraPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseEraPatterns$1, + defaultParseWidth: 'any' + }), + quarter: buildMatchFn({ + matchPatterns: matchQuarterPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseQuarterPatterns$1, + defaultParseWidth: 'any', + valueCallback: function (index) { + return index + 1; + } + }), + month: buildMatchFn({ + matchPatterns: matchMonthPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseMonthPatterns$1, + defaultParseWidth: 'any' + }), + day: buildMatchFn({ + matchPatterns: matchDayPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseDayPatterns$1, + defaultParseWidth: 'any' + }), + dayPeriod: buildMatchFn({ + matchPatterns: matchDayPeriodPatterns$1, + defaultMatchWidth: 'any', + parsePatterns: parseDayPeriodPatterns$1, + defaultParseWidth: 'any' + }) +}; -var MILLISECONDS_IN_HOUR = 3600000; /** - * @name differenceInHours - * @category Hour Helpers - * @summary Get the number of hours between the given dates. - * - * @description - * Get the number of hours between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of hours - * @throws {TypeError} 2 arguments required - * - * @example - * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? - * var result = differenceInHours( - * new Date(2014, 6, 2, 19, 0), - * new Date(2014, 6, 2, 6, 50) - * ) - * //=> 12 + * @type {Locale} + * @category Locales + * @summary Portuguese locale. + * @language Portuguese + * @iso-639-2 por + * @author Dário Freire [@dfreire]{@link https://github.com/dfreire} + * @author Adrián de la Rosa [@adrm]{@link https://github.com/adrm} */ -function differenceInHours(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR; - return diff > 0 ? Math.floor(diff) : Math.ceil(diff); -} +var locale$1 = { + code: 'pt', + formatDistance: formatDistance$2, + formatLong: formatLong$1, + formatRelative: formatRelative$1, + localize: localize$1, + match: match$1, + options: { + weekStartsOn: 1 + /* Monday */ + , + firstWeekContainsDate: 4 + } +}; /** * @name isValid @@ -3474,7 +3474,7 @@ function cleanEscapedString(input) { var datePtBrFull = function datePtBrFull(date) { if (!date) return false; - var d = date.replace("T", " "); + var d = date.replace('T', ' '); var _y = d.split('-'); @@ -3485,12 +3485,12 @@ var datePtBrFull = function datePtBrFull(date) { var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]); if (!(_date instanceof Date)) return false; - return "".concat(format(_date, "dd/MM/yyyy"), " \xE0s ").concat(format(_date, "HH:mm")); + return "".concat(format(_date, 'dd/MM/yyyy'), " \xE0s ").concat(format(_date, 'HH:mm')); }; var dateDistance = function dateDistance(date, limit) { if (!date) return false; - var d = date.replace("T", " "); + var d = date.replace('T', ' '); var _y = d.split('-'); @@ -3502,16 +3502,16 @@ var dateDistance = function dateDistance(date, limit) { var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime(); - var distanteInWords = formatDistance$2(_now, _date, { + var distanteInWords = formatDistance$1(_now, _date, { locale: locale$1 }); var diffHours = differenceInHours(_now, _date, { locale: locale$1 }); if (diffHours > limit) return datePtBrFull(date); - var replaces = [["aproximadamente ", ""]]; + var replaces = [['aproximadamente ', '']]; var date_string = distanteInWords; - lodash.map(replaces, function (r, k) { + lodash.map(replaces, function (r) { date_string = date_string.replace(r[0], r[1]); }); return "H\xE1 ".concat(date_string); @@ -3522,6 +3522,8 @@ var utils = { datePtBrFull: datePtBrFull }; +var _PropTypes$shape; + var Teaser = function Teaser(_ref) { var content = _ref.content, datePublished = _ref.datePublished, @@ -3577,8 +3579,8 @@ var Teaser = function Teaser(_ref) { }; if (!content['time-published']) return false; var dateValue = !datePublished && content['time-modifiedDate'] ? utils.dateDistance(content['time-modifiedDate'], 2880) : utils.datePtBrFull(content['time-published']); - dateValue = datePublished ? "Publicado em ".concat(dateValue) : dateValue.startsWith("Há") ? dateValue.replace("H\xE1", "Atualizado h\xE1") : "Atualizado em ".concat(dateValue); - var path_split = path.split(":8080"); + dateValue = datePublished ? "Publicado em ".concat(dateValue) : dateValue.startsWith('Há') ? dateValue.replace('Há', 'Atualizado há') : "Atualizado em ".concat(dateValue); + var path_split = path.split(':8080'); var url_rewrite = path_split.length > 1 ? "".concat(domain).concat(path_split[1]) : path; var TeaserImage = function TeaserImage() { @@ -3609,19 +3611,20 @@ var Teaser = function Teaser(_ref) { }; Teaser.propTypes = { - content: PropTypes.shape(_defineProperty({ + content: PropTypes.shape((_PropTypes$shape = { image: PropTypes.object, name: PropTypes.string, path: PropTypes.string, subtitle: PropTypes.string, subject: PropTypes.string - }, 'time-published', PropTypes.string)), + }, _defineProperty(_PropTypes$shape, 'time-published', PropTypes.string), _defineProperty(_PropTypes$shape, 'time-modified', PropTypes.string), _PropTypes$shape)), datePublished: PropTypes.bool, domain: PropTypes.string, hasImageTop: PropTypes.bool, hasSubtitle: PropTypes.bool, hasDate: PropTypes.bool, hasSubjectFilled: PropTypes.bool, + lazy: PropTypes.func, status: PropTypes.shape({ loading: PropTypes.bool, error: PropTypes.bool diff --git a/templates.js b/templates.js index 034bb3f30..ebed096f7 100644 --- a/templates.js +++ b/templates.js @@ -105,71 +105,6 @@ Block.propTypes = { }; Block.defaultProps = {}; -var pathToImage = function pathToImage(derivative, domain, policy_id, width) { - if (!policy_id) return null; - var w = width || 1000; - var r = domain || 'https://costanorte.com.br'; - var d = derivative || '2x1'; - var id = policy_id.split("."); - var string = id.length > 2 ? "".concat(policy_id, ":").concat(id[2]) : "".concat(policy_id); - var path = "".concat(r, "/image/policy:").concat(string, "/image.jpg?f=").concat(d, "&w=").concat(w); - return path; -}; - -var Image = function Image(_ref) { - var children = _ref.children, - content = _ref.content, - custom = _ref.custom, - domain = _ref.domain, - height = _ref.height, - lazy = _ref.lazy, - placeholder = _ref.placeholder; - var img_placeholder = placeholder || null; - - if (content['image-contentId']) { - var policy_id = content['image-contentId']; - var derivative = "2x1"; - var width = 1000; - content['image-path'] = pathToImage(derivative, domain, policy_id, width); - img_placeholder = img_placeholder || pathToImage(derivative, domain, policy_id, 10); - } - - var content_path = content['image-path']; - var image_style; - - if (lazy) { - image_style = { - backgroundImage: "url(".concat(lazy(content_path, img_placeholder), ")") - }; - } else { - image_style = { - backgroundImage: "url(".concat(content_path, ")") - }; - } - - if (height) { - image_style.height = height; - } - - return /*#__PURE__*/React.createElement("div", { - className: "image-background ".concat(custom || ''), - style: image_style - }, children && children); -}; - -Image.propTypes = { - children: PropTypes.node, - content: PropTypes.object.isRequired, - custom: PropTypes.string, - domain: PropTypes.string, - height: PropTypes.string, - lazy: PropTypes.func, - placeholder: PropTypes.string -}; -Image.defaultProps = { - content: {} -}; - var Typography = function Typography(props) { var _classnames; @@ -269,6 +204,87 @@ Typography.propTypes = { tokenVariant: PropTypes.oneOf(['article-title', 'article-title-intro', 'article-subtitle', 'article-subtitle-intro', 'article-paragraph', 'article-tag', 'title', 'subtitle', 'paragraph', 'paragraph-inner', 'subject', 'system', 'system-bold']) }; +var SectionTitle = function SectionTitle(_ref) { + var custom = _ref.custom, + name = _ref.name; + return /*#__PURE__*/React.createElement(Block, { + custom: "section-title-block", + mb: "3" + }, /*#__PURE__*/React.createElement(Typography, { + custom: "section-title ".concat(custom) + }, name)); +}; + +SectionTitle.propTypes = { + custom: PropTypes.string, + name: PropTypes.string +}; + +var pathToImage = function pathToImage(derivative, domain, policy_id, width) { + if (!policy_id) return null; + var w = width || 1000; + var r = domain || 'https://costanorte.com.br'; + var d = derivative || '2x1'; + var id = policy_id.split('.'); + var string = id.length > 2 ? "".concat(policy_id, ":").concat(id[2]) : "".concat(policy_id); + var path = "".concat(r, "/image/policy:").concat(string, "/image.jpg?f=").concat(d, "&w=").concat(w); + return path; +}; + +var Image = function Image(_ref) { + var children = _ref.children, + content = _ref.content, + custom = _ref.custom, + domain = _ref.domain, + height = _ref.height, + lazy = _ref.lazy, + placeholder = _ref.placeholder; + var img_placeholder = placeholder || null; + + if (content['image-contentId']) { + var policy_id = content['image-contentId']; + var derivative = '2x1'; + var width = 1000; + content['image-path'] = pathToImage(derivative, domain, policy_id, width); + img_placeholder = img_placeholder || pathToImage(derivative, domain, policy_id, 10); + } + + var content_path = content['image-path']; + var image_style; + + if (lazy) { + image_style = { + backgroundImage: "url(".concat(lazy(content_path, img_placeholder), ")") + }; + } else { + image_style = { + backgroundImage: "url(".concat(content_path, ")") + }; + } + + if (height) { + image_style.height = height; + } + + return /*#__PURE__*/React.createElement("div", { + className: "image-background ".concat(custom || ''), + style: image_style + }, children && children); +}; + +Image.propTypes = { + children: PropTypes.node, + content: PropTypes.object.isRequired, + custom: PropTypes.string, + domain: PropTypes.string, + height: PropTypes.string, + lazy: PropTypes.func, + placeholder: PropTypes.string +}; +Image.defaultProps = { + content: {} +}; + var Subject = function Subject(props) { var children = props.children, custom = props.custom, @@ -294,207 +310,287 @@ Subject.propTypes = { }; -function buildFormatLongFn(args) { - return function (dirtyOptions) { - var options = dirtyOptions || {}; - var width = options.width ? String(options.width) : args.defaultWidth; - var format = args.formats[width] || args.formats[args.defaultWidth]; - return format; - }; +function requiredArgs(required, args) { + if (args.length < required) { + throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); + } } -function buildLocalizeFn(args) { - return function (dirtyIndex, dirtyOptions) { - var options = dirtyOptions || {}; - var context = options.context ? String(options.context) : 'standalone'; - var valuesArray; +/** + * @name toDate + * @category Common Helpers + * @summary Convert the given argument to an instance of Date. + * + * @description + * Convert the given argument to an instance of Date. + * + * If the argument is an instance of Date, the function returns its clone. + * + * If the argument is a number, it is treated as a timestamp. + * + * If the argument is none of the above, the function returns Invalid Date. + * + * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`. + * + * @param {Date|Number} argument - the value to convert + * @returns {Date} the parsed date in the local time zone + * @throws {TypeError} 1 argument required + * + * @example + * // Clone the date: + * const result = toDate(new Date(2014, 1, 11, 11, 30, 30)) + * //=> Tue Feb 11 2014 11:30:30 + * + * @example + * // Convert the timestamp to date: + * const result = toDate(1392098430000) + * //=> Tue Feb 11 2014 11:30:30 + */ - if (context === 'formatting' && args.formattingValues) { - var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; - var width = options.width ? String(options.width) : defaultWidth; - valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; - } else { - var _defaultWidth = args.defaultWidth; +function toDate(argument) { + requiredArgs(1, arguments); + var argStr = Object.prototype.toString.call(argument); // Clone the date - var _width = options.width ? String(options.width) : args.defaultWidth; + if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') { + // Prevent the date to lose the milliseconds when passed to new Date() in IE10 + return new Date(argument.getTime()); + } else if (typeof argument === 'number' || argStr === '[object Number]') { + return new Date(argument); + } else { + if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { + // eslint-disable-next-line no-console + console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console - valuesArray = args.values[_width] || args.values[_defaultWidth]; + console.warn(new Error().stack); } - var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; - return valuesArray[index]; - }; + return new Date(NaN); + } } -function buildMatchPatternFn(args) { - return function (dirtyString, dirtyOptions) { - var string = String(dirtyString); - var options = dirtyOptions || {}; - var matchResult = string.match(args.matchPattern); - - if (!matchResult) { - return null; - } +/** + * @name differenceInMilliseconds + * @category Millisecond Helpers + * @summary Get the number of milliseconds between the given dates. + * + * @description + * Get the number of milliseconds between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of milliseconds + * @throws {TypeError} 2 arguments required + * + * @example + * // How many milliseconds are between + * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? + * var result = differenceInMilliseconds( + * new Date(2014, 6, 2, 12, 30, 21, 700), + * new Date(2014, 6, 2, 12, 30, 20, 600) + * ) + * //=> 1100 + */ - var matchedString = matchResult[0]; - var parseResult = string.match(args.parsePattern); +function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + return dateLeft.getTime() - dateRight.getTime(); +} - if (!parseResult) { - return null; - } - - var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; - value = options.valueCallback ? options.valueCallback(value) : value; - return { - value: value, - rest: string.slice(matchedString.length) - }; - }; -} - -function buildMatchFn(args) { - return function (dirtyString, dirtyOptions) { - var string = String(dirtyString); - var options = dirtyOptions || {}; - var width = options.width; - var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; - var matchResult = string.match(matchPattern); - - if (!matchResult) { - return null; - } - - var matchedString = matchResult[0]; - var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; - var value; - - if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { - value = findIndex(parsePatterns, function (pattern) { - return pattern.test(matchedString); - }); - } else { - value = findKey(parsePatterns, function (pattern) { - return pattern.test(matchedString); - }); - } - - value = args.valueCallback ? args.valueCallback(value) : value; - value = options.valueCallback ? options.valueCallback(value) : value; - return { - value: value, - rest: string.slice(matchedString.length) - }; - }; -} - -function findKey(object, predicate) { - for (var key in object) { - if (object.hasOwnProperty(key) && predicate(object[key])) { - return key; - } - } -} - -function findIndex(array, predicate) { - for (var key = 0; key < array.length; key++) { - if (predicate(array[key])) { - return key; - } - } -} - -function toInteger(dirtyNumber) { - if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { - return NaN; - } - - var number = Number(dirtyNumber); - - if (isNaN(number)) { - return number; - } - - return number < 0 ? Math.ceil(number) : Math.floor(number); -} +var MILLISECONDS_IN_HOUR = 3600000; +/** + * @name differenceInHours + * @category Hour Helpers + * @summary Get the number of hours between the given dates. + * + * @description + * Get the number of hours between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of hours + * @throws {TypeError} 2 arguments required + * + * @example + * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? + * var result = differenceInHours( + * new Date(2014, 6, 2, 19, 0), + * new Date(2014, 6, 2, 6, 50) + * ) + * //=> 12 + */ -function requiredArgs(required, args) { - if (args.length < required) { - throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present'); - } +function differenceInHours(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR; + return diff > 0 ? Math.floor(diff) : Math.ceil(diff); } /** - * @name toDate + * @name compareAsc * @category Common Helpers - * @summary Convert the given argument to an instance of Date. + * @summary Compare the two dates and return -1, 0 or 1. * * @description - * Convert the given argument to an instance of Date. - * - * If the argument is an instance of Date, the function returns its clone. - * - * If the argument is a number, it is treated as a timestamp. + * Compare the two dates and return 1 if the first date is after the second, + * -1 if the first date is before the second or 0 if dates are equal. * - * If the argument is none of the above, the function returns Invalid Date. + * ### v2.0.0 breaking changes: * - * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`. + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * - * @param {Date|Number} argument - the value to convert - * @returns {Date} the parsed date in the local time zone - * @throws {TypeError} 1 argument required + * @param {Date|Number} dateLeft - the first date to compare + * @param {Date|Number} dateRight - the second date to compare + * @returns {Number} the result of the comparison + * @throws {TypeError} 2 arguments required * * @example - * // Clone the date: - * const result = toDate(new Date(2014, 1, 11, 11, 30, 30)) - * //=> Tue Feb 11 2014 11:30:30 + * // Compare 11 February 1987 and 10 July 1989: + * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) + * //=> -1 * * @example - * // Convert the timestamp to date: - * const result = toDate(1392098430000) - * //=> Tue Feb 11 2014 11:30:30 + * // Sort the array of dates: + * var result = [ + * new Date(1995, 6, 2), + * new Date(1987, 1, 11), + * new Date(1989, 6, 10) + * ].sort(compareAsc) + * //=> [ + * // Wed Feb 11 1987 00:00:00, + * // Mon Jul 10 1989 00:00:00, + * // Sun Jul 02 1995 00:00:00 + * // ] */ -function toDate(argument) { - requiredArgs(1, arguments); - var argStr = Object.prototype.toString.call(argument); // Clone the date +function compareAsc(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var diff = dateLeft.getTime() - dateRight.getTime(); - if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') { - // Prevent the date to lose the milliseconds when passed to new Date() in IE10 - return new Date(argument.getTime()); - } else if (typeof argument === 'number' || argStr === '[object Number]') { - return new Date(argument); + if (diff < 0) { + return -1; + } else if (diff > 0) { + return 1; // Return 0 if diff is 0; return NaN if diff is NaN } else { - if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') { - // eslint-disable-next-line no-console - console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console + return diff; + } +} - console.warn(new Error().stack); - } +/** + * @name differenceInCalendarMonths + * @category Month Helpers + * @summary Get the number of calendar months between the given dates. + * + * @description + * Get the number of calendar months between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of calendar months + * @throws {TypeError} 2 arguments required + * + * @example + * // How many calendar months are between 31 January 2014 and 1 September 2014? + * var result = differenceInCalendarMonths( + * new Date(2014, 8, 1), + * new Date(2014, 0, 31) + * ) + * //=> 8 + */ - return new Date(NaN); - } +function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); + var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); + return yearDiff * 12 + monthDiff; } -// See issue: https://github.com/date-fns/date-fns/issues/376 +/** + * @name differenceInMonths + * @category Month Helpers + * @summary Get the number of full months between the given dates. + * + * @description + * Get the number of full months between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of full months + * @throws {TypeError} 2 arguments required + * + * @example + * // How many full months are between 31 January 2014 and 1 September 2014? + * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) + * //=> 7 + */ -function startOfUTCWeek(dirtyDate, dirtyOptions) { - requiredArgs(1, arguments); - var options = dirtyOptions || {}; - var locale = options.locale; - var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; - var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); - var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN +function differenceInMonths(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var dateLeft = toDate(dirtyDateLeft); + var dateRight = toDate(dirtyDateRight); + var sign = compareAsc(dateLeft, dateRight); + var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); + dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full + // If so, result must be decreased by 1 in absolute value - if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { - throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); - } + var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; + var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero - var date = toDate(dirtyDate); - var day = date.getUTCDay(); - var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; - date.setUTCDate(date.getUTCDate() - diff); - date.setUTCHours(0, 0, 0, 0); - return date; + return result === 0 ? 0 : result; +} + +/** + * @name differenceInSeconds + * @category Second Helpers + * @summary Get the number of seconds between the given dates. + * + * @description + * Get the number of seconds between the given dates. + * + * ### v2.0.0 breaking changes: + * + * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * + * @param {Date|Number} dateLeft - the later date + * @param {Date|Number} dateRight - the earlier date + * @returns {Number} the number of seconds + * @throws {TypeError} 2 arguments required + * + * @example + * // How many seconds are between + * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? + * var result = differenceInSeconds( + * new Date(2014, 6, 2, 12, 30, 20, 0), + * new Date(2014, 6, 2, 12, 30, 7, 999) + * ) + * //=> 12 + */ + +function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { + requiredArgs(2, arguments); + var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; + return diff > 0 ? Math.floor(diff) : Math.ceil(diff); } var formatDistanceLocale = { @@ -583,6 +679,48 @@ function formatDistance(token, count, options) { return result; } +function buildFormatLongFn(args) { + return function (dirtyOptions) { + var options = dirtyOptions || {}; + var width = options.width ? String(options.width) : args.defaultWidth; + var format = args.formats[width] || args.formats[args.defaultWidth]; + return format; + }; +} + +var dateFormats = { + full: 'EEEE, MMMM do, y', + long: 'MMMM do, y', + medium: 'MMM d, y', + short: 'MM/dd/yyyy' +}; +var timeFormats = { + full: 'h:mm:ss a zzzz', + long: 'h:mm:ss a z', + medium: 'h:mm:ss a', + short: 'h:mm a' +}; +var dateTimeFormats = { + full: "{{date}} 'at' {{time}}", + long: "{{date}} 'at' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +}; +var formatLong = { + date: buildFormatLongFn({ + formats: dateFormats, + defaultWidth: 'full' + }), + time: buildFormatLongFn({ + formats: timeFormats, + defaultWidth: 'full' + }), + dateTime: buildFormatLongFn({ + formats: dateTimeFormats, + defaultWidth: 'full' + }) +}; + var formatRelativeLocale = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", @@ -595,6 +733,29 @@ function formatRelative(token, _date, _baseDate, _options) { return formatRelativeLocale[token]; } +function buildLocalizeFn(args) { + return function (dirtyIndex, dirtyOptions) { + var options = dirtyOptions || {}; + var context = options.context ? String(options.context) : 'standalone'; + var valuesArray; + + if (context === 'formatting' && args.formattingValues) { + var defaultWidth = args.defaultFormattingWidth || args.defaultWidth; + var width = options.width ? String(options.width) : defaultWidth; + valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth]; + } else { + var _defaultWidth = args.defaultWidth; + + var _width = options.width ? String(options.width) : args.defaultWidth; + + valuesArray = args.values[_width] || args.values[_defaultWidth]; + } + + var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; + return valuesArray[index]; + }; +} + var eraValues = { narrow: ['B', 'A'], abbreviated: ['BC', 'AD'], @@ -743,6 +904,83 @@ var localize = { }) }; +function buildMatchPatternFn(args) { + return function (dirtyString, dirtyOptions) { + var string = String(dirtyString); + var options = dirtyOptions || {}; + var matchResult = string.match(args.matchPattern); + + if (!matchResult) { + return null; + } + + var matchedString = matchResult[0]; + var parseResult = string.match(args.parsePattern); + + if (!parseResult) { + return null; + } + + var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0]; + value = options.valueCallback ? options.valueCallback(value) : value; + return { + value: value, + rest: string.slice(matchedString.length) + }; + }; +} + +function buildMatchFn(args) { + return function (dirtyString, dirtyOptions) { + var string = String(dirtyString); + var options = dirtyOptions || {}; + var width = options.width; + var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth]; + var matchResult = string.match(matchPattern); + + if (!matchResult) { + return null; + } + + var matchedString = matchResult[0]; + var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth]; + var value; + + if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { + value = findIndex(parsePatterns, function (pattern) { + return pattern.test(matchedString); + }); + } else { + value = findKey(parsePatterns, function (pattern) { + return pattern.test(matchedString); + }); + } + + value = args.valueCallback ? args.valueCallback(value) : value; + value = options.valueCallback ? options.valueCallback(value) : value; + return { + value: value, + rest: string.slice(matchedString.length) + }; + }; +} + +function findKey(object, predicate) { + for (var key in object) { + if (object.hasOwnProperty(key) && predicate(object[key])) { + return key; + } + } +} + +function findIndex(array, predicate) { + for (var key = 0; key < array.length; key++) { + if (predicate(array[key])) { + return key; + } + } +} + var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i; var parseOrdinalNumberPattern = /\d+/i; var matchEraPatterns = { @@ -839,39 +1077,6 @@ var match = { }) }; -var dateFormats = { - full: 'EEEE, MMMM do, y', - long: 'MMMM do, y', - medium: 'MMM d, y', - short: 'MM/dd/yyyy' -}; -var timeFormats = { - full: 'h:mm:ss a zzzz', - long: 'h:mm:ss a z', - medium: 'h:mm:ss a', - short: 'h:mm a' -}; -var dateTimeFormats = { - full: "{{date}} 'at' {{time}}", - long: "{{date}} 'at' {{time}}", - medium: '{{date}}, {{time}}', - short: '{{date}}, {{time}}' -}; -var formatLong = { - date: buildFormatLongFn({ - formats: dateFormats, - defaultWidth: 'full' - }), - time: buildFormatLongFn({ - formats: timeFormats, - defaultWidth: 'full' - }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats, - defaultWidth: 'full' - }) -}; - /** * @type {Locale} * @category Locales @@ -897,859 +1102,670 @@ var locale = { } }; -var formatDistanceLocale$1 = { - lessThanXSeconds: { - one: 'menos de um segundo', - other: 'menos de {{count}} segundos' - }, - xSeconds: { - one: '1 segundo', - other: '{{count}} segundos' - }, - halfAMinute: 'meio minuto', - lessThanXMinutes: { - one: 'menos de um minuto', - other: 'menos de {{count}} minutos' - }, - xMinutes: { - one: '1 minuto', - other: '{{count}} minutos' - }, - aboutXHours: { - one: 'aproximadamente 1 hora', - other: 'aproximadamente {{count}} horas' - }, - xHours: { - one: '1 hora', - other: '{{count}} horas' - }, - xDays: { - one: '1 dia', - other: '{{count}} dias' - }, - aboutXWeeks: { - one: 'aproximadamente 1 mês', - // TODO - other: 'aproximadamente {{count}} meses' // TODO +function assign(target, dirtyObject) { + if (target == null) { + throw new TypeError('assign requires that input parameter not be null or undefined'); + } - }, - xWeeks: { - one: '1 mês', - // TODO - other: '{{count}} meses' // TODO - - }, - aboutXMonths: { - one: 'aproximadamente 1 mês', - other: 'aproximadamente {{count}} meses' - }, - xMonths: { - one: '1 mês', - other: '{{count}} meses' - }, - aboutXYears: { - one: 'aproximadamente 1 ano', - other: 'aproximadamente {{count}} anos' - }, - xYears: { - one: '1 ano', - other: '{{count}} anos' - }, - overXYears: { - one: 'mais de 1 ano', - other: 'mais de {{count}} anos' - }, - almostXYears: { - one: 'quase 1 ano', - other: 'quase {{count}} anos' - } -}; -function formatDistance$1(token, count, options) { - options = options || {}; - var result; - - if (typeof formatDistanceLocale$1[token] === 'string') { - result = formatDistanceLocale$1[token]; - } else if (count === 1) { - result = formatDistanceLocale$1[token].one; - } else { - result = formatDistanceLocale$1[token].other.replace('{{count}}', count); - } + dirtyObject = dirtyObject || {}; - if (options.addSuffix) { - if (options.comparison > 0) { - return 'daqui a ' + result; - } else { - return 'há ' + result; + for (var property in dirtyObject) { + if (dirtyObject.hasOwnProperty(property)) { + target[property] = dirtyObject[property]; } } - return result; + return target; } -var dateFormats$1 = { - full: "EEEE, d 'de' MMMM 'de' y", - long: "d 'de' MMMM 'de' y", - medium: "d 'de' MMM 'de' y", - short: 'dd/MM/y' -}; -var timeFormats$1 = { - full: 'HH:mm:ss zzzz', - long: 'HH:mm:ss z', - medium: 'HH:mm:ss', - short: 'HH:mm' -}; -var dateTimeFormats$1 = { - full: "{{date}} 'às' {{time}}", - long: "{{date}} 'às' {{time}}", - medium: '{{date}}, {{time}}', - short: '{{date}}, {{time}}' -}; -var formatLong$1 = { - date: buildFormatLongFn({ - formats: dateFormats$1, - defaultWidth: 'full' - }), - time: buildFormatLongFn({ - formats: timeFormats$1, - defaultWidth: 'full' - }), - dateTime: buildFormatLongFn({ - formats: dateTimeFormats$1, - defaultWidth: 'full' - }) -}; - -var formatRelativeLocale$1 = { - lastWeek: "'na última' eeee 'às' p", - yesterday: "'ontem às' p", - today: "'hoje às' p", - tomorrow: "'amanhã às' p", - nextWeek: "eeee 'às' p", - other: 'P' -}; -function formatRelative$1(token, _date, _baseDate, _options) { - return formatRelativeLocale$1[token]; +function cloneObject(dirtyObject) { + return assign({}, dirtyObject); } -function ordinalNumber$1(dirtyNumber) { - var number = Number(dirtyNumber); - return number + 'º'; +var MILLISECONDS_IN_MINUTE = 60000; + +function getDateMillisecondsPart(date) { + return date.getTime() % MILLISECONDS_IN_MINUTE; } +/** + * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. + * They usually appear for dates that denote time before the timezones were introduced + * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891 + * and GMT+01:00:00 after that date) + * + * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above, + * which would lead to incorrect calculations. + * + * This function returns the timezone offset in milliseconds that takes seconds in account. + */ -var eraValues$1 = { - narrow: ['aC', 'dC'], - abbreviated: ['a.C.', 'd.C.'], - wide: ['antes de Cristo', 'depois de Cristo'] -}; -var quarterValues$1 = { - narrow: ['1', '2', '3', '4'], - abbreviated: ['T1', 'T2', 'T3', 'T4'], - wide: ['1º trimestre', '2º trimestre', '3º trimestre', '4º trimestre'] -}; -var monthValues$1 = { - narrow: ['j', 'f', 'm', 'a', 'm', 'j', 'j', 'a', 's', 'o', 'n', 'd'], - abbreviated: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], - wide: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] -}; -var dayValues$1 = { - narrow: ['d', 's', 't', 'q', 'q', 's', 's'], - short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], - abbreviated: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], - wide: ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'] -}; -var dayPeriodValues$1 = { - narrow: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - }, - abbreviated: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - }, - wide: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'manhã', - afternoon: 'tarde', - evening: 'noite', - night: 'madrugada' - } -}; -var formattingDayPeriodValues$1 = { - narrow: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - }, - abbreviated: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - }, - wide: { - am: 'AM', - pm: 'PM', - midnight: 'meia-noite', - noon: 'meio-dia', - morning: 'da manhã', - afternoon: 'da tarde', - evening: 'da noite', - night: 'da madrugada' - } -}; -var localize$1 = { - ordinalNumber: ordinalNumber$1, - era: buildLocalizeFn({ - values: eraValues$1, - defaultWidth: 'wide' - }), - quarter: buildLocalizeFn({ - values: quarterValues$1, - defaultWidth: 'wide', - argumentCallback: function (quarter) { - return Number(quarter) - 1; - } - }), - month: buildLocalizeFn({ - values: monthValues$1, - defaultWidth: 'wide' - }), - day: buildLocalizeFn({ - values: dayValues$1, - defaultWidth: 'wide' - }), - dayPeriod: buildLocalizeFn({ - values: dayPeriodValues$1, - defaultWidth: 'wide', - formattingValues: formattingDayPeriodValues$1, - defaultFormattingWidth: 'wide' - }) -}; -var matchOrdinalNumberPattern$1 = /^(\d+)(º|ª)?/i; -var parseOrdinalNumberPattern$1 = /\d+/i; -var matchEraPatterns$1 = { - narrow: /^(ac|dc|a|d)/i, - abbreviated: /^(a\.?\s?c\.?|a\.?\s?e\.?\s?c\.?|d\.?\s?c\.?|e\.?\s?c\.?)/i, - wide: /^(antes de cristo|antes da era comum|depois de cristo|era comum)/i -}; -var parseEraPatterns$1 = { - any: [/^ac/i, /^dc/i], - wide: [/^(antes de cristo|antes da era comum)/i, /^(depois de cristo|era comum)/i] -}; -var matchQuarterPatterns$1 = { - narrow: /^[1234]/i, - abbreviated: /^T[1234]/i, - wide: /^[1234](º|ª)? trimestre/i -}; -var parseQuarterPatterns$1 = { - any: [/1/i, /2/i, /3/i, /4/i] -}; -var matchMonthPatterns$1 = { - narrow: /^[jfmasond]/i, - abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i, - wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i -}; -var parseMonthPatterns$1 = { - narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], - any: [/^ja/i, /^f/i, /^mar/i, /^ab/i, /^mai/i, /^jun/i, /^jul/i, /^ag/i, /^s/i, /^o/i, /^n/i, /^d/i] -}; -var matchDayPatterns$1 = { - narrow: /^[dstq]/i, - short: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, - abbreviated: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, - wide: /^(domingo|segunda-?\s?feira|terça-?\s?feira|quarta-?\s?feira|quinta-?\s?feira|sexta-?\s?feira|s[áa]bado)/i -}; -var parseDayPatterns$1 = { - narrow: [/^d/i, /^s/i, /^t/i, /^q/i, /^q/i, /^s/i, /^s/i], - any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[áa]/i] -}; -var matchDayPeriodPatterns$1 = { - narrow: /^(a|p|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i, - any: /^([ap]\.?\s?m\.?|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i -}; -var parseDayPeriodPatterns$1 = { - any: { - am: /^a/i, - pm: /^p/i, - midnight: /^meia/i, - noon: /^meio/i, - morning: /manh[ãa]/i, - afternoon: /tarde/i, - evening: /noite/i, - night: /madrugada/i - } -}; -var match$1 = { - ordinalNumber: buildMatchPatternFn({ - matchPattern: matchOrdinalNumberPattern$1, - parsePattern: parseOrdinalNumberPattern$1, - valueCallback: function (value) { - return parseInt(value, 10); - } - }), - era: buildMatchFn({ - matchPatterns: matchEraPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseEraPatterns$1, - defaultParseWidth: 'any' - }), - quarter: buildMatchFn({ - matchPatterns: matchQuarterPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseQuarterPatterns$1, - defaultParseWidth: 'any', - valueCallback: function (index) { - return index + 1; - } - }), - month: buildMatchFn({ - matchPatterns: matchMonthPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseMonthPatterns$1, - defaultParseWidth: 'any' - }), - day: buildMatchFn({ - matchPatterns: matchDayPatterns$1, - defaultMatchWidth: 'wide', - parsePatterns: parseDayPatterns$1, - defaultParseWidth: 'any' - }), - dayPeriod: buildMatchFn({ - matchPatterns: matchDayPeriodPatterns$1, - defaultMatchWidth: 'any', - parsePatterns: parseDayPeriodPatterns$1, - defaultParseWidth: 'any' - }) -}; - -/** - * @type {Locale} - * @category Locales - * @summary Portuguese locale. - * @language Portuguese - * @iso-639-2 por - * @author Dário Freire [@dfreire]{@link https://github.com/dfreire} - * @author Adrián de la Rosa [@adrm]{@link https://github.com/adrm} - */ - -var locale$1 = { - code: 'pt', - formatDistance: formatDistance$1, - formatLong: formatLong$1, - formatRelative: formatRelative$1, - localize: localize$1, - match: match$1, - options: { - weekStartsOn: 1 - /* Monday */ - , - firstWeekContainsDate: 4 - } -}; +function getTimezoneOffsetInMilliseconds(dirtyDate) { + var date = new Date(dirtyDate.getTime()); + var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset()); + date.setSeconds(0, 0); + var hasNegativeUTCOffset = baseTimezoneOffset > 0; + var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? (MILLISECONDS_IN_MINUTE + getDateMillisecondsPart(date)) % MILLISECONDS_IN_MINUTE : getDateMillisecondsPart(date); + return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset; +} +var MINUTES_IN_DAY = 1440; +var MINUTES_IN_ALMOST_TWO_DAYS = 2520; +var MINUTES_IN_MONTH = 43200; +var MINUTES_IN_TWO_MONTHS = 86400; /** - * @name compareAsc + * @name formatDistance * @category Common Helpers - * @summary Compare the two dates and return -1, 0 or 1. + * @summary Return the distance between the given dates in words. * * @description - * Compare the two dates and return 1 if the first date is after the second, - * -1 if the first date is before the second or 0 if dates are equal. + * Return the distance between the given dates in words. + * + * | Distance between dates | Result | + * |-------------------------------------------------------------------|---------------------| + * | 0 ... 30 secs | less than a minute | + * | 30 secs ... 1 min 30 secs | 1 minute | + * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes | + * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour | + * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours | + * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day | + * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days | + * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month | + * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months | + * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months | + * | 1 yr ... 1 yr 3 months | about 1 year | + * | 1 yr 3 months ... 1 yr 9 month s | over 1 year | + * | 1 yr 9 months ... 2 yrs | almost 2 years | + * | N yrs ... N yrs 3 months | about N years | + * | N yrs 3 months ... N yrs 9 months | over N years | + * | N yrs 9 months ... N+1 yrs | almost N+1 years | + * + * With `options.includeSeconds == true`: + * | Distance between dates | Result | + * |------------------------|----------------------| + * | 0 secs ... 5 secs | less than 5 seconds | + * | 5 secs ... 10 secs | less than 10 seconds | + * | 10 secs ... 20 secs | less than 20 seconds | + * | 20 secs ... 40 secs | half a minute | + * | 40 secs ... 60 secs | less than a minute | + * | 60 secs ... 90 secs | 1 minute | * * ### v2.0.0 breaking changes: * * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). * - * @param {Date|Number} dateLeft - the first date to compare - * @param {Date|Number} dateRight - the second date to compare - * @returns {Number} the result of the comparison - * @throws {TypeError} 2 arguments required + * - The function was renamed from `distanceInWords ` to `formatDistance` + * to make its name consistent with `format` and `formatRelative`. * - * @example - * // Compare 11 February 1987 and 10 July 1989: - * var result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10)) - * //=> -1 + * - The order of arguments is swapped to make the function + * consistent with `differenceIn...` functions. * - * @example - * // Sort the array of dates: - * var result = [ - * new Date(1995, 6, 2), - * new Date(1987, 1, 11), - * new Date(1989, 6, 10) - * ].sort(compareAsc) - * //=> [ - * // Wed Feb 11 1987 00:00:00, - * // Mon Jul 10 1989 00:00:00, - * // Sun Jul 02 1995 00:00:00 - * // ] - */ - -function compareAsc(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var diff = dateLeft.getTime() - dateRight.getTime(); - - if (diff < 0) { - return -1; - } else if (diff > 0) { - return 1; // Return 0 if diff is 0; return NaN if diff is NaN - } else { - return diff; - } -} - -/** - * @name differenceInCalendarMonths - * @category Month Helpers - * @summary Get the number of calendar months between the given dates. + * ```javascript + * // Before v2.0.0 * - * @description - * Get the number of calendar months between the given dates. + * distanceInWords( + * new Date(1986, 3, 4, 10, 32, 0), + * new Date(1986, 3, 4, 11, 32, 0), + * { addSuffix: true } + * ) //=> 'in about 1 hour' * - * ### v2.0.0 breaking changes: + * // v2.0.0 onward * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). + * formatDistance( + * new Date(1986, 3, 4, 11, 32, 0), + * new Date(1986, 3, 4, 10, 32, 0), + * { addSuffix: true } + * ) //=> 'in about 1 hour' + * ``` * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of calendar months + * @param {Date|Number} date - the date + * @param {Date|Number} baseDate - the date to compare with + * @param {Object} [options] - an object with options. + * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed + * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first + * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} + * @returns {String} the distance in words * @throws {TypeError} 2 arguments required + * @throws {RangeError} `date` must not be Invalid Date + * @throws {RangeError} `baseDate` must not be Invalid Date + * @throws {RangeError} `options.locale` must contain `formatDistance` property * * @example - * // How many calendar months are between 31 January 2014 and 1 September 2014? - * var result = differenceInCalendarMonths( - * new Date(2014, 8, 1), - * new Date(2014, 0, 31) + * // What is the distance between 2 July 2014 and 1 January 2015? + * var result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) + * //=> '6 months' + * + * @example + * // What is the distance between 1 January 2015 00:00:15 + * // and 1 January 2015 00:00:00, including seconds? + * var result = formatDistance( + * new Date(2015, 0, 1, 0, 0, 15), + * new Date(2015, 0, 1, 0, 0, 0), + * { includeSeconds: true } * ) - * //=> 8 + * //=> 'less than 20 seconds' + * + * @example + * // What is the distance from 1 January 2016 + * // to 1 January 2015, with a suffix? + * var result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { + * addSuffix: true + * }) + * //=> 'about 1 year ago' + * + * @example + * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto? + * import { eoLocale } from 'date-fns/locale/eo' + * var result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { + * locale: eoLocale + * }) + * //=> 'pli ol 1 jaro' */ -function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) { +function formatDistance$1(dirtyDate, dirtyBaseDate, dirtyOptions) { requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear(); - var monthDiff = dateLeft.getMonth() - dateRight.getMonth(); - return yearDiff * 12 + monthDiff; -} + var options = dirtyOptions || {}; + var locale$1 = options.locale || locale; -/** - * @name differenceInMonths - * @category Month Helpers - * @summary Get the number of full months between the given dates. - * - * @description - * Get the number of full months between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of full months - * @throws {TypeError} 2 arguments required - * - * @example - * // How many full months are between 31 January 2014 and 1 September 2014? - * var result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) - * //=> 7 - */ - -function differenceInMonths(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - var sign = compareAsc(dateLeft, dateRight); - var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight)); - dateLeft.setMonth(dateLeft.getMonth() - sign * difference); // Math.abs(diff in full months - diff in calendar months) === 1 if last calendar month is not full - // If so, result must be decreased by 1 in absolute value + if (!locale$1.formatDistance) { + throw new RangeError('locale must contain formatDistance property'); + } - var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign; - var result = sign * (difference - isLastMonthNotFull); // Prevent negative zero + var comparison = compareAsc(dirtyDate, dirtyBaseDate); - return result === 0 ? 0 : result; -} + if (isNaN(comparison)) { + throw new RangeError('Invalid time value'); + } -/** - * @name differenceInMilliseconds - * @category Millisecond Helpers - * @summary Get the number of milliseconds between the given dates. - * - * @description - * Get the number of milliseconds between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of milliseconds - * @throws {TypeError} 2 arguments required - * - * @example - * // How many milliseconds are between - * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700? - * var result = differenceInMilliseconds( - * new Date(2014, 6, 2, 12, 30, 21, 700), - * new Date(2014, 6, 2, 12, 30, 20, 600) - * ) - * //=> 1100 - */ + var localizeOptions = cloneObject(options); + localizeOptions.addSuffix = Boolean(options.addSuffix); + localizeOptions.comparison = comparison; + var dateLeft; + var dateRight; -function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var dateLeft = toDate(dirtyDateLeft); - var dateRight = toDate(dirtyDateRight); - return dateLeft.getTime() - dateRight.getTime(); -} + if (comparison > 0) { + dateLeft = toDate(dirtyBaseDate); + dateRight = toDate(dirtyDate); + } else { + dateLeft = toDate(dirtyDate); + dateRight = toDate(dirtyBaseDate); + } -/** - * @name differenceInSeconds - * @category Second Helpers - * @summary Get the number of seconds between the given dates. - * - * @description - * Get the number of seconds between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of seconds - * @throws {TypeError} 2 arguments required - * - * @example - * // How many seconds are between - * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000? - * var result = differenceInSeconds( - * new Date(2014, 6, 2, 12, 30, 20, 0), - * new Date(2014, 6, 2, 12, 30, 7, 999) - * ) - * //=> 12 - */ + var seconds = differenceInSeconds(dateRight, dateLeft); + var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; + var minutes = Math.round((seconds - offsetInSeconds) / 60); + var months; // 0 up to 2 mins -function differenceInSeconds(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000; - return diff > 0 ? Math.floor(diff) : Math.ceil(diff); -} + if (minutes < 2) { + if (options.includeSeconds) { + if (seconds < 5) { + return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); + } else if (seconds < 10) { + return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); + } else if (seconds < 20) { + return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); + } else if (seconds < 40) { + return locale$1.formatDistance('halfAMinute', null, localizeOptions); + } else if (seconds < 60) { + return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); + } else { + return locale$1.formatDistance('xMinutes', 1, localizeOptions); + } + } else { + if (minutes === 0) { + return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); + } else { + return locale$1.formatDistance('xMinutes', minutes, localizeOptions); + } + } // 2 mins up to 0.75 hrs -function assign(target, dirtyObject) { - if (target == null) { - throw new TypeError('assign requires that input parameter not be null or undefined'); + } else if (minutes < 45) { + return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs + } else if (minutes < 90) { + return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs + } else if (minutes < MINUTES_IN_DAY) { + var hours = Math.round(minutes / 60); + return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days + } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { + return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days + } else if (minutes < MINUTES_IN_MONTH) { + var days = Math.round(minutes / MINUTES_IN_DAY); + return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months + } else if (minutes < MINUTES_IN_TWO_MONTHS) { + months = Math.round(minutes / MINUTES_IN_MONTH); + return locale$1.formatDistance('aboutXMonths', months, localizeOptions); } - dirtyObject = dirtyObject || {}; + months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months - for (var property in dirtyObject) { - if (dirtyObject.hasOwnProperty(property)) { - target[property] = dirtyObject[property]; + if (months < 12) { + var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); + return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date + } else { + var monthsSinceStartOfYear = months % 12; + var years = Math.floor(months / 12); // N years up to 1 years 3 months + + if (monthsSinceStartOfYear < 3) { + return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months + } else if (monthsSinceStartOfYear < 9) { + return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months + } else { + return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); } } - - return target; } -function cloneObject(dirtyObject) { - return assign({}, dirtyObject); -} +function toInteger(dirtyNumber) { + if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) { + return NaN; + } -var MILLISECONDS_IN_MINUTE = 60000; + var number = Number(dirtyNumber); -function getDateMillisecondsPart(date) { - return date.getTime() % MILLISECONDS_IN_MINUTE; + if (isNaN(number)) { + return number; + } + + return number < 0 ? Math.ceil(number) : Math.floor(number); } -/** - * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds. - * They usually appear for dates that denote time before the timezones were introduced - * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891 - * and GMT+01:00:00 after that date) - * - * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above, - * which would lead to incorrect calculations. - * - * This function returns the timezone offset in milliseconds that takes seconds in account. - */ +// See issue: https://github.com/date-fns/date-fns/issues/376 -function getTimezoneOffsetInMilliseconds(dirtyDate) { - var date = new Date(dirtyDate.getTime()); - var baseTimezoneOffset = Math.ceil(date.getTimezoneOffset()); - date.setSeconds(0, 0); - var hasNegativeUTCOffset = baseTimezoneOffset > 0; - var millisecondsPartOfTimezoneOffset = hasNegativeUTCOffset ? (MILLISECONDS_IN_MINUTE + getDateMillisecondsPart(date)) % MILLISECONDS_IN_MINUTE : getDateMillisecondsPart(date); - return baseTimezoneOffset * MILLISECONDS_IN_MINUTE + millisecondsPartOfTimezoneOffset; +function startOfUTCWeek(dirtyDate, dirtyOptions) { + requiredArgs(1, arguments); + var options = dirtyOptions || {}; + var locale = options.locale; + var localeWeekStartsOn = locale && locale.options && locale.options.weekStartsOn; + var defaultWeekStartsOn = localeWeekStartsOn == null ? 0 : toInteger(localeWeekStartsOn); + var weekStartsOn = options.weekStartsOn == null ? defaultWeekStartsOn : toInteger(options.weekStartsOn); // Test if weekStartsOn is between 0 and 6 _and_ is not NaN + + if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) { + throw new RangeError('weekStartsOn must be between 0 and 6 inclusively'); + } + + var date = toDate(dirtyDate); + var day = date.getUTCDay(); + var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn; + date.setUTCDate(date.getUTCDate() - diff); + date.setUTCHours(0, 0, 0, 0); + return date; } -var MINUTES_IN_DAY = 1440; -var MINUTES_IN_ALMOST_TWO_DAYS = 2520; -var MINUTES_IN_MONTH = 43200; -var MINUTES_IN_TWO_MONTHS = 86400; -/** - * @name formatDistance - * @category Common Helpers - * @summary Return the distance between the given dates in words. - * - * @description - * Return the distance between the given dates in words. - * - * | Distance between dates | Result | - * |-------------------------------------------------------------------|---------------------| - * | 0 ... 30 secs | less than a minute | - * | 30 secs ... 1 min 30 secs | 1 minute | - * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes | - * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour | - * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours | - * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day | - * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days | - * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month | - * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months | - * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months | - * | 1 yr ... 1 yr 3 months | about 1 year | - * | 1 yr 3 months ... 1 yr 9 month s | over 1 year | - * | 1 yr 9 months ... 2 yrs | almost 2 years | - * | N yrs ... N yrs 3 months | about N years | - * | N yrs 3 months ... N yrs 9 months | over N years | - * | N yrs 9 months ... N+1 yrs | almost N+1 years | - * - * With `options.includeSeconds == true`: - * | Distance between dates | Result | - * |------------------------|----------------------| - * | 0 secs ... 5 secs | less than 5 seconds | - * | 5 secs ... 10 secs | less than 10 seconds | - * | 10 secs ... 20 secs | less than 20 seconds | - * | 20 secs ... 40 secs | half a minute | - * | 40 secs ... 60 secs | less than a minute | - * | 60 secs ... 90 secs | 1 minute | - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * - The function was renamed from `distanceInWords ` to `formatDistance` - * to make its name consistent with `format` and `formatRelative`. - * - * - The order of arguments is swapped to make the function - * consistent with `differenceIn...` functions. - * - * ```javascript - * // Before v2.0.0 - * - * distanceInWords( - * new Date(1986, 3, 4, 10, 32, 0), - * new Date(1986, 3, 4, 11, 32, 0), - * { addSuffix: true } - * ) //=> 'in about 1 hour' - * - * // v2.0.0 onward - * - * formatDistance( - * new Date(1986, 3, 4, 11, 32, 0), - * new Date(1986, 3, 4, 10, 32, 0), - * { addSuffix: true } - * ) //=> 'in about 1 hour' - * ``` - * - * @param {Date|Number} date - the date - * @param {Date|Number} baseDate - the date to compare with - * @param {Object} [options] - an object with options. - * @param {Boolean} [options.includeSeconds=false] - distances less than a minute are more detailed - * @param {Boolean} [options.addSuffix=false] - result indicates if the second date is earlier or later than the first - * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} - * @returns {String} the distance in words - * @throws {TypeError} 2 arguments required - * @throws {RangeError} `date` must not be Invalid Date - * @throws {RangeError} `baseDate` must not be Invalid Date - * @throws {RangeError} `options.locale` must contain `formatDistance` property - * - * @example - * // What is the distance between 2 July 2014 and 1 January 2015? - * var result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1)) - * //=> '6 months' - * - * @example - * // What is the distance between 1 January 2015 00:00:15 - * // and 1 January 2015 00:00:00, including seconds? - * var result = formatDistance( - * new Date(2015, 0, 1, 0, 0, 15), - * new Date(2015, 0, 1, 0, 0, 0), - * { includeSeconds: true } - * ) - * //=> 'less than 20 seconds' - * - * @example - * // What is the distance from 1 January 2016 - * // to 1 January 2015, with a suffix? - * var result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), { - * addSuffix: true - * }) - * //=> 'about 1 year ago' - * - * @example - * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto? - * import { eoLocale } from 'date-fns/locale/eo' - * var result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), { - * locale: eoLocale - * }) - * //=> 'pli ol 1 jaro' - */ +var formatDistanceLocale$1 = { + lessThanXSeconds: { + one: 'menos de um segundo', + other: 'menos de {{count}} segundos' + }, + xSeconds: { + one: '1 segundo', + other: '{{count}} segundos' + }, + halfAMinute: 'meio minuto', + lessThanXMinutes: { + one: 'menos de um minuto', + other: 'menos de {{count}} minutos' + }, + xMinutes: { + one: '1 minuto', + other: '{{count}} minutos' + }, + aboutXHours: { + one: 'aproximadamente 1 hora', + other: 'aproximadamente {{count}} horas' + }, + xHours: { + one: '1 hora', + other: '{{count}} horas' + }, + xDays: { + one: '1 dia', + other: '{{count}} dias' + }, + aboutXWeeks: { + one: 'aproximadamente 1 mês', + // TODO + other: 'aproximadamente {{count}} meses' // TODO -function formatDistance$2(dirtyDate, dirtyBaseDate, dirtyOptions) { - requiredArgs(2, arguments); - var options = dirtyOptions || {}; - var locale$1 = options.locale || locale; + }, + xWeeks: { + one: '1 mês', + // TODO + other: '{{count}} meses' // TODO - if (!locale$1.formatDistance) { - throw new RangeError('locale must contain formatDistance property'); + }, + aboutXMonths: { + one: 'aproximadamente 1 mês', + other: 'aproximadamente {{count}} meses' + }, + xMonths: { + one: '1 mês', + other: '{{count}} meses' + }, + aboutXYears: { + one: 'aproximadamente 1 ano', + other: 'aproximadamente {{count}} anos' + }, + xYears: { + one: '1 ano', + other: '{{count}} anos' + }, + overXYears: { + one: 'mais de 1 ano', + other: 'mais de {{count}} anos' + }, + almostXYears: { + one: 'quase 1 ano', + other: 'quase {{count}} anos' } +}; +function formatDistance$2(token, count, options) { + options = options || {}; + var result; - var comparison = compareAsc(dirtyDate, dirtyBaseDate); + if (typeof formatDistanceLocale$1[token] === 'string') { + result = formatDistanceLocale$1[token]; + } else if (count === 1) { + result = formatDistanceLocale$1[token].one; + } else { + result = formatDistanceLocale$1[token].other.replace('{{count}}', count); + } - if (isNaN(comparison)) { - throw new RangeError('Invalid time value'); + if (options.addSuffix) { + if (options.comparison > 0) { + return 'daqui a ' + result; + } else { + return 'há ' + result; + } } - var localizeOptions = cloneObject(options); - localizeOptions.addSuffix = Boolean(options.addSuffix); - localizeOptions.comparison = comparison; - var dateLeft; - var dateRight; + return result; +} - if (comparison > 0) { - dateLeft = toDate(dirtyBaseDate); - dateRight = toDate(dirtyDate); - } else { - dateLeft = toDate(dirtyDate); - dateRight = toDate(dirtyBaseDate); +var dateFormats$1 = { + full: "EEEE, d 'de' MMMM 'de' y", + long: "d 'de' MMMM 'de' y", + medium: "d 'de' MMM 'de' y", + short: 'dd/MM/y' +}; +var timeFormats$1 = { + full: 'HH:mm:ss zzzz', + long: 'HH:mm:ss z', + medium: 'HH:mm:ss', + short: 'HH:mm' +}; +var dateTimeFormats$1 = { + full: "{{date}} 'às' {{time}}", + long: "{{date}} 'às' {{time}}", + medium: '{{date}}, {{time}}', + short: '{{date}}, {{time}}' +}; +var formatLong$1 = { + date: buildFormatLongFn({ + formats: dateFormats$1, + defaultWidth: 'full' + }), + time: buildFormatLongFn({ + formats: timeFormats$1, + defaultWidth: 'full' + }), + dateTime: buildFormatLongFn({ + formats: dateTimeFormats$1, + defaultWidth: 'full' + }) +}; + +var formatRelativeLocale$1 = { + lastWeek: "'na última' eeee 'às' p", + yesterday: "'ontem às' p", + today: "'hoje às' p", + tomorrow: "'amanhã às' p", + nextWeek: "eeee 'às' p", + other: 'P' +}; +function formatRelative$1(token, _date, _baseDate, _options) { + return formatRelativeLocale$1[token]; +} + +function ordinalNumber$1(dirtyNumber) { + var number = Number(dirtyNumber); + return number + 'º'; +} + +var eraValues$1 = { + narrow: ['aC', 'dC'], + abbreviated: ['a.C.', 'd.C.'], + wide: ['antes de Cristo', 'depois de Cristo'] +}; +var quarterValues$1 = { + narrow: ['1', '2', '3', '4'], + abbreviated: ['T1', 'T2', 'T3', 'T4'], + wide: ['1º trimestre', '2º trimestre', '3º trimestre', '4º trimestre'] +}; +var monthValues$1 = { + narrow: ['j', 'f', 'm', 'a', 'm', 'j', 'j', 'a', 's', 'o', 'n', 'd'], + abbreviated: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'], + wide: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'] +}; +var dayValues$1 = { + narrow: ['d', 's', 't', 'q', 'q', 's', 's'], + short: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], + abbreviated: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], + wide: ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'] +}; +var dayPeriodValues$1 = { + narrow: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + }, + abbreviated: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + }, + wide: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'manhã', + afternoon: 'tarde', + evening: 'noite', + night: 'madrugada' + } +}; +var formattingDayPeriodValues$1 = { + narrow: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' + }, + abbreviated: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' + }, + wide: { + am: 'AM', + pm: 'PM', + midnight: 'meia-noite', + noon: 'meio-dia', + morning: 'da manhã', + afternoon: 'da tarde', + evening: 'da noite', + night: 'da madrugada' } +}; +var localize$1 = { + ordinalNumber: ordinalNumber$1, + era: buildLocalizeFn({ + values: eraValues$1, + defaultWidth: 'wide' + }), + quarter: buildLocalizeFn({ + values: quarterValues$1, + defaultWidth: 'wide', + argumentCallback: function (quarter) { + return Number(quarter) - 1; + } + }), + month: buildLocalizeFn({ + values: monthValues$1, + defaultWidth: 'wide' + }), + day: buildLocalizeFn({ + values: dayValues$1, + defaultWidth: 'wide' + }), + dayPeriod: buildLocalizeFn({ + values: dayPeriodValues$1, + defaultWidth: 'wide', + formattingValues: formattingDayPeriodValues$1, + defaultFormattingWidth: 'wide' + }) +}; - var seconds = differenceInSeconds(dateRight, dateLeft); - var offsetInSeconds = (getTimezoneOffsetInMilliseconds(dateRight) - getTimezoneOffsetInMilliseconds(dateLeft)) / 1000; - var minutes = Math.round((seconds - offsetInSeconds) / 60); - var months; // 0 up to 2 mins - - if (minutes < 2) { - if (options.includeSeconds) { - if (seconds < 5) { - return locale$1.formatDistance('lessThanXSeconds', 5, localizeOptions); - } else if (seconds < 10) { - return locale$1.formatDistance('lessThanXSeconds', 10, localizeOptions); - } else if (seconds < 20) { - return locale$1.formatDistance('lessThanXSeconds', 20, localizeOptions); - } else if (seconds < 40) { - return locale$1.formatDistance('halfAMinute', null, localizeOptions); - } else if (seconds < 60) { - return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); - } else { - return locale$1.formatDistance('xMinutes', 1, localizeOptions); - } - } else { - if (minutes === 0) { - return locale$1.formatDistance('lessThanXMinutes', 1, localizeOptions); - } else { - return locale$1.formatDistance('xMinutes', minutes, localizeOptions); - } - } // 2 mins up to 0.75 hrs - - } else if (minutes < 45) { - return locale$1.formatDistance('xMinutes', minutes, localizeOptions); // 0.75 hrs up to 1.5 hrs - } else if (minutes < 90) { - return locale$1.formatDistance('aboutXHours', 1, localizeOptions); // 1.5 hrs up to 24 hrs - } else if (minutes < MINUTES_IN_DAY) { - var hours = Math.round(minutes / 60); - return locale$1.formatDistance('aboutXHours', hours, localizeOptions); // 1 day up to 1.75 days - } else if (minutes < MINUTES_IN_ALMOST_TWO_DAYS) { - return locale$1.formatDistance('xDays', 1, localizeOptions); // 1.75 days up to 30 days - } else if (minutes < MINUTES_IN_MONTH) { - var days = Math.round(minutes / MINUTES_IN_DAY); - return locale$1.formatDistance('xDays', days, localizeOptions); // 1 month up to 2 months - } else if (minutes < MINUTES_IN_TWO_MONTHS) { - months = Math.round(minutes / MINUTES_IN_MONTH); - return locale$1.formatDistance('aboutXMonths', months, localizeOptions); +var matchOrdinalNumberPattern$1 = /^(\d+)(º|ª)?/i; +var parseOrdinalNumberPattern$1 = /\d+/i; +var matchEraPatterns$1 = { + narrow: /^(ac|dc|a|d)/i, + abbreviated: /^(a\.?\s?c\.?|a\.?\s?e\.?\s?c\.?|d\.?\s?c\.?|e\.?\s?c\.?)/i, + wide: /^(antes de cristo|antes da era comum|depois de cristo|era comum)/i +}; +var parseEraPatterns$1 = { + any: [/^ac/i, /^dc/i], + wide: [/^(antes de cristo|antes da era comum)/i, /^(depois de cristo|era comum)/i] +}; +var matchQuarterPatterns$1 = { + narrow: /^[1234]/i, + abbreviated: /^T[1234]/i, + wide: /^[1234](º|ª)? trimestre/i +}; +var parseQuarterPatterns$1 = { + any: [/1/i, /2/i, /3/i, /4/i] +}; +var matchMonthPatterns$1 = { + narrow: /^[jfmasond]/i, + abbreviated: /^(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez)/i, + wide: /^(janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro)/i +}; +var parseMonthPatterns$1 = { + narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i], + any: [/^ja/i, /^f/i, /^mar/i, /^ab/i, /^mai/i, /^jun/i, /^jul/i, /^ag/i, /^s/i, /^o/i, /^n/i, /^d/i] +}; +var matchDayPatterns$1 = { + narrow: /^[dstq]/i, + short: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, + abbreviated: /^(dom|seg|ter|qua|qui|sex|s[áa]b)/i, + wide: /^(domingo|segunda-?\s?feira|terça-?\s?feira|quarta-?\s?feira|quinta-?\s?feira|sexta-?\s?feira|s[áa]bado)/i +}; +var parseDayPatterns$1 = { + narrow: [/^d/i, /^s/i, /^t/i, /^q/i, /^q/i, /^s/i, /^s/i], + any: [/^d/i, /^seg/i, /^t/i, /^qua/i, /^qui/i, /^sex/i, /^s[áa]/i] +}; +var matchDayPeriodPatterns$1 = { + narrow: /^(a|p|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i, + any: /^([ap]\.?\s?m\.?|meia-?\s?noite|meio-?\s?dia|(da) (manh[ãa]|tarde|noite|madrugada))/i +}; +var parseDayPeriodPatterns$1 = { + any: { + am: /^a/i, + pm: /^p/i, + midnight: /^meia/i, + noon: /^meio/i, + morning: /manh[ãa]/i, + afternoon: /tarde/i, + evening: /noite/i, + night: /madrugada/i } - - months = differenceInMonths(dateRight, dateLeft); // 2 months up to 12 months - - if (months < 12) { - var nearestMonth = Math.round(minutes / MINUTES_IN_MONTH); - return locale$1.formatDistance('xMonths', nearestMonth, localizeOptions); // 1 year up to max Date - } else { - var monthsSinceStartOfYear = months % 12; - var years = Math.floor(months / 12); // N years up to 1 years 3 months - - if (monthsSinceStartOfYear < 3) { - return locale$1.formatDistance('aboutXYears', years, localizeOptions); // N years 3 months up to N years 9 months - } else if (monthsSinceStartOfYear < 9) { - return locale$1.formatDistance('overXYears', years, localizeOptions); // N years 9 months up to N year 12 months - } else { - return locale$1.formatDistance('almostXYears', years + 1, localizeOptions); +}; +var match$1 = { + ordinalNumber: buildMatchPatternFn({ + matchPattern: matchOrdinalNumberPattern$1, + parsePattern: parseOrdinalNumberPattern$1, + valueCallback: function (value) { + return parseInt(value, 10); } - } -} + }), + era: buildMatchFn({ + matchPatterns: matchEraPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseEraPatterns$1, + defaultParseWidth: 'any' + }), + quarter: buildMatchFn({ + matchPatterns: matchQuarterPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseQuarterPatterns$1, + defaultParseWidth: 'any', + valueCallback: function (index) { + return index + 1; + } + }), + month: buildMatchFn({ + matchPatterns: matchMonthPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseMonthPatterns$1, + defaultParseWidth: 'any' + }), + day: buildMatchFn({ + matchPatterns: matchDayPatterns$1, + defaultMatchWidth: 'wide', + parsePatterns: parseDayPatterns$1, + defaultParseWidth: 'any' + }), + dayPeriod: buildMatchFn({ + matchPatterns: matchDayPeriodPatterns$1, + defaultMatchWidth: 'any', + parsePatterns: parseDayPeriodPatterns$1, + defaultParseWidth: 'any' + }) +}; -var MILLISECONDS_IN_HOUR = 3600000; /** - * @name differenceInHours - * @category Hour Helpers - * @summary Get the number of hours between the given dates. - * - * @description - * Get the number of hours between the given dates. - * - * ### v2.0.0 breaking changes: - * - * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes). - * - * @param {Date|Number} dateLeft - the later date - * @param {Date|Number} dateRight - the earlier date - * @returns {Number} the number of hours - * @throws {TypeError} 2 arguments required - * - * @example - * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00? - * var result = differenceInHours( - * new Date(2014, 6, 2, 19, 0), - * new Date(2014, 6, 2, 6, 50) - * ) - * //=> 12 + * @type {Locale} + * @category Locales + * @summary Portuguese locale. + * @language Portuguese + * @iso-639-2 por + * @author Dário Freire [@dfreire]{@link https://github.com/dfreire} + * @author Adrián de la Rosa [@adrm]{@link https://github.com/adrm} */ -function differenceInHours(dirtyDateLeft, dirtyDateRight) { - requiredArgs(2, arguments); - var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_HOUR; - return diff > 0 ? Math.floor(diff) : Math.ceil(diff); -} +var locale$1 = { + code: 'pt', + formatDistance: formatDistance$2, + formatLong: formatLong$1, + formatRelative: formatRelative$1, + localize: localize$1, + match: match$1, + options: { + weekStartsOn: 1 + /* Monday */ + , + firstWeekContainsDate: 4 + } +}; /** * @name isValid @@ -3494,7 +3510,7 @@ function cleanEscapedString(input) { var datePtBrFull = function datePtBrFull(date) { if (!date) return false; - var d = date.replace("T", " "); + var d = date.replace('T', ' '); var _y = d.split('-'); @@ -3505,12 +3521,12 @@ var datePtBrFull = function datePtBrFull(date) { var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]); if (!(_date instanceof Date)) return false; - return "".concat(format(_date, "dd/MM/yyyy"), " \xE0s ").concat(format(_date, "HH:mm")); + return "".concat(format(_date, 'dd/MM/yyyy'), " \xE0s ").concat(format(_date, 'HH:mm')); }; var dateDistance = function dateDistance(date, limit) { if (!date) return false; - var d = date.replace("T", " "); + var d = date.replace('T', ' '); var _y = d.split('-'); @@ -3522,16 +3538,16 @@ var dateDistance = function dateDistance(date, limit) { var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime(); - var distanteInWords = formatDistance$2(_now, _date, { + var distanteInWords = formatDistance$1(_now, _date, { locale: locale$1 }); var diffHours = differenceInHours(_now, _date, { locale: locale$1 }); if (diffHours > limit) return datePtBrFull(date); - var replaces = [["aproximadamente ", ""]]; + var replaces = [['aproximadamente ', '']]; var date_string = distanteInWords; - lodash.map(replaces, function (r, k) { + lodash.map(replaces, function (r) { date_string = date_string.replace(r[0], r[1]); }); return "H\xE1 ".concat(date_string); @@ -3542,6 +3558,8 @@ var utils = { datePtBrFull: datePtBrFull }; +var _PropTypes$shape; + var Teaser = function Teaser(_ref) { var content = _ref.content, datePublished = _ref.datePublished, @@ -3597,8 +3615,8 @@ var Teaser = function Teaser(_ref) { }; if (!content['time-published']) return false; var dateValue = !datePublished && content['time-modifiedDate'] ? utils.dateDistance(content['time-modifiedDate'], 2880) : utils.datePtBrFull(content['time-published']); - dateValue = datePublished ? "Publicado em ".concat(dateValue) : dateValue.startsWith("Há") ? dateValue.replace("H\xE1", "Atualizado h\xE1") : "Atualizado em ".concat(dateValue); - var path_split = path.split(":8080"); + dateValue = datePublished ? "Publicado em ".concat(dateValue) : dateValue.startsWith('Há') ? dateValue.replace('Há', 'Atualizado há') : "Atualizado em ".concat(dateValue); + var path_split = path.split(':8080'); var url_rewrite = path_split.length > 1 ? "".concat(domain).concat(path_split[1]) : path; var TeaserImage = function TeaserImage() { @@ -3629,19 +3647,20 @@ var Teaser = function Teaser(_ref) { }; Teaser.propTypes = { - content: PropTypes.shape(_defineProperty({ + content: PropTypes.shape((_PropTypes$shape = { image: PropTypes.object, name: PropTypes.string, path: PropTypes.string, subtitle: PropTypes.string, subject: PropTypes.string - }, 'time-published', PropTypes.string)), + }, _defineProperty(_PropTypes$shape, 'time-published', PropTypes.string), _defineProperty(_PropTypes$shape, 'time-modified', PropTypes.string), _PropTypes$shape)), datePublished: PropTypes.bool, domain: PropTypes.string, hasImageTop: PropTypes.bool, hasSubtitle: PropTypes.bool, hasDate: PropTypes.bool, hasSubjectFilled: PropTypes.bool, + lazy: PropTypes.func, status: PropTypes.shape({ loading: PropTypes.bool, error: PropTypes.bool @@ -3654,22 +3673,6 @@ Teaser.defaultProps = { hasDate: true }; -var SectionTitle = function SectionTitle(_ref) { - var custom = _ref.custom, - name = _ref.name; - return /*#__PURE__*/React.createElement(Block, { - custom: "section-title-block", - mb: "3" - }, /*#__PURE__*/React.createElement(Typography, { - custom: "section-title ".concat(custom) - }, name)); -}; - -SectionTitle.propTypes = { - custom: PropTypes.string, - name: PropTypes.string -}; - var Columnists = function Columnists(props) { var content = props.content, domain = props.domain, @@ -3684,7 +3687,7 @@ var Columnists = function Columnists(props) { mb: '3' } }; - return /*#__PURE__*/React.createElement(React.Fragment, null, title && title !== "" && /*#__PURE__*/React.createElement(SectionTitle, { + return /*#__PURE__*/React.createElement(React.Fragment, null, title && title !== '' && /*#__PURE__*/React.createElement(SectionTitle, { name: title }), /*#__PURE__*/React.createElement(Block, propsTemplate, lodash.map(content['items'], function (item, key) { return /*#__PURE__*/React.createElement(Teaser, { @@ -3796,7 +3799,7 @@ var GridNews = function GridNews(props) { propsTemplate.custom = 'templates-newsgrid four'; } - return /*#__PURE__*/React.createElement(React.Fragment, null, title && title !== "" && /*#__PURE__*/React.createElement(SectionTitle, { + return /*#__PURE__*/React.createElement(React.Fragment, null, title && title !== '' && /*#__PURE__*/React.createElement(SectionTitle, { name: title }), /*#__PURE__*/React.createElement(Block, propsTemplate, lodash.map(items, function (item, key) { return /*#__PURE__*/React.createElement(Teaser, { @@ -3917,7 +3920,7 @@ var Latest = function Latest(_ref) { }; return /*#__PURE__*/React.createElement(Block, propsContainer, /*#__PURE__*/React.createElement(Block, propsPageLeft, Title && /*#__PURE__*/React.createElement(Title, null), /*#__PURE__*/React.createElement(Block, { custom: "latest-news" - }, lodash.map(content["items-latest"], function (item, key) { + }, lodash.map(content['items-latest'], function (item, key) { return /*#__PURE__*/React.createElement(Teaser, { content: item, datePublished: true, @@ -3931,7 +3934,7 @@ var Latest = function Latest(_ref) { })), ReadMore && /*#__PURE__*/React.createElement(ReadMore, null)), /*#__PURE__*/React.createElement(Block, propsPageRight, /*#__PURE__*/React.createElement(SectionTitle, { name: "MAIS LIDAS" }), /*#__PURE__*/React.createElement(MostRead, { - content: content["items-mostread"], + content: content['items-mostread'], status: status }))); }; @@ -3975,6 +3978,7 @@ var Related = function Related(_ref) { }; Related.propTypes = { + domain: PropTypes.string, items: PropTypes.array, lazy: PropTypes.func, ReadMore: PropTypes.func, @@ -3997,12 +4001,12 @@ var Subjects = function Subjects(props) { align: 'row between' } }; - return /*#__PURE__*/React.createElement(React.Fragment, null, title && title !== "" && /*#__PURE__*/React.createElement(SectionTitle, { + return /*#__PURE__*/React.createElement(React.Fragment, null, title && title !== '' && /*#__PURE__*/React.createElement(SectionTitle, { name: title }), /*#__PURE__*/React.createElement(Block, propsTemplate, /*#__PURE__*/React.createElement(Block, { - custom: "col left ".concat(content["style-left"]) + custom: "col left ".concat(content['style-left']) }, /*#__PURE__*/React.createElement(SectionTitle, { - name: content["title-left"] + name: content['title-left'] }), lodash.map(content['items-left'], function (item, key) { return /*#__PURE__*/React.createElement(Teaser, { content: item, @@ -4012,9 +4016,9 @@ var Subjects = function Subjects(props) { status: status }); }), ReadMore && /*#__PURE__*/React.createElement(ReadMore, null)), /*#__PURE__*/React.createElement(Block, { - custom: "col center ".concat(content["style-center"]) + custom: "col center ".concat(content['style-center']) }, /*#__PURE__*/React.createElement(SectionTitle, { - name: content["title-center"] + name: content['title-center'] }), lodash.map(content['items-center'], function (item, key) { return /*#__PURE__*/React.createElement(Teaser, { content: item, @@ -4024,9 +4028,9 @@ var Subjects = function Subjects(props) { status: status }); }), ReadMore && /*#__PURE__*/React.createElement(ReadMore, null)), /*#__PURE__*/React.createElement(Block, { - custom: "col right ".concat(content["style-right"]) + custom: "col right ".concat(content['style-right']) }, /*#__PURE__*/React.createElement(SectionTitle, { - name: content["title-right"] + name: content['title-right'] }), lodash.map(content['items-right'], function (item, key) { return /*#__PURE__*/React.createElement(Teaser, { content: item,