diff --git a/src/pages/tools/time/convert-unix-to-date/index.tsx b/src/pages/tools/time/convert-unix-to-date/index.tsx index 8e5c249..7b22f02 100644 --- a/src/pages/tools/time/convert-unix-to-date/index.tsx +++ b/src/pages/tools/time/convert-unix-to-date/index.tsx @@ -7,7 +7,7 @@ import ToolTextResult from '@components/result/ToolTextResult'; import { GetGroupsType } from '@components/options/ToolOptions'; import { CardExampleType } from '@components/examples/ToolExamples'; import CheckboxWithDesc from '@components/options/CheckboxWithDesc'; -import { convertString } from './service'; +import { UnixDateConverter } from './service'; import { useTranslation } from 'react-i18next'; import InitialValuesType from './types'; import SimpleRadio from '@components/options/SimpleRadio'; @@ -49,18 +49,6 @@ const exampleCards: CardExampleType[] = [ useLocalTime: false } }, - { - title: 'Use Local Time', - description: - 'This example demonstrates how timestamps are shown in your local timezone rather than UTC. The UTC suffix is omitted in this case.', - sampleText: `1721287227`, - sampleResult: `2024-07-18 12:00:27`, - sampleOptions: { - mode: 'unix-to-date', - withLabel: true, - useLocalTime: true - } - }, { title: 'Basic Date to Unix', description: @@ -88,18 +76,6 @@ const exampleCards: CardExampleType[] = [ withLabel: true, useLocalTime: false } - }, - { - title: 'Use Local Time', - description: - "This example uses your browser's timezone. Any suffix provided as the UTC offset is ignored. In this example we assume the timezone of the user to be UTC+6.", - sampleText: `2025-04-04 11:30:00`, - sampleResult: `1743744600`, - sampleOptions: { - mode: 'date-to-unix', - withLabel: true, - useLocalTime: true - } } ]; @@ -108,10 +84,8 @@ export default function ConvertUnixToDate({ title }: ToolComponentProps) { const [input, setInput] = useState(''); const [result, setResult] = useState(''); - const compute = (values: typeof initialValues, input: string) => { - setResult( - convertString(input, values.mode, values.useLocalTime, values.withLabel) - ); + const compute = (values: InitialValuesType, input: string) => { + setResult(UnixDateConverter(input, values)); }; const getGroups: GetGroupsType | null = ({ @@ -136,11 +110,22 @@ export default function ConvertUnixToDate({ title }: ToolComponentProps) { ) }, { - title: t('convertUnixToDate.withLabel'), + title: t('convertUnixToDate.tzOptions'), component: ( - {/* Only Show Add UTC Suffix Option on Convert Unix to Date */} - {values.mode === 'unix-to-date' && ( + updateField('useLocalTime', true)} + checked={values.useLocalTime === true} + title={t('convertUnixToDate.useLocalTime')} + /> + updateField('useLocalTime', false)} + checked={values.useLocalTime === false} + title={t('convertUnixToDate.useUTC')} + /> + + {/* Only Show Add UTC Suffix Option on Convert Unix to Date and utc mode selected */} + {values.mode === 'unix-to-date' && !values.useLocalTime && ( updateField('withLabel', val)} checked={values.withLabel} @@ -148,12 +133,6 @@ export default function ConvertUnixToDate({ title }: ToolComponentProps) { description={t('convertUnixToDate.addUtcLabelDescription')} /> )} - updateField('useLocalTime', val)} - checked={values.useLocalTime} - title={t('convertUnixToDate.useLocalTime')} - description={t('convertUnixToDate.useLocalTimeDescription')} - /> ) }