* FUNCTION: UTC_Time.prg * Author: George Tasker * Date: December 18, 1999 - 11:28 AM * Purpose: Converts a Date/Time value to * Universal Coordinated Time LPARAMETER tDateTime LOCAL ltresult, loConvert, lcsystime,; lcfiletime SET PROCEDURE TO Con_Time ADDITIVE loConvert = CREATEOBJECT('ConvertTime') RELEASE PROCEDURE Con_time lcfiletime = loConvert.SystemToFileTime(tDateTime) lcfiletime = loConvert.LocalToFileTime(lcfiletime) lcsystime = loConvert.FileTimeToSystem(lcfiletime) ltresult = loConvert.SystemToDateTime(lcsystime) ltresult = ltresult + (loConvert.Get_Bias(ltresult) * 60) loConvert = NULL RETURN ltresult DEFINE CLASS ConvertTime AS CUSTOM * Converts to and from FILETIME to SYSTEMTIME * structures oInteger = "" PROCEDURE Init SET PROCEDURE TO CON_INT ADDITIVE This.oInteger = CREATEOBJECT("ConvertInt") RELEASE PROCEDURE CON_INT RETURN NOT ISNULL(This.oInteger) ENDPROC FUNCTION FileToLocalTime * Converts a FILETIME structure * from the system time (UTC) to the * local time LPARAMETER pcFileTime * A FILETIME structure DECLARE SHORT FileTimeToLocalFileTime IN Win32API; STRING @lpFileTime, STRING @lpLocalFileTime LOCAL lcresult, lcFileTime lcFileTime = pcFileTime lcresult = REPLICATE(CHR(0), 8) = FileTimeToLocalFileTime(@lcFileTime, @lcresult) RETURN lcresult ENDFUNC FUNCTION LocalToFileTime * Converts a local FILETIME structure * a UTC FILETIME structure LPARAMETER pcFileTime DECLARE SHORT LocalFileTimeToFileTime IN Win32API; STRING @lpLocalFileTime, STRING @lpFileTime LOCAL lcresult, lcfiletime lcfiletime = pcFileTime lcresult = REPLICATE(CHR(0), 8) = LocalFileTimeToFileTime(@lcfiletime, @lcresult) RETURN lcresult ENDFUNC FUNCTION SystemToFileTime LPARAMETER pdtvalue * Parameter is of type DATETIME DECLARE SHORT SystemTimeToFileTime IN Win32API; STRING @lpst, STRING @lpft LOCAL lcsystemtime, lcfiletime lcfiletime = REPLICATE(CHR(0), 8) lcsystemtime = This.CreateSystemTime(pdtvalue) = SystemTimeToFileTime(@lcsystemtime, @lcfiletime) RETURN lcfiletime ENDFUNC FUNCTION FileTimeToSystem * Converts a FILETIME structure * to a SYSTEMTIME structure LPARAMETER pcFileTime DECLARE SHORT FileTimeToSystemTime IN Win32API; STRING @lpFileTime, STRING @lpSystemTime LOCAL lcfiletime, lcresult lcfiletime = pcFileTime lcresult = REPLICATE(CHR(0), 16) = FileTimeToSystemTime(@lcfiletime, @lcresult) RETURN lcresult ENDFUNC FUNCTION CreateSystemTime LPARAMETER pdtvalue * Parameter is of type DATETIME LOCAL lcresult, lnyear, lnmonth,; lndow, lnday, lnhour, lnminute, lnsec,; lnsize lnsize = 2 lnyear = YEAR(pdtvalue) lnmonth = MONTH(pdtvalue) lndow = DOW(pdtvalue, 0) - 1 lnday = DAY(pdtvalue) lnhour = HOUR(pdtvalue) lnminute = MINUTE(pdtvalue) lnsec = SEC(pdtvalue) WITH This.oInteger lcresult = .IntegerToString(lnyear, lnsize) +; .IntegerToString(lnmonth, lnsize) +; .IntegerToString(lndow, lnsize) +; .IntegerToString(lnday, lnsize) +; .IntegerToString(lnhour, lnsize) +; .IntegerToString(lnminute, lnsize) +; .IntegerToString(lnsec, lnsize) +; .IntegerToString(0, lnsize) ENDWITH RETURN lcresult ENDFUNC FUNCTION SystemToDateTime LPARAMETER pcsystemtime * Parameter is a SYSTEMTIME structure LOCAL ldtresult, lcyear, lcmonth,; lcday, lchour, lcmin, lcsec, lnsize lnsize = 2 WITH This.oInteger lcyear = STR(.StringToInteger(LEFT(pcsystemtime, lnsize))) lcmonth = STR(.StringToInteger(SUBSTR(pcsystemtime, 3, lnsize))) lcday = STR(.StringToInteger(SUBSTR(pcsystemtime, 7, lnsize))) lchour = STR(.StringToInteger(SUBSTR(pcsystemtime, 9, lnsize))) lcmin = STR(.StringToInteger(SUBSTR(pcsystemtime, 11, lnsize))) lcsec = STR(.StringToInteger(SUBSTR(pcsystemtime, 13, lnsize))) ENDWITH ldtresult = CTOT("^" + lcyear + "/" +; lcmonth + "/" + lcday + "," + lchour +; ":" + lcmin + ":" + lcsec) RETURN ldtresult ENDFUNC FUNCTION ConvertFromFileTime LPARAMETER pcfiletime * A file's FILETIME structure * in UTC format LOCAL lcfiletime, ldtresult, lcsystemtime lcfiletime = This.FileToLocalTime(pcfiletime) lcsystemtime = This.FileTimeToSystem(lcfiletime) ldtresult = This.SystemToDateTime(lcsystemtime) RETURN ldtresult ENDFUNC FUNCTION ConvertToFileTime * Converts a DATETIME to a UTC FILETIME * structure LPARAMETER pdtDateTime LOCAL lcsystemtime, lcresult lcsystemtime = This.CreateSystemTime(pdtDateTime) lcresult = This.SystemToFileTime(lcsystemtime) lcresult = This.LocalToFileTime(lcresult) RETURN lcresult ENDFUNC FUNCTION Get_Bias LPARAMETER ttdatetime DECLARE INTEGER GetTimeZoneInformation IN Win32API; STRING @lpTimeZoneInformation LOCAL lnresult, lcTimeZone, ltdaylight, ltstandard,; lldtdaylight, lldtcurrent, ltcurrent, lcdaysystime,; lcstdsystime lnresult = 0 lctimezone = REPLICATE(CHR(0), 172) = GetTimeZoneInformation(@lctimezone) * Get the starting time for daylight savings lcdaysystime = SUBSTR(lctimezone, 153, 16) lcstdsystime = SUBSTR(lctimezone, 69, 16) ltdaylight = This.Date_Calc(lcdaysystime, ttdatetime) * Get the starting time for standard ltstandard = This.Date_Calc(lcstdsystime, ttdatetime) * Determine if an adjustment is necessary * Is the passed date/time daylight savings? lldtdaylight = BETWEEN(ttdatetime, ltdaylight, ltstandard) * Is it currently daylight savings? ltcurrent = DATETIME() * Different years? IF YEAR(ltcurrent) # YEAR(ttdatetime) lldtcurrent = BETWEEN(ltcurrent, This.Date_Calc(lcdaysystime, ltcurrent),; This.Date_Calc(lcstdsystime, ltcurrent)) ELSE lldtcurrent = BETWEEN(ltcurrent, ltdaylight, ltstandard) ENDIF IF lldtdaylight AND NOT lldtcurrent * This compensates for a date/time that's during * daylight savings when the current period is * standard time lnresult = This.oInteger.StringToInteger(RIGHT(lctimezone, 4), .T.) ELSE IF NOT lldtdaylight AND lldtcurrent * This compensates for a date/time that's * standard time during daylight savings lnresult = ABS(This.oInteger.StringToInteger(RIGHT(lctimezone, 4), .T.)) ENDIF ENDIF RETURN lnresult ENDFUNC FUNCTION Date_Calc * Calculates the date of a time * change from Daylight or Standard time LPARAMETERS tcSysTime, ttdatetime LOCAL ltresult, lnyear, lndow, lnday,; lndow, lddate * Year of the change lnyear = YEAR(ttdatetime) * The month of the change lnmonth = This.oInteger.StringToInteger(SUBSTR(tcSysTime, 3, 2)) * Window's DOWs are zero based, VFP's 1 based lndow = This.oInteger.StringToInteger(SUBSTR(tcSysTime, 5, 2)) + 1 * Get the day - 1 or 5. * 1 = First occurance of the DOW * 5 = Last occurance of the DOW lnday = This.oInteger.StringToInteger(SUBSTR(tcSysTime, 7, 2)) lddate = This.AdjustDate(lnmonth, lndow, lnday, lnyear) * Create date/time ltresult = DATETIME(lnyear, lnmonth, DAY(lddate),; This.oInteger.StringToInteger(SUBSTR(tcSysTime, 9, 2))) RETURN ltresult ENDFUNC FUNCTION AdjustDate LPARAMETERS tnmonth, tndow, tnday, tnyear LOCAL ldresult, lddate * Get the first day of the month lddate = DATE(tnyear, tnmonth, 1) lllast = (tnday = 5) IF NOT lllast IF DOW(lddate) = tndow ldresult = lddate ELSE ldresult = lddate + (7 * tnday) - (DOW(lddate) - 1) ENDIF ELSE * Get the last date of the month lddate = GOMONTH(lddate, 1) - 1 IF DOW(lddate) = tndow ldresult = lddate ELSE ldresult = lddate - (DOW(lddate) - 1) ENDIF ENDIF RETURN ldresult ENDFUNC PROCEDURE Destroy This.oInteger = .NULL. RETURN ENDPROC ENDDEFINE DEFINE CLASS ConvertInt AS CUSTOM FUNCTION IntegerToString LPARAMETER pnInteger, pnbytes LOCAL lcresult, lnbytes, lnmask,; lninteger, lni, lnchar lcresult = "" IF PCOUNT() = 2 lnbytes = pnbytes ELSE * Default to DWORD lnbytes = 4 ENDIF lninteger = pnInteger lnmask = 255 FOR lni = 1 TO lnbytes lnchar = BITAND(lninteger, lnmask) lcresult = lcresult + CHR(lnchar) lninteger = BITRSHIFT(lninteger, 8) NEXT RETURN lcresult ENDFUNC FUNCTION StringToInteger LPARAMETER pcstring, plsigned LOCAL lnresult, lnlast, lni, llsigned,; lnmsb, lnmax lnresult = 0 lnlast = LEN(pcstring) * Return Signed Integer? IF PCOUNT() = 2 llsigned = plsigned ELSE llsigned = .F. ENDIF FOR lni = 1 TO lnlast lnresult = lnresult + ASC(SUBSTR(pcstring, lni, 1)) * (256 ^ (lni - 1)) NEXT IF llsigned lnmsb = (lnlast * 8) - 1 IF BITTEST(lnresult, lnmsb) lnmax = (2 ^ (lnmsb + 1)) lnresult = lnresult - lnmax ENDIF ENDIF RETURN lnresult ENDFUNC ENDDEFINESorry about the other post.