Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* Time unit converter tool - converts between milliseconds and seconds
*/
import { useState } from 'react';
import {
Box,
TextField,
Typography,
Paper,
Stack,
IconButton,
Collapse,
Divider,
} from '@mui/material';
import {
SwapVert as SwapVertIcon,
ExpandMore as ExpandMoreIcon,
ExpandLess as ExpandLessIcon,
} from '@mui/icons-material';
export default function TimeConverter() {
const [milliseconds, setMilliseconds] = useState<string>('125');
const [seconds, setSeconds] = useState<string>('0.125');
const [isExpanded, setIsExpanded] = useState<boolean>(false);
const handleMillisecondsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setMilliseconds(value);
const ms = parseFloat(value);
if (!isNaN(ms) && ms !== 0) {
setSeconds((ms / 1000).toFixed(6).replace(/\.?0+$/, ''));
} else {
setSeconds('0');
}
};
const handleSecondsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setSeconds(value);
const s = parseFloat(value);
if (!isNaN(s) && s !== 0) {
setMilliseconds((s * 1000).toFixed(3).replace(/\.?0+$/, ''));
} else {
setMilliseconds('0');
}
};
const handleSwap = () => {
const temp = milliseconds;
setMilliseconds(seconds);
setSeconds(temp);
};
return (
<Paper variant="outlined" sx={{ mt: 2 }}>
{/* Header */}
<Box
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
p: 1.5,
cursor: 'pointer',
'&:hover': { bgcolor: 'action.hover' },
}}
onClick={() => setIsExpanded(!isExpanded)}
>
<Typography variant="subtitle2" fontWeight={600} color="primary">
🔄 Convertisseur de temps
</Typography>
<IconButton size="small">
{isExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</IconButton>
</Box>
{/* Converter content */}
<Collapse in={isExpanded}>
<Divider />
<Box sx={{ p: 2 }}>
<Stack spacing={2}>
{/* Milliseconds input */}
<TextField
label="Millisecondes (ms)"
type="number"
value={milliseconds}
onChange={handleMillisecondsChange}
fullWidth
size="small"
inputProps={{ step: 1 }}
helperText="Temps en millisecondes"
InputProps={{
endAdornment: <Typography variant="caption" sx={{ ml: 1 }}>ms</Typography>
}}
/>
{/* Swap button */}
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<IconButton
onClick={handleSwap}
color="primary"
size="small"
sx={{
bgcolor: 'action.hover',
'&:hover': { bgcolor: 'action.selected' }
}}
>
<SwapVertIcon />
</IconButton>
</Box>
{/* Seconds input */}
<TextField
label="Secondes (s)"
type="number"
value={seconds}
onChange={handleSecondsChange}
fullWidth
size="small"
inputProps={{ step: 0.001 }}
helperText="Temps en secondes"
InputProps={{
endAdornment: <Typography variant="caption" sx={{ ml: 1 }}>s</Typography>
}}
/>
{/* Quick reference */}
<Box sx={{ mt: 2, p: 1.5, bgcolor: 'info.light', borderRadius: 1 }}>
<Typography variant="caption" fontWeight={600} display="block" gutterBottom>
Référence rapide (valeurs du TP):
</Typography>
<Stack spacing={0.5}>
<Typography variant="caption" fontFamily="monospace">
• Coordinateur: 10 ms = 0.010 s
</Typography>
<Typography variant="caption" fontFamily="monospace">
• Serveur rapide: 120 ms = 0.120 s
</Typography>
<Typography variant="caption" fontFamily="monospace">
• Serveur moyen: 190 ms = 0.190 s
</Typography>
<Typography variant="caption" fontFamily="monospace">
• Serveur lent: 240 ms = 0.240 s
</Typography>
<Typography variant="caption" fontFamily="monospace">
• Inter-arrivées: 125 ms = 0.125 s
</Typography>
</Stack>
</Box>
{/* Conversion formula */}
<Box sx={{ mt: 1, p: 1.5, bgcolor: 'grey.100', borderRadius: 1 }}>
<Typography variant="caption" fontWeight={600} display="block" gutterBottom>
Formules:
</Typography>
<Typography variant="caption" fontFamily="monospace" display="block">
1 s = 1,000 ms
</Typography>
<Typography variant="caption" fontFamily="monospace" display="block">
1 ms = 0.001 s
</Typography>
</Box>
</Stack>
</Box>
</Collapse>
</Paper>
);
}