QTP中时间的处理(转)

上一篇 / 下一篇  2010-01-28 20:23:22 / 个人分类:QTP

自动化测试中,经常遇到页面需要输入时间,而这个时间很多时候是当前时间之后某个范围之类才有效。我们采用数据驱动时如果采用绝对时间,则数据复用性就很差了,数据需要经常修改。所以采用相对时间

 

下面的函数用于获取相对时间

'------------------------------------------------------------------------

'获取以当前时间为参照的偏移时间

'increTime: 偏移时间量,可使用负数 格式:day:hour:min:sec  如 1:3:8:23

'------------------------------------------------------------------------

Public Function GetTime(byval increTime)

       Dim y,m,d,h,n,s,timeArray

      

       timeArray = split(increTime,":",-1,1)

       d= timeArray(0)

       h= timeArray(1)

       n= timeArray(2)

       s= timeArray(3)

      

       GetTime = dateadd("d",d,now)

       GetTime = dateadd("h",h,GetTime)

       GetTime = dateadd("n",n,GetTime)

       GetTime = dateadd("s",s,GetTime)

      

       ' change to GE Time type

       Dim dateArr,timeArr

       timeArray = split(GetTime," ",-1,1)

       dateArr = split(timeArray(0),"-",-1,1)

       y = dateArr(0)

       m = ExpandByZero("L", dateArr(1),2)

       d = ExpandByZero("L", dateArr(2),2)

      

       timeArr = split(timeArray(1),":",-1,1)

       h = ExpandByZero("L", timeArr(0),2)

       n = ExpandByZero("L", timeArr(1),2)

       s = ExpandByZero("L", timeArr(2),2)

      

       GetTime = y  & "-" & m & "-" & d & " " & h & ":" & n & ":" & s

 

End Function

'------------------------------------------------------------------------

'以0扩展当前字符串

'way: 扩展方式 L-左扩,R-右扩

'OrigStr: 原字符串

'HopeLen: 扩展后字符长度

'------------------------------------------------------------------------

Public Function ExpandByZero(byval way,byval OrigStr,byval HopeLen)

   Dim i,ZeroStr

   ZeroStr = ""

   For i =1 to HopeLen - len(OrigStr)

              ZeroStr = ZeroStr & "0"

   Next

   If way = "L" Then

              ExpandByZero = ZeroStr & OrigStr

       elseif way = "R" Then

              ExpandByZero = OrigStr & ZeroStr

       else

              Exit Function

   End If

End Function


TAG:

 

评分:0

我来说两句

Open Toolbar