feat: Add Unix Timestamp (Epoch) Converter Utility#28
feat: Add Unix Timestamp (Epoch) Converter Utility#28udaykiran243 wants to merge 3 commits intobetterbugs:developfrom
Conversation
|
@udaykiran243 also attach a reference video of the tool implemented. |
|
https://drive.google.com/file/d/1X9T9cysvlUFFgTY3OSvrVf76Cx9z1VRt/view?usp=sharing the video size is more, so I'm sharing the drive link. |
|
hey @rishima17 @SyedFahad7 @mohitmalibetterbugs resolved the merge conflicts please review. |
SyedFahad7
left a comment
There was a problem hiding this comment.
Hi @udaykiran243, I’m seeing a TypeScript error in epochConverter.tsx related to the Ant Design ConfigProvider theme config..
borderColor is not a valid component token for Input or DatePicker in AntD v5, which causes a type error.
Please replace borderColor with the correct token (with likely colorBorder) or remove it if not needed. We should keep the codebase type safe.
Once updated, I’ll re-review.
|
hey @SyedFahad7 made the changes. |
There was a problem hiding this comment.
Pull request overview
Adds a new “Unix Timestamp Converter” tool page to the BetterBugs development tools suite, including routing and SEO/content metadata.
Changes:
- Added
EpochConverterReact component to convert between epoch timestamps (sec/ms) and dates with multiple formatted outputs. - Registered the new route (
/unix-timestamp-converter) inPATHSanddevelopmentToolsRoutes. - Added tool metadata/content to
DEVELOPMENTTOOLSand introduceddayjsdependency.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
package.json |
Adds dayjs dependency needed by the new converter component. |
package-lock.json |
Locks dayjs (and other dependency graph changes) for reproducible installs. |
app/libs/developmentToolsConstant.tsx |
Adds SEO + usage content entry for the new converter slug. |
app/libs/constants.tsx |
Registers the new path constant and route component mapping. |
app/components/developmentToolsComponent/epochConverter.tsx |
Implements the Unix timestamp ↔ date converter UI/logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import utc from "dayjs/plugin/utc"; | ||
| import timezone from "dayjs/plugin/timezone"; | ||
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | ||
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; |
There was a problem hiding this comment.
CopyOutlined is imported but not used anywhere in this component. Please remove it (or wire it into the UI) to keep lint clean.
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | |
| import { ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; |
| const copyToClipboard = (text: string) => { | ||
| navigator.clipboard.writeText(text); | ||
| message.success("Copied to clipboard!"); | ||
| }; | ||
|
|
There was a problem hiding this comment.
copyToClipboard is currently unused (the UI uses Text's copyable prop instead). Please remove this helper (or switch the UI to call it) to avoid unused-function lint errors and potential unhandled clipboard promise rejections.
| const copyToClipboard = (text: string) => { | |
| navigator.clipboard.writeText(text); | |
| message.success("Copied to clipboard!"); | |
| }; |
| const currentDayjs = timestamp ? dayjs(isMilliseconds ? Number(timestamp) : Number(timestamp) * 1000) : null; | ||
| const isValid = currentDayjs && currentDayjs.isValid(); |
There was a problem hiding this comment.
With strict: true, currentDayjs is typed as Dayjs | null, but later it’s used as non-null (currentDayjs.format(), utc(), etc.). This will cause TypeScript errors; consider restructuring to explicitly guard (if (!currentDayjs || !currentDayjs.isValid()) ...) so TS can narrow the type in the render branch (or use a non-null assertion if you’re certain).
| const currentDayjs = timestamp ? dayjs(isMilliseconds ? Number(timestamp) : Number(timestamp) * 1000) : null; | |
| const isValid = currentDayjs && currentDayjs.isValid(); | |
| const num = timestamp ? Number(timestamp) : NaN; | |
| const currentDayjs = dayjs(isMilliseconds ? num : num * 1000); | |
| const isValid = !!timestamp && !Number.isNaN(num) && currentDayjs.isValid(); |
| import timezone from "dayjs/plugin/timezone"; | ||
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | ||
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | ||
|
|
||
| dayjs.extend(relativeTime); | ||
| dayjs.extend(utc); | ||
| dayjs.extend(timezone); |
There was a problem hiding this comment.
dayjs/plugin/timezone is imported, but the component doesn’t use .tz() anywhere. If timezone conversion isn’t needed, consider removing the timezone plugin import/usage to reduce bundle size.
| import timezone from "dayjs/plugin/timezone"; | |
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | |
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | |
| dayjs.extend(relativeTime); | |
| dayjs.extend(utc); | |
| dayjs.extend(timezone); | |
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | |
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | |
| dayjs.extend(relativeTime); | |
| dayjs.extend(utc); |
| import timezone from "dayjs/plugin/timezone"; | ||
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | ||
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | ||
|
|
||
| dayjs.extend(relativeTime); | ||
| dayjs.extend(utc); | ||
| dayjs.extend(timezone); |
There was a problem hiding this comment.
dayjs.extend(timezone) is currently unused since the component doesn’t call .tz(). Consider dropping this extend call (and the plugin import) unless you plan to add explicit timezone selection/conversion.
| import timezone from "dayjs/plugin/timezone"; | |
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | |
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | |
| dayjs.extend(relativeTime); | |
| dayjs.extend(utc); | |
| dayjs.extend(timezone); | |
| import DevelopmentToolsStyles from "../../developmentToolsStyles.module.scss"; | |
| import { CopyOutlined, ReloadOutlined, DeleteOutlined } from "@ant-design/icons"; | |
| dayjs.extend(relativeTime); | |
| dayjs.extend(utc); |
| import React, { useState, useEffect } from "react"; | ||
| import { Button, Input, DatePicker, message, Tooltip, Card, Typography, Space, Row, Col, ConfigProvider, theme } from "antd"; |
There was a problem hiding this comment.
Unused imports here (useEffect and several AntD exports like Tooltip/Card) should be removed to avoid next lint failures. Please trim the import list to only what the component uses.
| import React, { useState, useEffect } from "react"; | |
| import { Button, Input, DatePicker, message, Tooltip, Card, Typography, Space, Row, Col, ConfigProvider, theme } from "antd"; | |
| import React, { useState } from "react"; | |
| import { Button, Input, DatePicker, message, Typography, Space, Row, Col, ConfigProvider, theme } from "antd"; |
| dayjs.extend(utc); | ||
| dayjs.extend(timezone); | ||
|
|
||
| const { Title, Text } = Typography; |
There was a problem hiding this comment.
Title is destructured from Typography but not used. Please remove it (or render a heading with it) to avoid unused-variable lint errors.
| const { Title, Text } = Typography; | |
| const { Text } = Typography; |
| // Auto-detect milliseconds if value is large (simple heuristic: > 10000000000 implies likely ms for recent dates) | ||
| // Standard unix timestamp for today is ~1.7e9 (10 digits). MS is ~1.7e12 (13 digits). | ||
| // However, user might toggle the switch manually. | ||
| // We'll trust the toggle or update the date based on current toggle. | ||
| const timestampInMs = isMilliseconds ? num : num * 1000; | ||
| setDate(dayjs(timestampInMs)); |
There was a problem hiding this comment.
The PR description mentions auto-detecting seconds vs milliseconds, and this block’s comment suggests a heuristic, but the implementation always relies on the current isMilliseconds toggle and never updates it based on the input size. Either implement the heuristic (e.g., switch to ms for 13-digit values / >1e11) or update/remove the comment and PR description to match the actual behavior.
| // However, user might toggle the switch manually. | ||
| // We'll trust the toggle or update the date based on current toggle. | ||
| const timestampInMs = isMilliseconds ? num : num * 1000; | ||
| setDate(dayjs(timestampInMs)); |
There was a problem hiding this comment.
If the user enters a non-numeric timestamp (e.g. abc), timestamp updates but date is left unchanged, so the DatePicker can show a stale value while the output says "Invalid Timestamp". Consider setting date to null (or otherwise clearing/invalidating it) when Number(val) is NaN to keep the two inputs consistent.
| setDate(dayjs(timestampInMs)); | |
| setDate(dayjs(timestampInMs)); | |
| } else { | |
| // Clear date when timestamp is non-numeric to avoid stale DatePicker value | |
| setDate(null); |
Feature: Unix Timestamp (Epoch) Converter Utility
Description
This PR introduces a new utility tool, Unix Timestamp Converter, to the development tools suite. This tool allows users to seamlessly convert between Unix timestamps (Seconds/Milliseconds) and human-readable dates. It's designed to help developers, QAs, and investigators debugging logs or working with time-series data.
fixes #16
Key Features
Implementation Details
app/components/developmentToolsComponent/epochConverter.tsx/unix-timestamp-converterinapp/libs/constants.tsxapp/libs/developmentToolsConstant.tsxdayjsfor robust date manipulation and timezone handling.checklist
hey @rishima17 raised on develop branch