|
|
The Duration constructors allow clients to specify (1) no parameters, yielding a zero-length Duration, (2) days, (3) days and hours, (4) days, hours, and minutes, or (5) days hours, minutes, and seconds. For example:
Duration d0; // zero-length Duration Duration d1(1); // Duration of 1d Duration d2(1,1); // Duration of 1d 1h Duration d3(1,1,1); // Duration of 1d 1h 1m Duration d4(1,1,1,1); // Duration of 1d 1h 1m 1s
As usual, constructors may appear in expressions. Although addition has yet to be discussed, the following example illustrates such an expression:
Duration d; ... d += Duration(1); // add one day to d
The arguments to the Duration constructors may have mixed signs. Furthermore, hours may lie outside the range [0,23] and both minutes and seconds may lie outside the range [0,59]. Such ``unnormalized'' arguments are immediately normalized by the constructor, as illustrated by the following example:
cout << Duration(-1,25,-61,61) << endl;
which prints
0d 00h 00m 01s