Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FoxTools and the undocumented FoxTouch()

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,333
FR
I needed to set a file Date / Time stamp back to what it was before I added a barcode to a pdf file.

I opted to use FoxTouch() which is in the FoxTools.fll

This has one niggle, it adopts a 'bias' when you set the time stamp, so in the UK right now
if I used FoxTouch to save the file at 17:48, it would actually set it to 18:48.

I tried to get the bias from the TimeZoneInformation, but could not get it to work at all.
So, I reasoned that I could calculate it from the new file time stamp anyway...

Thus, all you have to do is test to see if the time you got was different to the time you hoped for.
If it is, calculate how far out it is and deduct that from the time you want and then set it again.

Code:
FUNCTION MyTouch
	PARAMETERS m.FileName,m.WasFTime
	PRIVATE m.FileName,M.WasFTime, M.NowFDate, M.NowFTime, M.TimeDiff
	** Set the hours format to 24HR
	SET HOURS TO 24
	** Open up the FOXTOOLS - in the same folder as the executable (because the system puts it there if it isn't already)
	SET LIBRARY TO ("foxtools") additive
	** RESET THE TIME AND DATE BACK...
         =FOXTOUCH( m.FileName, YEAR(m.WasFTime),MONTH(m.WasFTime), DAY(m.WasFTime), HOUR(m.WasFTime), MINUTE(m.WasFTime), SEC(m.WasFTime))		
         ** FOXTOUCH INCLUDES A 'BIAS' THAT WILL PUT THE TIME WRONG... SO IF WE WORK OUT HOW FAR OUT IT IS WE CAN RETOUCH AND CORRECT
	m.NowFDATE = FDATE(m.FileName)
	m.NowFTIME = FTIME(m.FileName)
	m.NowFTIME = CTOT(STR(YEAR(m.NowFDATE),4,0)+"-"+alltrim(STR(MONTH(m.NowFDATE),2,0))+"-"+alltrim(STR(Day(m.NowFDATE),2,0))+"T"+m.NowFTIME)
	IF M.NOWFTIME <> M.WASFTIME
	    M.TIMEDIFF = M.NOWFTIME - M.WASFTIME
	    M.WASFTIME = M.WASFTIME - M.TIMEDIFF
	    =FOXTOUCH( m.FileName, YEAR(m.WasFTIME),MONTH(m.WasFTIME), DAY(m.WasFTIME), HOUR(m.WasFTIME), MINUTE(m.WasFTIME), SEC(m.WasFTIME))		
	ENDIF			
    
	RELEASE LIBRARY foxtools
RETURN(.T.)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
I know Mike, but I couldn't get that to work at all - just kept getting a blank for the bias.

Maybe it doesn't work in Windows 7 and above?
Or, more likely, I'm too stupid to get it to work!

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
AFAIK file times are UTC and so you can inversely use this to find out your time zone bias to UTC.

Bye, Olaf.
 
By the way:

FDATE(m.FileName,1) returns the datetime, so you won't need FTIME() and CTOT(), you already will have a datetime value, type "T".

It's just, that I always prevent CTOT or CTOD conversions, as they depend on too many date settings, even though VFP makes some right guesses, even if you have your MARK or HOURS or anything set differently.

Bye, Olaf.
 
Good thinking Olaf

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Code:
FUNCTION MyTouch
	PARAMETERS m.FileName,m.WasFTime
	PRIVATE m.FileName,M.WasFTime, M.NowFDate, M.NowFTime, M.TimeDiff
	** Set the hours format to 24HR
	SET HOURS TO 24
	** Open up the FOXTOOLS - in the same folder as the executable (because the system puts it there if it isn't already)
	SET LIBRARY TO ("foxtools") additive
	
	** RESET THE TIME AND DATE BACK...
         =FOXTOUCH( m.FileName, YEAR(m.WasFTime),MONTH(m.WasFTime), DAY(m.WasFTime), HOUR(m.WasFTime), MINUTE(m.WasFTime), SEC(m.WasFTime))		
         ** FOXTOUCH INCLUDES A 'BIAS' THAT WILL PUT THE TIME WRONG... SO IF WE WORK OUT HOW FAR OUT IT IS WE CAN RETOUCH AND CORRECT
	m.NowFTIME = FDATE(m.FileName,1)
	IF M.NOWFTIME <> M.WASFTIME
	    M.TIMEDIFF = M.NOWFTIME - M.WASFTIME
	    M.WASFTIME = M.WASFTIME - M.TIMEDIFF
	    =FOXTOUCH( m.FileName, YEAR(m.WasFTIME),MONTH(m.WasFTIME), DAY(m.WasFTIME), HOUR(m.WasFTIME), MINUTE(m.WasFTIME), SEC(m.WasFTIME))		
	ENDIF			
    
	RELEASE LIBRARY foxtools
RETURN(.T.)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
I get a positive Bias with this function:

And I get a negative value with this function:
Code:
clear 
strComputer = "."
objWMIService = GetObject("winmgmts:\\" + strComputer + "\root\cimv2")
colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem in colItems
    ? "Description of time zone in hours: " + objItem.Description
    ? "Daylight Name: " + objItem.DaylightName
    ? "Standard Name: " + objItem.StandardName
    ? "Offset in minutes: " +transform(objItem.Bias )
Next

But in either case I get a value (Windows 7)


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Thanks Mike,

I never tried the winmgmts technique and simply couldn't get a result with the other one...
But the method I've adopted seems to work well.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top