hpdatetime.java

来自「一个简单的visio程序。」· Java 代码 · 共 2,210 行 · 第 1/5 页

JAVA
2,210
字号
        double dbl = exp.dblValue();
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc(dbl);
        return (short)(tm.dt_minute);
    }
    public static short MINUTE(fixedString  exp) throws HpException
    {
        double dbl = getdt_db(new VString(exp.strValue() ) );
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc((double)dbl);
        return (short)(tm.dt_minute);
    }
    public static short MINUTE(String  exp) throws HpException
    {
        double dbl = getdt_db( (Variant)(new VString(exp) ));
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc((double)dbl);
        return (short)(tm.dt_minute);
    }


    /**
	 *Second(date)
	 *Returns a whole number between 0 and 59, inclusive, representing the second of
	 *the minute.If time contains Null, Null is returned.
	 */
    public static Variant SECOND(Variant exp)  throws HpException
    {
	HCDateTimeStruct	    tm;
    Variant                 v = null;

    int  type = exp.getType();
    if( type==Variant.V_NULL)
    {
        v = new VNull();
    }
    else
    {
        double  dbl = getdt_db( exp) ;
        tm = new HCDateTimeStruct();
        tm.DT_DblToStruc(dbl);
        v = new VInt( (short)tm.dt_second);
    }
    return v;
    }

    public static short SECOND(boolean  exp) throws HpException
    {
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
       	double  dbl = exp==true ? (double)-1:(double)0;
        tm.DT_DblToStruc(dbl);
        return (short)(tm.dt_second);
    }
    public static short SECOND(HByte  exp) throws HpException
    {
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc((double)(exp.byteValue()));
        return (short)(tm.dt_second);
    }
    public static short SECOND(short  exp) throws HpException
    {
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc((double)exp);
        return (short)(tm.dt_second);
    }
    public static short SECOND(int  exp) throws HpException
    {
    	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc((double)exp);
        return (short)(tm.dt_second);
    }
    public static short SECOND(float  exp) throws HpException
    {
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc((double)exp);
        return (short)(tm.dt_second);
    }
    public static short SECOND(double  exp) throws HpException
    {
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc(exp);
        return (short)(tm.dt_second);
    }
    public static short SECOND(HCurr  exp) throws HpException
    {
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
       	double  dbl = exp.dblValue();
        tm.DT_DblToStruc(dbl);
        return (short)(tm.dt_second);
    }
    public static short SECOND(HDate  exp) throws HpException
    {
        double dbl = exp.dblValue();
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc(dbl);
        return (short)(tm.dt_second);
    }
    public static short SECOND(fixedString  exp) throws HpException
    {
        double dbl = getdt_db( new VString(exp.strValue() ) );
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc(dbl);
        return (short)(tm.dt_second);
    }
    public static short SECOND(String  exp) throws HpException
    {
        double dbl = getdt_db( (Variant)(new VString(exp) ));
       	HCDateTimeStruct	    tm = new HCDateTimeStruct();
        tm.DT_DblToStruc(dbl);
        return (short)(tm.dt_second);
    }


    /**
	 *TimeSerial( hour, minute, second)
	 *Returns a Date containing the time for a specific hour, minute, and second.
	 */
    public static Variant TIMESERIAL(Variant  varhours,Variant varminutes,Variant varseconds)
    throws HpException
    {
    HCDateTimeStruct	    tm;
    double   hours, minutes,seconds;

    hours = hpstring.get_db( varhours );
    if( hours>0.5 || hours<-0.5 )
        hours = (double)hpstring.dbl2int( hours);

    minutes = hpstring.get_db( varminutes );
    if( minutes>0.5 || minutes<-0.5 )
        minutes = (double)hpstring.dbl2int( minutes );

    seconds = hpstring.get_db( varseconds );
    if( seconds>0.5 || seconds<-0.5 )
        seconds = (double)hpstring.dbl2int(seconds );

    if(     hours>32767     || hours<-32768     ||
            minutes>32767   || minutes<-32768   ||
            seconds>32767   || seconds<-32768   )
        throw new HpException( 6, "Overflow");

    double  total = hours/24 + minutes/(24*60)+ seconds/(24*60*60);

    return new VDate(total);
    }

    /**DateSerial( year,month,day)
	 *Returns a Date for a specified year, month, and day.
	 */
    public static Variant DATESERIAL(Variant varyear,Variant varmonth,Variant varday)
       throws HpException
    {
	double	    dbl=0 ;
    int         i=0;
    HCDateTimeStruct    tm = new HCDateTimeStruct();
    int         year=0, month=0,day=0;

    year = hpstring.dbl2int( hpstring.get_db( varyear ) );
    month = hpstring.dbl2int( hpstring.get_db( varmonth) );
    day = hpstring.dbl2int( hpstring.get_db( varday));

	/* separate invalied argument */
	if ( year > 9999 && month > 0 )
        throw new HpException(6,"Overflow");
	if ( month > 32767 || month < -32768 )
        throw new HpException(6, "Overflow") ;
	if ( day > 32767 || day < -32768 )
	    throw new HpException(6,"Overflow") ;

	/* year */
 	if ( (year > 0 && year <= 99) /*|| (year < 0 && year>=-1901) */)
		year +=1900;

	/* month */
	if ( month < 0 )
	{
		year = year + (int)(month / 12) - 1 ;
		month = 12 + month % 12 ;
     	if ( year > 0 && year <= 99 )
		    year +=1900;
	}
	else if ( month == 0 )
	{
		month = 12 ;
		year -- ;
     	if ( year > 0 && year <= 99 )
		    year +=1900;
	}
	else if ( month > 0 )
	{
		year = year + (int)(month / 12) ;
		if ( month%12 == 0 )
		{
			month = 12 ;
			year -- ;
            if ( year > 0 && year <= 99 )
                year +=1900;
        }
		else
			month = month%12 ;
    }

 	/* get double value of year argument */
    if( year<=0 )
	    year +=1900;
	if ( year > 1899 )
	{
		for ( i=1900; i<year ;i++ )
		{
    		dbl += 365 ;
    		if ( (i%4 == 0 && i%100 != 0) || (i%400 == 0) )
    			dbl ++ ;
		}
	}
	else
	{
		for ( i=1899 ; i>year ; i-- )
		{
    		dbl -= 365 ;
    		if ( (i%4 == 0 && i%100 != 0) || (i%400 == 0) )
    			dbl -- ;
		}
	}

    /* get double value of month argument */
	if ( year > 1899 )
	{
		for ( i=1 ; i<month ; i++ )
		dbl += tm.Month_Day(year,i) ;
	}
	else
	{
		for ( i=12 ; i>month ; i-- )
		dbl -= tm.Month_Day(year,i) ;
	}
	/* get double value of day argument */
	if ( year > 1899 )
		dbl += day+1 ;
	else
		dbl = dbl - (tm.Month_Day(year,month) - day) + 1 ;

	if(dbl< -657435 || dbl > 2958465 )
		throw new HpException(6, "Overflow") ;

    return new VDate(dbl);
    }

    /**
	 *DateValue(date)
	 *Returns a Date.
	 */
    public static HDate DATEVALUE(Variant exp) throws HpException
    {
    String       str;
    UdtDatetime  udt=new UdtDatetime();
    int[]        standdt;
    double       dbl;

    str = hpstring.get_str(exp);
    standdt = udt.DtFormat(str);
    if( standdt==null)
        throw new HpException(13,"Type mismatch");
    dbl = udt.StrToDbl(standdt);
    if(dbl < -657435 || dbl > 2958465)
       throw new HpException(5,"Invalid procedure call");

    return new HDate(dbl);
    }

    public static HDate DATEVALUE(boolean  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate DATEVALUE(HByte  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate DATEVALUE(short  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate DATEVALUE(int  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate DATEVALUE(float  exp) throws HpException
    {
        UdtDatetime udt=new UdtDatetime();
        String      str = Float.toString(exp);

        int[]      standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");
        double dbl = udt.StrToDbl(standdt);
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        return new HDate( dbl);
    }

    public static HDate DATEVALUE(double  exp) throws HpException
    {
        UdtDatetime udt=new UdtDatetime();
        String      str = Double.toString(exp);

        int[]      standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");
        double dbl = udt.StrToDbl(standdt);
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        return new HDate( dbl);
    }
    public static HDate DATEVALUE(HCurr  exp) throws HpException
    {
        UdtDatetime udt=new UdtDatetime();
        String      str = Double.toString(exp.dblValue() );

        int[]      standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");
        double dbl = udt.StrToDbl(standdt);
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        return new HDate( dbl);
    }
    public static HDate DATEVALUE(HDate  exp) throws HpException
    {
        return new HDate(exp.dblValue());
    }
    public static HDate DATEVALUE(fixedString  exp) throws HpException
    {
        double dbl = getdt_db(new VString(exp.strValue() ) );
        return new HDate(dbl);
    }
    public static HDate DATEVALUE(String  exp) throws HpException
    {
        double dbl = getdt_db( (Variant)(new VString(exp) ));
        return new HDate(dbl);
    }


    /**
	 *TimeValue(date)
	 *Returns a Date containing the time.
	 */
    public static HDate TIMEVALUE(Variant exp) throws HpException
    {
        String       str;
        UdtDatetime  udt=new UdtDatetime();
        int[]        standdt;
        double       dbl;


        str = hpstring.get_str(exp);
        standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");

        dbl = udt.StrToDbl(standdt);

        if(dbl < -657435 || dbl > 2958465)
            throw new HpException(95,"Invalid procedure call");

        dbl -= Math.floor( dbl);

        return new HDate(dbl);
    }

    public static HDate TIMEVALUE(boolean  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate TIMEVALUE(HByte  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate TIMEVALUE(short  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate TIMEVALUE(int  exp) throws HpException
    {
        throw new HpException(13,"Type mismatch");
    }
    public static HDate TIMEVALUE(float  exp) throws HpException
    {
        UdtDatetime udt=new UdtDatetime();
        String      str = Float.toString(exp);

        int[]      standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");
        double dbl = udt.StrToDbl(standdt);
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        dbl -= Math.floor( dbl);
        return new HDate(dbl);
    }
    public static HDate TIMEVALUE(double  exp) throws HpException
    {
        UdtDatetime udt=new UdtDatetime();
        String      str = Double.toString(exp);

        int[]      standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");
        double dbl = udt.StrToDbl(standdt);
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        dbl -= Math.floor( dbl);
        return new HDate(dbl);
    }
    public static HDate TIMEVALUE(HCurr  exp) throws HpException
    {
        UdtDatetime udt=new UdtDatetime();
        String      str = Double.toString(exp.dblValue());

        int[]      standdt = udt.DtFormat(str);
        if( standdt==null)
            throw new HpException(13,"Type mismatch");
        double dbl = udt.StrToDbl(standdt);
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        dbl -= Math.floor( dbl);
        return new HDate(dbl);
    }
    public static HDate TIMEVALUE(HDate  exp) throws HpException
    {
       	double  dbl = exp.dblValue();
        if(dbl < -657435 || dbl > 2958465)
           throw new HpException(5,"Invalid procedure call");

        dbl -= Math.floor( dbl);
        return new HDate(dbl);
    }
    public static HDate TIMEVALUE(fixedString  exp) throws HpException
    {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?