namespace time; 
 
class ole{
    ctor( ... ) begin
        var tm = ..time(...);
        
        var arg = ...
        if(type(arg)==type.number){ 
            VariantTimeToSystemTime(arg,tm) 
        }
/*
        if(type(arg)==type.table)begin
            for(k,v in arg){
                tm[k] = arg[k]
            }  
        end;
        
*/
		//其目的为丢弃元表
        for(k,v in tm){
        	this[k] = v;
        }
         
    end; 
    
    @metabable
}

namespace ole{

	
	metabable = {
	
		//AAuto内核time对象是以秒为单位，而oletime是以天为单位，因些必须重载天、时、分、秒相关的加减运算
		addday = function(span){
			return self( tonumber(owner)+span )
		} 
		addhour = function(span){
			return self( ( tonumber(owner)/24 + span)*24 )
		} 
		addminute = function(span){
			return self( ( tonumber(owner)/1440 + span)*1440 )
		} 
		addsecond = function(span){
			return self( ( tonumber(owner)/86400 + span)*86400 )
		} 
		diffhour = function(tm2){
			return (tonumber(owner) -tonumber(tm2))  /24
		} 
		diffminute = function(tm2){
			return (tonumber(owner) -tonumber(tm2)) /1440
		} 
		diffsecond= function(tm2){
		   return (tonumber(owner) -tonumber(tm2))  /86400
		}
		diffday = function(tm2){
			return (tonumber(owner) -tonumber(tm2))  
		} 
		
		_tonumber = function(){
        	var re,n = SystemTimeToVariantTime(owner,0)
        	return n;
    	}
    	_type = "time.datetime.ole"
	}
	
	//继承time.datetime元表的其他功能
	var tm = ..time();
	for(k,v in tm@){
		if(!metabable[k]){
			metabable[k]=v;
		}
	}  
		      
    oleaut32 = ..raw.loadDll("oleaut32.dll")
    VariantTimeToSystemTime= oleaut32.api("VariantTimeToSystemTime","int(double vtime,struct& lpSystemTime)");
    SystemTimeToVariantTime= oleaut32.api("SystemTimeToVariantTime","int(struct lpSystemTime,double&pvtime)"); 
}

/*intellisense()
time.ole(.(__,"%Y/%m/%d %H:%M:%S") = 参数可以是时间数值、时间字符串、或其他datetime对象\n第二个参数指定格式化串,首字符为!表示GMT时间\n返回datetime对象
?time.ole =!time.
end intellisense*/



