Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 4a2251d

Browse files
chore: add dev time stamp component (#431)
* chore: add dev time stamp component * chore: add timestamp formatting * chore: decrease interval * Update src/components/dev/DevTimeStamp/DevTimeStamp.scss Co-authored-by: Chris Smith <[email protected]> * chore: move dev timestamp out of auth protected * chore: center timestamp * chore: place timestamp on top * chore: explain comment --------- Co-authored-by: Chris Smith <[email protected]>
1 parent 0a90e99 commit 4a2251d

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.DevTimeStamp {
2+
color: #888888;
3+
position: fixed;
4+
width: 100%;
5+
top: 0.5em;
6+
font-size: 11px;
7+
pointer-events: none;
8+
z-index: 999;
9+
10+
span {
11+
display: block;
12+
width: fit-content;
13+
margin: auto;
14+
}
15+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useContext, useEffect, useState } from 'react';
2+
import './DevTimeStamp.scss'
3+
import SettingsContext from '@/contexts/SettingsContext/context';
4+
5+
const getTimeStampFormatted = (rawTimestamp: number) => {
6+
7+
const timestamp = new Date(rawTimestamp)
8+
9+
const year = timestamp.getFullYear();
10+
11+
// Months are zero-indexed
12+
const month = (timestamp.getMonth() + 1).toString().padStart(2, '0');
13+
const day = timestamp.getDate().toString().padStart(2, '0');
14+
const hours = timestamp.getHours().toString().padStart(2, '0');
15+
const minutes = timestamp.getMinutes().toString().padStart(2, '0');
16+
const seconds = timestamp.getSeconds().toString().padStart(2, '0');
17+
18+
const timeZone = new Intl.DateTimeFormat('en', { timeZoneName: 'short' }).formatToParts(timestamp).find(part => part.type === 'timeZoneName')!.value;
19+
20+
const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${timeZone}`;
21+
22+
return formattedDateTime
23+
24+
}
25+
26+
const DevTimeStamp = () => {
27+
const [timestamp, setTimestamp] = useState(Date.now())
28+
const {isDevModeEnabled} = useContext(SettingsContext)
29+
30+
useEffect(() => {
31+
if(isDevModeEnabled) {
32+
const intervalId = setInterval(() => {
33+
setTimestamp(Date.now())
34+
}, 250)
35+
36+
return () => clearInterval(intervalId)
37+
}
38+
}, [setTimestamp, isDevModeEnabled])
39+
40+
if (!isDevModeEnabled) {
41+
return null;
42+
}
43+
44+
return (
45+
<div className="DevTimeStamp">
46+
<span>{getTimeStampFormatted(timestamp)}</span>
47+
</div>
48+
)
49+
}
50+
51+
export default DevTimeStamp;

src/main.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { initSentry } from '@/utils/sentry'
1616
import { Modals } from './Modals'
1717

1818
import './index.css'
19+
import DevTimeStamp from './components/dev/DevTimeStamp'
1920

2021
polyfill()
2122
initSentry()
@@ -50,6 +51,7 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
5051
<BrowserRouter>
5152
<W3iContextProvider>
5253
<ConfiguredRoutes />
54+
<DevTimeStamp />
5355
<Modals />
5456
</W3iContextProvider>
5557
</BrowserRouter>

0 commit comments

Comments
 (0)