Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Time Elapsed
Message
De
06/06/2002 10:06:12
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00665357
Message ID:
00665413
Vues:
15
Hi Ria

I have found the need to convert a specified time to seconds since midnight, seconds since midnight (Seconds() format) to a time, and to be able to increment a time value by a specified number of seconds. As such I have created functions to do these things. You may find them useful.
FUNCTION sec2time
	PARAMETERS m.lnSec2Convert
	*** converts seconds since midnight to time () format
	*** useful for adding seconds to a time
	PRIVATE m.lcStHours,m.lcStMinutes,m.lcStSeconds,m.lcDay
	m.lcDay = ""
	IF TYPE("m.lnSec2Convert") <> "N"
		m.lnSec2Convert = SECONDS()
	ENDIF
	IF m.lnSec2Convert < 0
		m.s2tzz = iif(mod(abs(m.lnSec2Convert),86400)= 0,0,1)+int(abs(m.lnSec2Convert)/86400)
		m.lnSec2Convert = m.lnSec2Convert+((m.s2tzz*24)*3600)
		m.lcDay = " *** -"+alltrim(str(m.s2tzz))+" days "
	ENDIF
	m.lcStHours = INT(m.lnSec2Convert/3600)
	m.lcStMinutes = INT(MOD(m.lnSec2Convert,3600)/60)
	m.lcStSeconds = INT(MOD(MOD(m.lnSec2Convert,3600),60))
	IF m.lcStHours > 24 .or. (m.lcStHours >=24 .and. m.lcStMinutes+m.thissecond > 0)
		*** seconds passed is more than 24 hour - return number of days+time
		m.lcDay = " *** +"+alltrim(str(int(m.lcStHours/24)))+" days "
		m.lcStHours = mod(m.lcStHours,24)
	ENDIF
	RETURN PADL(ALLTRIM(STR(m.lcStHours)),2,"0")+":"+;
		PADL(ALLTRIM(STR(m.lcStMinutes)),2,"0")+":"+;
		PADL(ALLTRIM(STR(m.lcStSeconds)),2,"0")+m.lcDay

	*!*----------------------------------------------------------------------------

FUNCTION time2sec
	PARAMETERS m.lcTime2Convert
	*** converts time() format to seconds since midnight format
	PRIVATE m.lnTsHours,m.lnTsMinutes,m.lnTsSeconds
	IF TYPE("m.lcTime2Convert") <> "C"
		m.lcTime2Convert = time()
	ENDIF
	m.lcTime2Convert = padr(m.lcTime2Convert,8)
	m.lnTsHours = val(left(m.lcTime2Convert,2))
	m.lnTsMinutes = val(substr(m.lcTime2Convert,4,2))
	m.lnTsSeconds = val(right(m.lcTime2Convert,2))
	IF m.lnTsHours > 24 .or. (m.lnTsHours >=24 .and. m.lnTsMinutes+m.lnTsSeconds > 0)
		m.lnTsHours = mod(m.lnTsHours,24)
	ENDIF
	RETURN (m.lnTsHours*3600)+(m.lnTsMinutes*60)+m.lnTsSeconds

	*!*---------------------------------------------------------------------------

FUNCTION INCREMENT_TIME
	parameters m.lcBegTime,m.lcSec2Add
	*!* increments a time value by a specified number of seconds
	return sec2time(time2sec(m.lcBegTime)+m.lcSec2Add)
HTH
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform