udfFileTimeCodeToYmdHms
udfYmdHmsToFileTimeCode
str udfFileTimeCodeToYmdHms (int)
int udfYmdHmsToFileTimeCode (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileTimeCodeToYmdHms (intTimeCode)
intSecs    = (intTimeCode & 31) * 2      ; Start 0  uses 5.
intMinutes = (intTimeCode >> 5) & 63     ; Start 5  uses 6.
intHours   = (intTimeCode >> 11) & 31    ; Start 11 uses 5.
intDays    = (intTimeCode >> 16) & 31    ; Start 16 uses 5.
intMonths  = (intTimeCode >> 21) & 15    ; Start 21 uses 4.
intYear    = (intTimeCode >> 25) + 1980  ; Start 25 uses 6 ; 1980 to 2043.
strSecs    = StrFixLeft (intSecs, 0, 2)
strMinutes = StrFixLeft (intMinutes, 0, 2)
strHours   = StrFixLeft (intHours, 0, 2)
strDays    = StrFixLeft (intDays, 0, 2)
strMonths  = StrFixLeft (intMonths, 0, 2)
Return intYear : ":" : strMonths : ":" : strDays : ":" : strHours : ":" : strMinutes : ":" : strSecs
;..........................................................................................................................................
; This Function "udfFileTimeCodeToYmdHms" returns a YmdHms DateTime string on a given FileTimeCode number.
;
; Conf:  WinBatch Script Exchange
; From:  Marty marty@winbatch.com
; Date:  Saturday, April 21, 2001 07:54 PM
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfYmdHmsToFileTimeCode (strFileYmdHms)
intYear    = ItemExtract (1, strFileYmdHms, ":")
intMonths  = ItemExtract (2, strFileYmdHms, ":")
intDays    = ItemExtract (3, strFileYmdHms, ":")
intHours   = ItemExtract (4, strFileYmdHms, ":")
intMinutes = ItemExtract (5, strFileYmdHms, ":")
intSecs    = ItemExtract (6, strFileYmdHms, ":")
Terminate (intYear < 1980, "udfYmdHmsToFileTimeCode", "Year out of range 1980..2043 (underflow).")
Terminate (intYear > 2043, "udfYmdHmsToFileTimeCode", "Year out of range 1980..2043 (overflow).")
intCode = 0
intCode = intCode + (intSecs / 2)
intCode = intCode | (intMinutes << 5)
intCode = intCode | (intHours << 11)
intCode = intCode | (intDays << 16)
intCode = intCode | (intMonths << 21)
intCode = intCode | ((intYear - 1980) << 25)
Return intCode
;..........................................................................................................................................
; This Function "udfYmdHmsToFileTimeCode" returns a FileTimeCode number on a given YmdHms DateTime string.
;
; Conf:  WinBatch Script Exchange
; From:  Marty marty@winbatch.com
; Date:  Saturday, April 21, 2001 07:54 PM
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
; Note:
; Differences between this filetime and that filetime can rely on ...
;  1. NTFS file systems can have more accurate file times than DOS systems (Granularity: DOS: 2 secs, NTFS: 1 sec).
;  2. FAT and FAT32 partitions have a file time resolutions of 2 seconds.
;  3. WinBatch uses 1 second resolution on NTFS systems.
;  4. No matter what the source, the resolution of FileTimeCode is 2 seconds, as it is based on a DOS timestamp.
;  5. You don't need FileTimeCode, as FileYmdHms values are directly comparable with standard comparison operators.
;  6. When you get a filetime in FileTimeCode format the time is truncated to an even second.
;  7. When you get a filetime of any kind of a FAT or FAT32 volume, it is *always* an even number of seconds.
;  8. A FileYmdHms() of a NTFS volume will give you 1 second resolution.
;     A FileTimeCode of a NTFS volume will lose the odd second if any.
;     So...basically 50% of the time the numbers will disagree.
;  9. Conversion script in separate message.
; 10. No bug. Thats just the way it is.
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strFilename = DirHome () : "WinBatch.exe"
intTimeCode = FileTimeCode (strFilename)
strFileYmdHms = FileYmdHms (strFilename)

strTestYmdHms = udfFileTimeCodeToYmdHms (intTimeCode)
intTestTimeCode = udfYmdHmsToFileTimeCode (strFileYmdHms)

strMsgTitle = "Demo: udfFileTimeCodeToYmdHms (intTimeCode) / udfYmdHmsToFileTimeCode (strFileYmdHms)"
strMsgText = 'Filename' : @LF : @TAB : '= ' : strFilename :  @LF
strMsgText = strMsgText : @LF :'FileTimeCode (Filename)' : @LF : @TAB : '= ' : intTimeCode
strMsgText = strMsgText : @LF :'FileYmdHms (Filename)' : @LF : @TAB : '= ' : strFileYmdHms : @LF
strMsgText = strMsgText : @LF :'udfFileTimeCodeToYmdHms (' : intTimeCode : ')' : @LF : @TAB : '= ' : strTestYmdHms
strMsgText = strMsgText : @LF :'udfYmdHmsToFileTimeCode ("' : strFileYmdHms : '")' : @LF : @TAB : '= ' : intTestTimeCode
Message (strMsgTitle, strMsgText)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------