From 50f8443605b21385d15f4a268c4ae8b64be1a35c Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 13 Mar 2022 01:39:16 -0500 Subject: [PATCH] Prevent initial redirect unless the user navigates --- src/App.tsx | 15 ++++++++++++--- src/TimeOfDay.tsx | 4 ++-- src/dates.ts | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b1a5f10..366c83f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,16 @@ import React, {FormEvent} from 'react'; import {Calendar} from './Calendar'; -import {endGregorian, endJD, frSupportedYear, gregorianJDN, jdnFrench, Month, startGregorian, startJD} from './dates'; +import { + dateJDN, + endGregorian, + endJD, + frSupportedYear, + gregorianJDN, + jdnFrench, + Month, + startGregorian, + startJD +} from './dates'; import {TimeOfDay} from './TimeOfDay'; type YearMonth = { @@ -33,7 +43,7 @@ class App extends React.Component<{}, AppState> { constructor(props: {}) { super(props); const today = new Date(); - const todayJDN = gregorianJDN(today.getFullYear(), today.getMonth() + 1, today.getDate()); + const todayJDN = dateJDN(today); const {year, month} = jdnFrench(todayJDN); this.state = { @@ -43,7 +53,6 @@ class App extends React.Component<{}, AppState> { goMonth: (today.getMonth() + 1).toString(), goDay: today.getDate().toString(), }; - this.updateURL(); this.updateStateFromURL = this.updateStateFromURL.bind(this); } diff --git a/src/TimeOfDay.tsx b/src/TimeOfDay.tsx index 8e66715..80e2a0f 100644 --- a/src/TimeOfDay.tsx +++ b/src/TimeOfDay.tsx @@ -1,6 +1,6 @@ import React from 'react'; import './TimeOfDay.scss'; -import {gregorianJDN} from './dates'; +import {dateJDN, gregorianJDN} from './dates'; type TimeStamp = { hour: number, @@ -52,7 +52,7 @@ export class TimeOfDay extends React.Component { decimalTimer: 0, normal: zero, normalTimer: 0, - jdn: 0, + jdn: dateJDN(new Date()), }; } diff --git a/src/dates.ts b/src/dates.ts index 71ef10c..ab5d047 100644 --- a/src/dates.ts +++ b/src/dates.ts @@ -88,6 +88,10 @@ export function gregorianJDN(year: number, month: number, day: number): number { return J + dg; } +export function dateJDN(date: Date) { + return gregorianJDN(date.getFullYear(), date.getMonth() + 1, date.getDate()); +} + export function frJDN(year: number, month: Month, day: Day): number { const dy = year - startYear; const dd = month * 30 + day - 31;