-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.ts
39 lines (30 loc) · 839 Bytes
/
index.ts
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
import { program } from 'commander';
import { NtpClient } from './ntp-client';
const client = new NtpClient();
program.option('--setTime', 'Set the system timestamp');
program.parse();
const options = program.opts();
client
.getTime()
.then((msg) => {
console.log('NTP Packet', msg);
const offset = client.getOffset();
console.log(`Offset (theta) ${offset}ms`);
const rtt = client.getRtt();
console.log(`RTT (delta) ${rtt}ms`);
// The correct time will be calculated based on the offset
const now = client.now();
if (options.setTime) {
client
.setSystemTime(now)
.then(() => {
console.log('Successfully set system time');
})
.catch((err) => {
console.error(err);
});
}
})
.catch((err) => {
console.error(err);
});