Skip to content

Commit 6bb69c5

Browse files
committed
Fixed conversion between JS and NTP timestamps.
1 parent 9c42919 commit 6bb69c5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

osc.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ var osc = osc || {};
380380

381381
// TODO: Unit tests.
382382
osc.jsTimeToNTP = function (jsTime) {
383-
var ms = jsTime | 0,
384-
secs = (ms / 1000) | 0,
383+
var ms = Math.floor(jsTime),
384+
secs = ms / 1000,
385+
fracSec = secs - Math.floor(secs),
385386
secs1900 = secs + osc.SEVENTY_YEARS_SECS,
386-
fracMs = jsTime - ms,
387-
fracSec = ((fracMs / 1000) * 4294967296) | 0;
387+
ntpFracs = 4294967296 * fracSec;
388388

389-
return [secs1900, fracSec];
389+
return [secs1900, ntpFracs];
390390
};
391391

392392
/**

tests/js/osc-tests.js

+11
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@
434434

435435
timeTagTests(timeTagTestSpecs);
436436

437+
test("Write native-only time tag.", function () {
438+
var testSpec = timeTagTestSpecs[1],
439+
expected = testSpec.timeTagBytes,
440+
timeTag = {
441+
native: testSpec.timeTag.native
442+
};
443+
444+
var actual = osc.writeTimeTag(timeTag);
445+
arrayEqual(actual, expected,
446+
"A time tag with no raw value (only a native value) should be written correctly.");
447+
});
437448

438449
/**********************************************
439450
* Read Type-Only Arguments (e.g. T, F, N, I) *

0 commit comments

Comments
 (0)