Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>class ztimeinfo</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
class zTimeInfo

Usage

    #include <time.hpp>
    zTimeInfo ...;

Description

        zTimeInfo(void);
                        // set all from system
        zTimeInfo(const zTimeInfo&);
                        // copy constructor
        zTimeInfo(int, int, int = 0);
                        // set time - date from system
        zTimeInfo(char *, int=0, int=0, int=0);
                        // set all from arguments
        zTimeInfo &operator=(const zTimeInfo&);

    // A set of access function return the values of the various members
    // of the underlying struct tm.

        int sec() const { return ts.tm_sec; }
        int min() const { return ts.tm_min; }
        int hour() const {return ts.tm_hour; }
        int day() const { return ts.tm_mday; }
        int mon() const { return ts.tm_mon; }
        int year() const { return ts.tm_year; }
        int yday() const { return ts.tm_yday; }
        int dayw() const { return ts.tm_wday; }
        unsigned dayno() const { return last/SECSPERDAY; }

    // The next group of functions provide character string representations
    // of various aspects of the time and date.  The defaulted argument to
    // tod determines whether seconds are to be displayed as part of
    // the time of day.

        char *tod(int = 0);
        char *wday();
        char *dldate(); // like Tuesday 9 April 1990
        char *ldate();  // 9 April 1990
        char *date();   // 09/04/90

    // A set function allows for an existing zTimeInfo object to be
    // completely reset.  The arguments are year, month, day, hour,
    // minute and second.

        time_t set(int, int , int , int = 0, int = 0, int = 0);

    // Date and time arithmetic are facilitated by definitions of the
    // +, -, += and -= operations.  The latter two affect the object for
    // which they are called.

        zTimeInfo operator+(long);
        zTimeInfo operator-(long);
        long operator-(const zTimeInfo &a) { return last - a.last; }
        zTimeInfo &operator+=(long);
        zTimeInfo &operator-=(long);

    // The boolean operators are also implemented.

        int operator>(const zTimeInfo &a) { return last > a.last; }
        int operator<(const zTimeInfo &a) { return last < a.last; }
        int operator>=(const zTimeInfo &a) { return last >= a.last; }
        int operator<=(const zTimeInfo &a) { return last <= a.last; }
        int operator==(const zTimeInfo &a) { return last == a.last; }
        int operator!=(const zTimeInfo &a) { return last != a.last; }

    // The now function fixes up an existing zTimeInfo object from
    // the system clock.

        time_t now();
        int error() { int e = err; err = 0; return e; }
        ~zTimeInfo() { delete dbuf; delete tbuf; }

    // Set the static class variable zTimeInfo::notUS to something other
    // than zero for European date styles.

        static int notUS;

Example 

    #include <stdlib.h>
    #include <time.hpp>

    main()
    {
        //. Declare two zTimeInfo objects, one, ti initialized from the
        //. sytem clock, and the other by a date string.
            zTimeInfo ti, apr1 = "4/1/91";

        //. Demonstrate the date/time formatting functions, then do some
        //. date arithmetic.
            printf("Today is %s - time: %s\n",
                ti.dldate(),ti.tod());
            if (ti > apr1)
                printf("%ld days after ",
                (ti-apr1)/SECSPERDAY);
            else if (ti < apr1)
                printf("%ld days before ",
                    (apr1-ti)/SECSPERDAY);
            printf("April fools day\n");
        // check addition and assignment
            ti = apr1+364*SECSPERDAY;
            printf("ti becomes %s - time: %s\n",
                    ti.dldate(),ti.tod());

        // modify ti to November 5 - same year
            ti.set(-1,11,5);

        // and the other date formats
            printf("Other date formats are:\n");
            printf("    %s\n",ti.ldate());
        // then to July 4 1990 12:30
            ti.set(90,7,4,12,30);
            printf("    %s\n",ti.date());
            printf(
        "20 days after this last date it will be ");

        // check the copy constructor
            zTimeInfo then = ti;
            then += 20*SECSPERDAY;
            printf("%s - time: %s\n",
                then.dldate(),then.tod());
            return EXIT_SUCCESS;
    }

See Also




Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson