Skip to content

Commit ff7365d

Browse files
committed
Don't include date in datetime prop of time element
1 parent 60f739f commit ff7365d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/react-clock/src/Clock.spec.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ describe('Clock', () => {
4040

4141
const time = container.querySelector('time');
4242

43-
expect(time).toHaveAttribute('datetime', date.toISOString());
43+
expect(time).toHaveAttribute(
44+
'datetime',
45+
date.toLocaleTimeString('en', {
46+
hourCycle: 'h23',
47+
hour: '2-digit',
48+
minute: '2-digit',
49+
second: '2-digit',
50+
}),
51+
);
4452
});
4553

4654
it('has proper datetime attribute when given string value', () => {

packages/react-clock/src/Clock.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,17 @@ export default function Clock({
339339
return (
340340
<time
341341
className={clsx('react-clock', className)}
342-
dateTime={value instanceof Date ? value.toISOString() : value || undefined}
342+
dateTime={
343+
value instanceof Date
344+
? // Returns a string in the format "HH:MM" or "HH:MM:SS"
345+
value.toLocaleTimeString('en', {
346+
hourCycle: 'h23',
347+
hour: '2-digit',
348+
minute: renderMinuteHand ? '2-digit' : undefined,
349+
second: renderSecondHand ? '2-digit' : undefined,
350+
})
351+
: value || undefined
352+
}
343353
style={{
344354
width: size,
345355
height: size,

0 commit comments

Comments
 (0)