From e7f6349650ed288c3fee6f35578e0fb0e0ad34d5 Mon Sep 17 00:00:00 2001 From: majakomel Date: Tue, 18 Jun 2024 16:24:48 -0400 Subject: [PATCH 1/2] Fix calendar in all timezones --- components/as/Calendar.js | 17 +- package.json | 12 +- public/mockServiceWorker.js | 2 +- yarn.lock | 2622 +++++++++++++++++------------------ 4 files changed, 1297 insertions(+), 1356 deletions(-) diff --git a/components/as/Calendar.js b/components/as/Calendar.js index a2a857931..9bfc76954 100644 --- a/components/as/Calendar.js +++ b/components/as/Calendar.js @@ -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` @@ -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 } @@ -68,7 +69,7 @@ const Calendar = React.memo(function Calendar({data}) { dayBorderColor="#ffffff" /> - + {colorLegend.map(item => ( =1.0.2: version "1.0.2" @@ -7601,7 +7541,7 @@ which-collection@^1.0.1: is-weakmap "^2.0.2" is-weakset "^2.0.3" -which-typed-array@^1.1.13, which-typed-array@^1.1.14, which-typed-array@^1.1.15, which-typed-array@^1.1.9: +which-typed-array@^1.1.14, which-typed-array@^1.1.15, which-typed-array@^1.1.9: version "1.1.15" resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d" integrity sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA== @@ -7619,6 +7559,11 @@ which@^2.0.1, which@^2.0.2: dependencies: isexe "^2.0.0" +word-wrap@^1.2.5: + version "1.2.5" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" + integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== + wrap-ansi@^6.2.0: version "6.2.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" @@ -7643,14 +7588,14 @@ wrappy@1: integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== ws@^7.3.1: - version "7.5.9" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" - integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== + version "7.5.10" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9" + integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ== ws@^8.16.0: - version "8.16.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4" - integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ== + version "8.17.1" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b" + integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ== xml-name-validator@^5.0.0: version "5.0.0" @@ -7672,11 +7617,6 @@ yallist@^3.0.2: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== -yallist@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" - integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== - yaml@^1.10.0: version "1.10.2" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b" From eac7986c1239d733aff806c01c48057ab1d54b3c Mon Sep 17 00:00:00 2001 From: majakomel Date: Tue, 18 Jun 2024 18:40:25 -0400 Subject: [PATCH 2/2] Show only 1 year at once in the calendar --- components/as/Calendar.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/as/Calendar.js b/components/as/Calendar.js index 9bfc76954..ff87375bd 100644 --- a/components/as/Calendar.js +++ b/components/as/Calendar.js @@ -59,7 +59,9 @@ const Calendar = React.memo(function Calendar({data}) { findColor(value)}