Guidance
指路人
g.yi.org
software / rapidq / Examples / Date & Time / timestamp.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
' This is freeware to help Rapid-Q users to enjoy the power of that great
' Basic language, note that use in your own risk.
' Any update of this file please keep full backward compatibility and
' upload to: http://g.yi.org/f.php?f=7306
' Created by Guidance 2002-10-23

' This file implemented timestamp for Win32 in Rapid-Q, it's a double number
' with resolution 1 stands for 100nS, since January 1, 1601. With that timestamp, you
' can easily compare or
' add/minus dates and so on. Because the Win32 filetime resolution is 100nS
' with 64-bit int which can not be handled by Rapid-Q directly, I have to use a
' double instead, however, it's accurate enough now.

' Usage:
'  Now()                  -- function to get current timestamp
'  FileDateTime(filename) -- function to get file last modify timestamp
'  DayDiff(day_from,day_to)
'                         -- gets the days between day_from and day_to

' dword is same with long under windows!
     DECLARE FUNCTION DeleteFile LIB "kernel32.dll" ALIAS "DeleteFileA" (BYVAL lpFileName AS STRING) AS LONG

'Platforms: Win 32s, Win 95/98, Win NT

'DeleteFile deletes a file completely -- it does not send it to the Recycle Bin.
'It also doesn't prompt to confirm the deletion, so use it carefully.
'The function returns 1 if successful, or 0 if an error occured (most likely the file doesn't exist).

'lpFileName
'The name of the file to delete.
     DECLARE FUNCTION CloseHandle LIB "kernel32" ALIAS "CloseHandle" (BYVAL hObject AS LONG) AS LONG

' The FILETIME structure holds a date and time associated with a file.
' The structure identifies a 64-bit integer specifying the number of 100-nanosecond intervals
' which have passed since January 1, 1601.
' This 64-bit value is split into the two dwords stored in the structure.
     TYPE FILETIME
      dwLowDateTime AS DWORD'Long
      dwHighDateTime AS DWORD'Long
     END TYPE
'GetFileTime determines the times and dates of creation, last access,
' and last modification (write-to) of a file.
' Each of these times are placed in the corresponding structures passed to
' the function. All times obtained by the function are in UTC time
' (Coordinated Universal Time, a.k.a. Greenwich Mean Time (GMT)),
' not in the system's local time. Note that, depending on the operating system,
' the exact resolution of file times may vary -- the file times obtained by
' the function may not correspond to the actual date and time of
' creation/access/modification simply because the operating system does not
' store the information that precisely.

'Return Value
'If an error occured, the function returns 0 (use GetLastError to get the
' error code). If successful, the function returns a non-zero value.
     DECLARE FUNCTION GetFileTime LIB "kernel32.dll" ALIAS "GetFileTime" (BYVAL hFile AS LONG,byref lpCreationTime AS FILETIME,byref lpLastAccessTime AS FILETIME,byref lpLastWriteTime AS FILETIME) AS LONG

'CompareFileTime compares two times stored in FILETIME format.
' The function determines which of the two times, if any,
' comes before the other chronologically.
' If the first time is earlier than the second time, the function returns -1.
' If the two times are equal, the function returns 0.
' If the first time is later than the second time, the function returns 1.

'lpFileTime1
'The first of the two times to compare.
'lpFileTime2
'The second of the two times to compare.
     DECLARE FUNCTION CompareFileTime LIB "kernel32.dll" ALIAS "CompareFileTime" (lpFileTime1 AS FILETIME, lpFileTime2 AS FILETIME) AS LONG

'GetSystemTimeAsFileTime retrieves the current system date and time
' and places it into a FILETIME structure.
' The system time is always reported in UTC time (Coordinated Universal Time,
' a.k.a. Greenwich Mean Time (GMT)).
     DECLARE SUB GetSystemTimeAsFileTime LIB "kernel32.dll" ALIAS "GetSystemTimeAsFileTime" (byref lpSystemTimeAsFileTime AS FILETIME)
     DECLARE FUNCTION GetFileSize LIB "kernel32.dll" ALIAS "GetFileSize" (BYVAL hFile AS LONG, byref lpFileSizeHigh AS LONG) AS LONG
