TTime
Source: source/classes/time.prg
TTime represents a time value as seconds since midnight. It provides time arithmetic (add/subtract hours, minutes, seconds), formatting to "HH:MM:SS", and the ability to read the system clock or write the time back to the system clock. Internally the time is stored as a single numeric value (nTime) modulo 86400.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
nTime | Numeric | Seconds since midnight (0-86399) |
Methods
| Method | Description |
|---|---|
New( nHours, nMinutes, nSeconds ) | Create a TTime from hour/minute/second values. All default to 0 |
System() | Initialize from the current system clock time |
AddHours( n ) | Add n hours to the stored time |
AddMinutes( n ) | Add n minutes to the stored time |
AddSeconds( n ) | Add n seconds to the stored time |
cAdd( nH, nM, nS ) | Add a time duration and return the result as a formatted "HH:MM:SS" string |
cSub( nH, nM, nS ) | Subtract a time duration (or another TTime object) and return the formatted result |
cGetTime() | Return the stored time formatted as "HH:MM:SS" |
SysChange() | Set the system clock to the stored time value |
Example: Time Arithmetic
#include "FiveWin.ch"
function Main()
local oTime, cResult
// Create a time: 09:30:00
oTime := TTime():New( 9, 30, 0 )
// Add 2 hours and 15 minutes
cResult := oTime:cAdd( 2, 15, 0 )
MsgInfo( cResult ) // --> "11:45:00"
// Subtract 45 minutes
cResult := oTime:cSub( 0, 45, 0 )
MsgInfo( cResult ) // --> "11:00:00"
// Get current system time
oTime:System()
MsgInfo( "Current time: " + oTime:cGetTime() )
return nil
Notes
- All arithmetic operations wrap modulo 86400 (seconds in a day). Values exceeding 24 hours roll over.
cAdd()andcSub()modify the internalnTimeand return the new formatted string.cSub()can accept either numeric hour/minute/second values or another TTime object as its first parameter.SysChange()callsSysTime( ::nTime )to write the time to the system clock; this may require appropriate privileges.