Leap seconds are seconds added or removed from UTC (Coordinated Universal Time) to keep it in sync with the Earth's rotation. If leap seconds were not added or removed, then UTC would drift from TAI. You can read much more about leap seconds on Wikipedia.
Because they are based on astronomical observations, leap seconds are scheduled and not predicted, or predictable. One has been scheduled for June 30th, 2015. What this means practically is that 23:59:59 will be followed by 23:59:60 before going on to 00:00:00. Leap seconds can be added (positive) or removed (negative). A negative leap second would mean that 23:59:58 would be followed by 00:00:00.
There have been problems caused by software not managing this second properly. Note also that depending on the specific implementation and time sychronization mechanisms used, a particular system may not actually "see" the leap second, but it will occur as a regular one second time correction at a later time. All of the timing functions used by Node are monotonic on their various platforms.
As to how this affects applications, as specified by ECMA-262, JavaScript and thus Node, explicitly ignores leap seconds when calculating the difference, in seconds, between two dates. In any event, it wouldn't be possible to take those into account without a historical table, and taking deltas more than 6 months in the future is impossible as the schedule is not known.
Applications should be aware that time-of-day, such as returned by Date()
, is not monotonic and should not be used for timing-sensitive intervals. This is true not just because of leap seconds, but also because of daylight savings time (summer time), corrections due to clock drift
For example, the following example code ( counting the number of seconds since Midnight, Jan 1st, 1970 GMT) does not include leap seconds.
var d0 = new Date(0);
var d1 = new Date(); // right now.
console.log('Unix time started',new Number((d1-d0)/1000).toLocaleString(),'seconds ago');
Issue: nodejs/node-v0.x-archive#9382