'GetFileSize determines the size of the file. The file size is given in a
' 64-bit value that is split into two 32-bit values. The high-order half is
' put into the variable passed as lpFileSizeHigh; the low-order half is
' returned by the function. To get the size, you can either put the binary or
' hexadecimal values of the two variables side-by-side, or use the formula
' filesize = lpFileSizeHigh * 2^32 + return value. If an error occurs, the
' function instead returns -1.

'hFile
'A handle to the file to determine the size of. The file must be opened with
' at least either read-level or write-level access.
'lpFileSizeHigh
'Variable that receives the high-order half of the file size.
     Public CONST OPEN_EXISTING = 3
     Public CONST FILE_SHARE_READ = &H1
     Public CONST GENERIC_READ = &H80000000
     TYPE SECURITY_ATTRIBUTES
      nLength AS LONG
      lpSecurityDescriptor AS LONG
      bInheritHandle AS LONG
     END TYPE
     DECLARE FUNCTION CreateFile LIB "kernel32" ALIAS "CreateFileA" (BYVAL lpFileName AS STRING, BYVAL dwDesiredAccess AS LONG, BYVAL dwShareMode AS LONG, lpSecurityAttributes AS SECURITY_ATTRIBUTES, BYVAL dwCreationDisposition AS LONG, BYVAL dwFlagsAndAttributes AS LONG, BYVAL hTemplateFile AS LONG) AS LONG
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''functions''''
     CONST bit32 AS DOUBLE=2^32
     CONST bit31 AS DOUBLE=2^31
     FUNCTION timestamp(t AS filetime) AS DOUBLE
      DEFDBL dlow=(t.dwLowDateTime AND &h7fffffff),dhigh=t.dwHighDateTime*bit32
      IF (t.dwLowDateTime AND &h80000000)<>0 THEN dlow+=bit31
      timestamp=dhigh + dlow
     END FUNCTION
     CONST dayticks AS DOUBLE =24*60*60*1000*10000
'const hourticks as double =60*60*1000*10000
'const minuteticks as double =60*1000*10000
     FUNCTION daydiff(dd1 AS DOUBLE,dd2 AS DOUBLE) AS DOUBLE ' unit: day
      daydiff=(dd2-dd1)/dayticks
     END FUNCTION
     FUNCTION FileDateTime(f AS STRING) AS DOUBLE
      DIM t1 AS filetime,t2 AS filetime, t3 AS filetime
      DEFLNG fh
      fh=createfile(f,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING, _
       FILE_ATTRIBUTE_ARCHIVE OR FILE_ATTRIBUTE_HIDDEN OR FILE_ATTRIBUTE_READONLY _
       OR FILE_ATTRIBUTE_SYSTEM,0)
      IF getfiletime(fh,t1,t2,t3)=0 THEN
       filedatetime=0
      ELSE
       filedatetime=timestamp(t3)
      END IF
      closehandle fh
     END FUNCTION
     FUNCTION now() AS DOUBLE
      DIM t0 AS filetime
      GetSystemTimeAsFileTime(t0)
      now=timestamp(t0)
     END FUNCTION
     FUNCTION filelen(f AS STRING) AS LONG
      DEFLNG fh,sizeh',sizel ' just ignore the low 32 bits
      fh=createfile(f,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING, _
       FILE_ATTRIBUTE_ARCHIVE OR FILE_ATTRIBUTE_HIDDEN OR FILE_ATTRIBUTE_READONLY _
       OR FILE_ATTRIBUTE_SYSTEM,0)
      IF fh=-1 THEN
       result=-1
      ELSE
       result= getfilesize(fh,sizeh)
      END IF
      closehandle fh
     END FUNCTION
掌柜推荐
 
 
¥477.00 ·
 
 
¥918.00 ·
 
 
¥370.00 ·
 
 
¥271.00 ·
 
 
¥995.00 ·
 
 
¥1,580.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2004-01-11 12:41:45