FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TimeToSecs() and SecsToTime()
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
TimeToSecs() and SecsToTime()
Posted: Mon Nov 24, 2014 06:52 AM
Not sure if there are already some functions to do this. Anyhow I have implemented them and I appreciate your tests. Not sure if it is fine yet, thanks!

timesecs.prg
Code (fw): Select all Collapse
#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   MsgInfo( SecsToTime( TimeToSecs( "15:30:00" ) - TimeToSecs( "12:00:00" ) ) )

return nil

//----------------------------------------------------------------------------//

function TimeToSecs( cTime )

return Val( SubStr( cTime, 1, 2 ) ) * 3600 + ;
       Val( SubStr( cTime, 4, 2 ) ) * 60 + ;
       Val( SubStr( cTime, 7, 2 ) )

//----------------------------------------------------------------------------//

function SecsToTime( nTimeInSecs )

   local nHours := Int( nTimeInSecs / 3600 )
   local nMins  := Int( nTimeInSecs % 3600 / 60 )
   local nSecs  := Int( nTimeInSecs - ( nHours * 3600 ) - ( nMins * 60 ) )

return StrZero( nHours, 2 ) + ":" + StrZero( nMins, 2 ) + ":" + ;
       StrZero( nSecs, 2 ) 

//----------------------------------------------------------------------------//
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TimeToSecs() and SecsToTime()
Posted: Mon Nov 24, 2014 01:52 PM

TimeToSec( cTime ) and SecToTime( nSecs ) are already available in (x)Harbour in CT.LIB / HBCT.LIB
( These functions were available in CA-Tools in the DOS Clipper days )

I feel we need not duplicate the same functions in FWH libs

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TimeToSecs() and SecsToTime()
Posted: Mon Nov 24, 2014 05:09 PM

Rao,

Yes, you are right, thanks :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 389
Joined: Mon Oct 13, 2008 11:26 AM
Re: TimeToSecs() and SecsToTime()
Posted: Tue Nov 25, 2014 10:19 AM

? Time() // 00:00:15
? Secs( Time() ) //15
? TString( Secs( Time() ) ) // 00:00:15

Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2

Continue the discussion