justaprogrammer/ObjectId.js — Issue #1: Not sure about toString function - a bug?
Author: hgoebl
Created: 2011-12-12 10:51:13+00:00
State: open

I didn't try / test it, but only by reading the code one thing sounds a bit strange to me:

ObjectId.prototype.toString = function () {
var timestamp = this.timestamp.toString(16);
var machine = this.machine.toString(16);
var pid = this.pid.toString(16);
var increment = this.increment.toString(16);
return '00000000'.substr(0, 6 - timestamp.length) + timestamp +
'000000'.substr(0, 6 - machine.length) + machine +
'0000'.substr(0, 4 - pid.length) + pid +
'000000'.substr(0, 6 - increment.length) + increment;
}

The zero-mask for the timestamp is 8 characters long, the substr function has 6 - timestamp.length.
The lenght of the zero-masks for machine, pid and increment are consistent with the argument for substr.

Is this a bug or have I missed something?