time-convertor-ts

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

FutureConverted.tsx (1207B)


      1 import React from "react";
      2 import moment from "moment-timezone";
      3 
      4 import { displayTime, friendlyStr, getAbbr } from "../../utils";
      5 
      6 import { HMMDY, HMSDMY } from "../../utils";
      7 
      8 import { IFutureConverted } from "../../utils/interfaces";
      9 
     10 function FutureConverted({
     11   selectedTime,
     12   TZ1,
     13   TZ2,
     14 }: IFutureConverted): JSX.Element {
     15   const chosenTime = selectedTime;
     16   const convertedTime = selectedTime.clone().tz(TZ2);
     17   const fromLbl = getAbbr({ timezone: TZ1, time: moment(chosenTime, HMSDMY) });
     18   const toLbl = getAbbr({ timezone: TZ2, time: moment(convertedTime, HMSDMY) });
     19   return (
     20     <div className="mt-5">
     21       <div className="row">
     22         <div className="col">
     23           <h1>{friendlyStr(TZ1)}</h1>
     24         </div>
     25         <div className="col">
     26           <h1>{friendlyStr(TZ2)}</h1>
     27         </div>
     28       </div>
     29       <div className="row">
     30         <div className="col">
     31           {displayTime({ fmtStr: HMMDY, time: chosenTime, timezone: TZ1 })} (
     32           {fromLbl})
     33         </div>
     34         <div className="col">
     35           {displayTime({ fmtStr: HMMDY, time: convertedTime, timezone: TZ2 })} (
     36           {toLbl})
     37         </div>
     38       </div>
     39     </div>
     40   );
     41 }
     42 
     43 export default FutureConverted;