Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/rn-tester/js/examples/Playground/RNTesterPlayground.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,33 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes';

import RNTesterText from '../../components/RNTesterText';
import * as React from 'react';
import {useEffect, useState} from 'react';
import {StyleSheet, View} from 'react-native';

// Reproducer for #60450: on iOS/macOS, performance.timeOrigin + performance.now()
// should approximate Date.now(), but it lags by the device's total sleep since
// boot. Run on an iOS simulator after the host Mac has slept (or on a device
// after it has slept), or leave this screen open and put the Mac to sleep for a
// minute: the drift jumps by the sleep duration. On Android it stays ~0.
function readDriftMs(): number {
return Date.now() - (performance.timeOrigin + performance.now());
}

function Playground() {
const [driftMs, setDriftMs] = useState(readDriftMs);

useEffect(() => {
const id = setInterval(() => setDriftMs(readDriftMs()), 1000);
return () => clearInterval(id);
}, []);

return (
<View style={styles.container}>
<RNTesterText>
Edit "RNTesterPlayground.js" to change this file
<RNTesterText testID="timeorigin-drift">
Date.now() - (performance.timeOrigin + performance.now()) ={' '}
{(driftMs / 1000).toFixed(3)} s
</RNTesterText>
<RNTesterText>Expected: about 0 s on every platform.</RNTesterText>
</View>
);
}
Expand Down