-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug data #154
Bug data #154
Changes from 11 commits
f6faf62
133b46a
7a1bc56
d68e22d
1930424
b5b01a5
d810c4e
b3c5ef5
fb51d98
f3bab4b
6cfaa06
ab772d0
bbf3b36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,15 +2,14 @@ import React, { useEffect, useState } from 'react' | |||||
import { NavLink } from 'react-router-dom' | ||||||
import 'swiper/css' | ||||||
import 'swiper/css/navigation' | ||||||
import { FreeMode, Navigation, Pagination } from 'swiper/modules' | ||||||
import { Navigation, Pagination } from 'swiper/modules' | ||||||
import { cms } from '../../client' | ||||||
import { Swiper, SwiperSlide } from 'swiper/react' | ||||||
import { CssCarrosselGlobal } from '../global-styles' | ||||||
import EventsComponent from './styled.js' | ||||||
|
||||||
const Events = () => { | ||||||
const [attributesEvents, setAttributesEvents] = useState([]) | ||||||
const urlCms = process.env.REACT_APP_URL_CMS | ||||||
useEffect(() => { | ||||||
cms.get('api/events/?populate=foto_divulgacao').then((response) => { | ||||||
const { data } = response.data | ||||||
|
@@ -19,21 +18,22 @@ const Events = () => { | |||||
return { | ||||||
id: data.id, | ||||||
name: data.attributes.nome, | ||||||
date: new Date(data.attributes.data_inicio), | ||||||
date: new Date(`${data.attributes.data_inicio}T00:00:00-0300`), | ||||||
image_url: data.attributes.foto_divulgacao.data.attributes.url, | ||||||
time_start: data.attributes.horario_inicio, | ||||||
time_end: data.attributes.horario_fim, | ||||||
type: data.attributes.tipo, | ||||||
location: data.attributes.local, | ||||||
price: data.attributes.preco, | ||||||
description: data.attributes.descricao | ||||||
description: data.attributes.descricao, | ||||||
} | ||||||
}) | ||||||
const eventsOrdered = events.filter(event => event !== null).sort((a, b) => a.date - b.date) | ||||||
setAttributesEvents(eventsOrdered) | ||||||
} | ||||||
}) | ||||||
}, []) | ||||||
|
||||||
return ( | ||||||
|
||||||
<CssCarrosselGlobal style={{ background: '#FAFAFA' }}> | ||||||
|
@@ -65,7 +65,7 @@ const Events = () => { | |||||
<img className="img" src={events.image_url} /> | ||||||
</div> | ||||||
<div> | ||||||
<p className="date">{events.date.toLocaleDateString('pt-BR', { Timezone: 'UTF' })}</p> | ||||||
<p className="date">{events.date.toLocaleDateString('pt-BR', { Timezone: 'UTC' })}</p> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<h3 className="title">{events.name}</h3> | ||||||
</div> | ||||||
<EventsComponent> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,8 @@ const endsOnSameDay = (workshop) => | |
export const formatWorkshopDates = (workshop) => { | ||
if (workshop && workshop.attributes && workshop.attributes.data_inicio && workshop.attributes.data_fim) { | ||
return endsOnSameDay(workshop) | ||
? formatDate(new Date(workshop.attributes?.data_inicio)) | ||
: `${formatDate(new Date(workshop.attributes?.data_inicio))} | ||
> ${formatDate(new Date(workshop.attributes?.data_fim))}` | ||
? formatDate(new Date(`${workshop.attributes?.data_inicio}T00:00:00-0300`)) | ||
: `${formatDate(new Date(`${workshop.attributes?.data_inicio}T00:00:00-0300`))} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Essa correção está se repetindo em tudo que é canto. Não seria melhor deixar a função |
||
> ${formatDate(new Date(`${workshop.attributes?.data_fim}T00:00:00-0300`))}` | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Porque estamos adicionando horário e offset de timezone? Qual é o bug que ocorre quando esta informação não está presente?
O que acontecerá quando o Brasil entrar em horário de verão e o offset mudar para
-0200
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preciso entender melhor o problema que está ocorrendo, mas tenho a impressão de que concatenar um offset de timezone não será a solução.
Acho que deveríamos continuar lidando com datas em UTC e só mudarmos o offset na hora de exibir o valor da data. Já fazemos isso no código desse componente, só estamos fazendo errado hehehe:
Mais para baixo, fazemos:
Quando poderíamos fazer:
Isso vai ajustar a data para o horário de Brasília e já vai dar conta de converter corretamente horário de verão. Já havia falado sobre isso em uma PR bem antiga.