From 90d7a708e42f0c150e9348d3b62105b63dd19a17 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 26 Aug 2020 01:07:32 -0300 Subject: [PATCH] Corrigido o problema da data --- components/Teasers/index.js | 2 +- components/Util/dateDistance.js | 13 +++++++++---- components/Util/datePtBrFull.js | 12 +++++++++++- index.js | 27 +++++++++++++++++++++++---- teasers.js | 27 +++++++++++++++++++++++---- templates.js | 27 +++++++++++++++++++++++---- 6 files changed, 90 insertions(+), 18 deletions(-) diff --git a/components/Teasers/index.js b/components/Teasers/index.js index b45221b9e..13173c989 100644 --- a/components/Teasers/index.js +++ b/components/Teasers/index.js @@ -17,7 +17,7 @@ const Teaser = ({content, datePublished, domain, hasImageTop, hasSubjectFilled, const propsDate = {custom: 'teaser-date',w: '100p'} const propsSubject = {custom: 'teaser-subject',mb: '1'} const propsTitle = {custom: 'teaser-title'} - + let dateValue = !datePublished && content['time-modifiedDate'] ? utils.dateDistance(content['time-modifiedDate'], 2880) : diff --git a/components/Util/dateDistance.js b/components/Util/dateDistance.js index ecc3236ea..a0ee82709 100644 --- a/components/Util/dateDistance.js +++ b/components/Util/dateDistance.js @@ -6,10 +6,15 @@ import datePtBrFull from './datePtBrFull' const dateDistance = (date, limit) => { - const _now = new Date() - const _date = new Date(date) - - const distanteInWords = formatDistance(_date, _now, {locale: pt}) + if(!date) return false + let d = date.replace("T", " ") + let _y = d.split('-') + let _d = _y[2].split(' ') + let _t = _d.length > 1 ? _d[1].split(':') : [0, 0] + let _now = new Date().getTime() + let _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime() + + const distanteInWords = formatDistance(_now, _date, {locale: pt}) const diffHours = differenceInHours(_now, _date, {locale: pt}) if(diffHours > limit) diff --git a/components/Util/datePtBrFull.js b/components/Util/datePtBrFull.js index c8583a38b..632ebb298 100644 --- a/components/Util/datePtBrFull.js +++ b/components/Util/datePtBrFull.js @@ -1,7 +1,17 @@ import format from 'date-fns/format' const datePtBrFull = (date) => { - const _date = new Date(date) + + if(!date) return false + let d = date.replace("T", " ") + let _y = d.split('-') + let _d = _y[2].split(' ') + let _t = _d.length > 1 ? _d[1].split(':') : [0, 0] + let _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]) + + if(!(_date instanceof Date)) + return false + return `${format(_date, "dd/MM/yyyy")} às ${format(_date, "HH:mm")}` } export default datePtBrFull \ No newline at end of file diff --git a/index.js b/index.js index 419be5a18..39b6dae54 100644 --- a/index.js +++ b/index.js @@ -4606,17 +4606,36 @@ function cleanEscapedString(input) { } var datePtBrFull = function datePtBrFull(date) { - var _date = new Date(date); + if (!date) return false; + var d = date.replace("T", " "); + var _y = d.split('-'); + + var _d = _y[2].split(' '); + + var _t = _d.length > 1 ? _d[1].split(':') : [0, 0]; + + 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")); }; var dateDistance = function dateDistance(date, limit) { - var _now = new Date(); + if (!date) return false; + var d = date.replace("T", " "); + + var _y = d.split('-'); + + var _d = _y[2].split(' '); + + var _t = _d.length > 1 ? _d[1].split(':') : [0, 0]; + + var _now = new Date().getTime(); - var _date = new Date(date); + var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime(); - var distanteInWords = formatDistance$2(_date, _now, { + var distanteInWords = formatDistance$2(_now, _date, { locale: locale$1 }); var diffHours = differenceInHours(_now, _date, { diff --git a/teasers.js b/teasers.js index dad927958..3301b29bf 100644 --- a/teasers.js +++ b/teasers.js @@ -3443,17 +3443,36 @@ function cleanEscapedString(input) { } var datePtBrFull = function datePtBrFull(date) { - var _date = new Date(date); + if (!date) return false; + var d = date.replace("T", " "); + var _y = d.split('-'); + + var _d = _y[2].split(' '); + + var _t = _d.length > 1 ? _d[1].split(':') : [0, 0]; + + 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")); }; var dateDistance = function dateDistance(date, limit) { - var _now = new Date(); + if (!date) return false; + var d = date.replace("T", " "); + + var _y = d.split('-'); + + var _d = _y[2].split(' '); + + var _t = _d.length > 1 ? _d[1].split(':') : [0, 0]; + + var _now = new Date().getTime(); - var _date = new Date(date); + var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime(); - var distanteInWords = formatDistance$2(_date, _now, { + var distanteInWords = formatDistance$2(_now, _date, { locale: locale$1 }); var diffHours = differenceInHours(_now, _date, { diff --git a/templates.js b/templates.js index 46a389861..3377d5960 100644 --- a/templates.js +++ b/templates.js @@ -3463,17 +3463,36 @@ function cleanEscapedString(input) { } var datePtBrFull = function datePtBrFull(date) { - var _date = new Date(date); + if (!date) return false; + var d = date.replace("T", " "); + var _y = d.split('-'); + + var _d = _y[2].split(' '); + + var _t = _d.length > 1 ? _d[1].split(':') : [0, 0]; + + 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")); }; var dateDistance = function dateDistance(date, limit) { - var _now = new Date(); + if (!date) return false; + var d = date.replace("T", " "); + + var _y = d.split('-'); + + var _d = _y[2].split(' '); + + var _t = _d.length > 1 ? _d[1].split(':') : [0, 0]; + + var _now = new Date().getTime(); - var _date = new Date(date); + var _date = new Date(_y[0], _y[1] - 1, _d[0], _t[0], _t[1]).getTime(); - var distanteInWords = formatDistance$2(_date, _now, { + var distanteInWords = formatDistance$2(_now, _date, { locale: locale$1 }); var diffHours = differenceInHours(_now, _date, {