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

Fix calendar in all timezones #944

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 12 additions & 9 deletions components/as/Calendar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react'
import { ResponsiveCalendar } from '@nivo/calendar'
import { add, compareDesc, startOfToday, startOfYear } from 'date-fns'
import { Flex, theme } from 'ooni-components'
import React, { useState } from 'react'
import styled from 'styled-components'
import { Flex, Box, theme } from 'ooni-components'
import { getRange } from 'utils'

const StyledCalendar = styled.div`
Expand All @@ -27,14 +28,14 @@ const colorLegend = [

const dateRange = (startDate, endDate) => {
if (!startDate || !endDate) return
const start = new Date(new Date(startDate.getFullYear(), 0, 0, 0).setUTCHours(0, 0, 0, 0))
const end = new Date(new Date(endDate).setUTCHours(0, 0, 0, 0))
const date = new Date(start.getTime())
const start = startOfYear(startDate)
const end = startOfToday()
let date = start
const dates = []

while (date <= end) {
while (compareDesc(date, end) >= 0) {
dates.push(new Date(date).toISOString().split('T')[0])
date.setUTCDate(date.getDate() + 1)
date = add(date, { days: 1 })
}
return dates
}
Expand All @@ -58,7 +59,9 @@ const Calendar = React.memo(function Calendar({data}) {
<StyledCalendar>
<ResponsiveCalendar
data={calendarData}
from={`${selectedYear}-01-01`}
// setting from field to Jan 2nd is a weird fix in order
// for the calendar to appear correctly as a single year
from={`${selectedYear}-01-02`}
to={`${selectedYear}-12-31`}
emptyColor={colors.gray1}
colorScale={(value) => findColor(value)}
Expand All @@ -68,7 +71,7 @@ const Calendar = React.memo(function Calendar({data}) {
dayBorderColor="#ffffff"
/>
</StyledCalendar>
<Flex justifyContent='space-between'alignItems='center' mb={60} mt={2}>
<Flex justifyContent='space-between' alignItems='center' mb={60} mt={2}>
<Flex>
{colorLegend.map(item => (
<span
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@nivo/tooltip": "0.80.0",
"@sentry/nextjs": "^7.109.0",
"@tanstack/react-table": "^8.11.6",
"axios": "^1.6.7",
"axios": "^1.7.2",
"buffer-from": "^1.1.2",
"country-util": "^0.2.0",
"date-fns": "^3.2.0",
Expand All @@ -28,7 +28,7 @@
"lodash.debounce": "^4.0.8",
"lru-cache": "^10.1.0",
"markdown-to-jsx": "^7.4.0",
"next": "^14.2.3",
"next": "^14.2.4",
"nprogress": "^0.2.0",
"ooni-components": "0.6.0-alpha.8",
"pretty-ms": "^8.0.0",
Expand All @@ -37,9 +37,9 @@
"react-content-loader": "^6.2.1",
"react-day-picker": "^8.10.0",
"react-dom": "^18.3.1",
"react-hook-form": "^7.51.3",
"react-icons": "^5.0.1",
"react-intl": "^6.6.0",
"react-hook-form": "^7.52.0",
"react-icons": "^5.2.1",
"react-intl": "^6.6.8",
"react-json-view": "^1.21.3",
"react-outside-click-handler": "^1.3.0",
"react-table": "^7.8.0",
Expand All @@ -49,7 +49,7 @@
"react-window": "^1.8.10",
"regenerator-runtime": "^0.14.1",
"styled-components": "^6.1.8",
"swr": "^2.2.4",
"swr": "^2.2.5",
"use-clipboard-copy": "^0.2.0",
"victory": "32.0.2",
"yup": "^1.3.3"
Expand Down
2 changes: 1 addition & 1 deletion public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.2.13'
const PACKAGE_VERSION = '2.3.1'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()
Expand Down
Loading
Loading