time-convertor-ts

Convert time across timezones (typescript)
git clone http://git.hanabi.in/repos/time-convertor-ts.git
Log | Files | Refs | README | LICENSE

commit 442ad77954b68292f96c237d8bf2064b110d2b0f
parent f62c4932b77c8dfa5fee06d126d0c7c5b78a2c8b
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Thu, 28 May 2020 00:16:19 +0530

Save state of date-time for future; fixes #1

Diffstat:
Msrc/App/index.tsx | 14++++++++++++--
Msrc/App/pages/FutureConversion.tsx | 15++++++---------
Msrc/utils/interfaces.tsx | 5++++-
3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/App/index.tsx b/src/App/index.tsx @@ -9,13 +9,20 @@ import SimpleConvertor from './pages/SimpleConvertor'; import Footer from './comps/Footer'; import Header from './comps/Header'; -import { basePath, DEFAULT_TZ, localTimezone } from '../utils'; +import { displayTime } from '../utils'; +import { basePath, DEFAULT_TZ, HM, localTimezone, YMD } from '../utils'; import useTime from '../utils/useTime'; function App<never>(): JSX.Element { const now = useTime(); const [timezone1, setTimezone1] = React.useState(DEFAULT_TZ); const [timezone2, setTimezone2] = React.useState(localTimezone); + const [date, setDate] = React.useState( + displayTime({ fmtStr: YMD, time: now, timezone: localTimezone }) + ); + const [time, setTime] = React.useState( + displayTime({ fmtStr: HM, time: now, timezone: localTimezone }) + ); return ( <Router> @@ -29,9 +36,12 @@ function App<never>(): JSX.Element { path={`${basePath}/future`} render={() => ( <FutureConversion - time={now} + date={date} + setDate={setDate} + setTime={setTime} setTZ1={setTimezone1} setTZ2={setTimezone2} + time={time} TZ1={timezone1} TZ2={timezone2} /> diff --git a/src/App/pages/FutureConversion.tsx b/src/App/pages/FutureConversion.tsx @@ -7,24 +7,21 @@ import SavedFuture from '../comps/SavedFuture'; import TimezoneInput from '../comps/TimezoneInput'; import { displayTime, getYesterday, timezoneList } from '../../utils'; -import { HM, MAX_DATE, YMD, localTimezone } from '../../utils'; +import { MAX_DATE, YMD, localTimezone } from '../../utils'; import { IFutureConversion } from '../../utils/interfaces'; function FutureConversion({ + date, + setDate, + setTime, setTZ1, setTZ2, - time: now, // aliased because [time, setTime] hook + time, + // now, // aliased because [time, setTime] hook TZ1, TZ2, }: IFutureConversion): JSX.Element { - const [date, setDate] = React.useState( - displayTime({ fmtStr: YMD, time: now, timezone: localTimezone }) - ); - const [time, setTime] = React.useState( - displayTime({ fmtStr: HM, time: now, timezone: localTimezone }) - ); - const [selectedTime, setSelectedTime] = React.useState< moment.Moment | undefined >(undefined); diff --git a/src/utils/interfaces.tsx b/src/utils/interfaces.tsx @@ -14,9 +14,12 @@ export interface IDualConvertor { } export interface IFutureConversion { + date: string; + setDate: React.Dispatch<React.SetStateAction<string>>; + setTime: React.Dispatch<React.SetStateAction<string>>; setTZ1: React.Dispatch<React.SetStateAction<string>>; setTZ2: React.Dispatch<React.SetStateAction<string>>; - time: moment.Moment; + time: string; TZ1: string; TZ2: string; }