Skip to content
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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/events-carrosel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`),
Copy link
Member

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?

Copy link
Member

@yrachid yrachid Feb 7, 2024

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:

events.date.toLocaleDateString('pt-BR', { Timezone: 'UTC' }

Quando poderíamos fazer:

events.date.toLocaleDateString('pt-BR', { timeZone: 'America/Sao_Paulo' }

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.

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' }}>
Expand Down Expand Up @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p className="date">{events.date.toLocaleDateString('pt-BR', { Timezone: 'UTC' })}</p>
<p className="date">{events.date.toLocaleDateString('pt-BR', { timeZone: 'UTC' })}</p>

<h3 className="title">{events.name}</h3>
</div>
<EventsComponent>
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/format-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`))}
Copy link
Member

Choose a reason for hiding this comment

The 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 fazer isso internamente? Continuamos passando a string de data para ela e ela concatena a informação faltante, assim não precisamos repetir a mesma coisa toda vez que a função for chamada.

> ${formatDate(new Date(`${workshop.attributes?.data_fim}T00:00:00-0300`))}`
}
}
4 changes: 2 additions & 2 deletions src/pages/therapies-description/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export const DetailsTherapies = () => {
<FontAwesomeIcon icon={faCalendarDays} size="lg" />{' '}
<p>{`
${handleDate(
new Date(therapies.attributes?.data_inicio)
new Date(`${therapies.attributes?.data_inicio}T00:00:00-0300`)
)} •
${therapies.attributes?.horario_inicio} >
${handleDate(new Date(therapies.attributes?.data_fim))}
${handleDate(new Date(`${therapies.attributes?.data_fim}T00:00:00-0300`))}
• ${therapies.attributes?.horario_fim}
`}</p>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/workshop-description/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export const WorkshopDetails = () => {
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))}
até ${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`))}
até ${formatDate(new Date(`${workshop.attributes?.data_fim}T00:00:00-0300`))}`
}
}

Expand Down
Loading
Loading