Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #789 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

TimeSpan.opCmp is broken

Reported by: Deewiant Assigned to: schveiguy
Priority: critical Milestone: 0.99.4
Component: Core Functionality Version: trunk
Keywords: Cc:


The current body of TimeSpan?.opCmp is the following:

return cast(int)((ticks - t.ticks) >>> 32);

This, of course, doesn't work if ticks - t.ticks is positive and less than int.max, because all such values result in 0.

Simplest fix, I'm not sure if any nontrivial bit twiddling works correctly for all cases:

return ticks > t.ticks ? 1 : ticks == t.ticks ? 0 : -1;


return typeid(typeof(ticks)).compare(&ticks, &t.ticks);

Here're some simple test cases. All should be true, but the current implementation gives "false" on the first, fourth, and sixth:

import tango.util.time.TimeSpan;

void main() {
	Stdout( >;
	Stdout(TimeSpan.year >;
	Stdout(TimeSpan.year >;
	Stdout( > TimeSpan.min).newline;
	Stdout(TimeSpan.max  >;
	Stdout(TimeSpan.max  > TimeSpan.min).newline;
	Stdout( >=;
	Stdout( <=;
	Stdout(TimeSpan.max >= TimeSpan.max).newline;
	Stdout(TimeSpan.max <= TimeSpan.max).newline;
	Stdout(TimeSpan.min >= TimeSpan.min).newline;
	Stdout(TimeSpan.min <= TimeSpan.min).newline;

Change History

11/26/07 13:49:11 changed by larsivi

While you are at it, make those unittests.

11/26/07 13:59:10 changed by Deewiant

Yeah, I figured that was implicit. ;-)

11/26/07 16:27:13 changed by schveiguy

  • status changed from new to closed.
  • resolution set to fixed.

(In [2936]) Closes #789 Fix dsss.conf to not build .di of timespan now that it is no longer part of the base lib.