Skip to content

Commit

Permalink
fix wrong dates date selections
Browse files Browse the repository at this point in the history
Apparently, JS Date's toISOString() does not include the local timezone offset; it is UTC.
We want the local date here. So we need to use Luxon.
  • Loading branch information
JGreenlee committed Mar 22, 2024
1 parent 368f6c8 commit 1a12b8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion www/js/diary/list/LabelListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import TimelineScrollList from './TimelineScrollList';
import NavBar from '../../components/NavBar';
import TimelineContext from '../../TimelineContext';
import { LabelTabContext } from '../LabelTab';
import { DateTime } from 'luxon';
import { displayErrorMsg } from '../../plugin/logger';

const LabelListScreen = () => {
const { filterInputs, setFilterInputs, displayedEntries } = useContext(LabelTabContext);
Expand All @@ -25,7 +27,11 @@ const LabelListScreen = () => {
/>
<DateSelect
mode="single"
onChoose={({ date }) => loadSpecificWeek(date.toISOString().substring(0, 10))}
onChoose={({ date }) => {
const d = DateTime.fromJSDate(date).toISODate();
if (!d) return displayErrorMsg('Invalid date');
loadSpecificWeek(d);
}}
/>
<Appbar.Action
icon="refresh"
Expand Down
14 changes: 7 additions & 7 deletions www/js/metrics/MetricsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import DailyActiveMinutesCard from './DailyActiveMinutesCard';
import CarbonTextCard from './CarbonTextCard';
import ActiveMinutesTableCard from './ActiveMinutesTableCard';
import { getAggregateData, getMetrics } from '../services/commHelper';
import { displayError, logDebug, logWarn } from '../plugin/logger';
import { displayErrorMsg, logDebug, logWarn } from '../plugin/logger';
import useAppConfig from '../useAppConfig';
import { ServerConnConfig } from '../types/appConfigTypes';
import DateSelect from '../diary/list/DateSelect';
Expand Down Expand Up @@ -103,12 +103,12 @@ const MetricsTab = () => {
<Appbar.Content title={t('metrics.dashboard-tab')} />
<DateSelect
mode="range"
onChoose={({ startDate, endDate }) =>
setDateRange([
startDate.toISOString().substring(0, 10),
endDate.toISOString().substring(0, 10),
])
}
onChoose={({ startDate, endDate }) => {
const start = DateTime.fromJSDate(startDate).toISODate();
const end = DateTime.fromJSDate(endDate).toISODate();
if (!start || !end) return displayErrorMsg('Invalid date');
setDateRange([start, end]);
}}
/>
<Appbar.Action icon="refresh" size={32} onPress={refreshTimeline} />
</NavBar>
Expand Down

0 comments on commit 1a12b8b

Please sign in to comment.