DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
No more ctime(3C) errors - Time(3C++)

Component extractors

The individual components of a Duration can be viewed by the `component extractor' operations:

       Duration d = Duration::seconds(-1);
       cout << d.day_part() << "d "
            << d.hour_part() << "h "
            << d.minute_part() << "m "
            << d.second_part() << "s"
            << endl;

which prints

       0d 0h 0m -1s

The fact that Duration arguments are `normalized' means that the values returned by the component extractors satisfy the following invariant:

Another function named seconds() returns the value of a given Duration in seconds:
       Duration d = Duration::hours(1);
   

cout << seconds(d) << endl;

which prints 3600.

Finally, operator void*() provides a convenient test for zero-length Durations through implicit conversion in contexts like if and loop conditions, which expect integral or pointer values. The following loop depends on implicit conversion for its termination condition:

       for(Duration d = Duration::days(100);
           d;
           d -= Duration::days(1)){
           ...
       }

Next topic: Relational operators
Previous topic: Functions for expressing Durations in natural units

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004