Annotation of parser3/src/types/pa_vdate.h, revision 1.1

1.1     ! parser      1: /** @file
        !             2:        Parser: @b date parser class decl.
        !             3: 
        !             4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             5: 
        !             6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
        !             7: 
        !             8:        $Id: pa_vint.h,v 1.22 2001/05/11 17:45:10 parser Exp $
        !             9: */
        !            10: 
        !            11: #ifndef PA_VDATE_H
        !            12: #define PA_VDATE_H
        !            13: 
        !            14: #include "classes.h"
        !            15: #include "pa_common.h"
        !            16: #include "pa_vstateless_object.h"
        !            17: #include "pa_vint.h"
        !            18: 
        !            19: #define SECS_PER_DAY (60*60*24)
        !            20: 
        !            21: extern Methoded *date_class;
        !            22: 
        !            23: /// value of type 'date'. implemented with @c time_t
        !            24: class VDate : public VStateless_object {
        !            25: public: // Value
        !            26: 
        !            27:        const char *type() const { return "date"; }
        !            28:        /// VDate: ftime -> float days
        !            29:        Value *as_expr_result(bool return_string_as_is=false) {
        !            30:                return NEW VDouble(pool(), as_double());
        !            31:        }
        !            32: 
        !            33:        /// VDate: ftime -> float days
        !            34:        double as_double() { return ((double)ftime)/ SECS_PER_DAY; }
        !            35:        /// VDate: 0 or !0
        !            36:        bool as_bool() { return ftime!=0; }
        !            37: 
        !            38: 
        !            39:        /// VDate: CLASS,BASE,method,field
        !            40:        Value *get_element(const String& aname) {
        !            41:                // $CLASS,$BASE,$method
        !            42:                if(Value *result=VStateless_object::get_element(aname))
        !            43:                        return result;
        !            44: 
        !            45:                // $year month day  hour minute second  weekday
        !            46:                tm *tmOut=localtime(&ftime);
        !            47:                int result;
        !            48:                if(aname=="year") result=1900+tmOut->tm_year;
        !            49:                else if(aname=="month") result=1+tmOut->tm_mon;
        !            50:                else if(aname=="day") result=tmOut->tm_mday;
        !            51:                else if(aname=="hour") result=tmOut->tm_hour;
        !            52:                else if(aname=="minute") result=tmOut->tm_min;
        !            53:                else if(aname=="second") result=tmOut->tm_sec;
        !            54:                else if(aname=="weekday") result=tmOut->tm_wday;
        !            55:                else return 0;
        !            56:                return NEW VInt(pool(), result);
        !            57:        }
        !            58: 
        !            59: protected: // VAliased
        !            60: 
        !            61:        /// disable .CLASS element. @see VAliased::get_element
        !            62:        bool hide_class() { return true; }
        !            63: 
        !            64: public: // usage
        !            65: 
        !            66:        VDate(Pool& apool, time_t adate) : VStateless_object(apool, *date_class), 
        !            67:                ftime(adate) {
        !            68:        }
        !            69: 
        !            70:        time_t get_time() { return ftime; }
        !            71:        void set_time(time_t atime) { ftime=atime; }
        !            72: 
        !            73: private:
        !            74: 
        !            75:        time_t ftime;
        !            76: 
        !            77: };
        !            78: 
        !            79: #endif

E-mail: