Time

Handle time values

Arguments

$datestring
Time in various string formats:
h:m:s
Time -string: now
Timestamp: Y-m-d H:i:s (gets only time)
fieldtype: Kello, Kesto, Aikaleima (only time)

Example

Get total time from various inputs:

$totalTime = $this->get('time')
  ->addTime('1:15')
  ->addTime('2h')
  ->addSeconds(600);
// --> 02:25

Set time

You can give target time as a second parameter. Time can be in many formats: The given value is interpreted accordingly.

h:m:s        $this->get('time','02:00');
Hour float   $this->get('time',2.5);
Time -string $this->get('time','now');

Get time of value in time -field

You can create new eTime -object of time or timestamp with Field::getTime() -method.

$endTime = $Task->start_time->getTime()->addHours(2);

You can get reference to eTime -object of field value with Field::getTimeReference() method. Add 14 days to value in field:

$Task->start_time->getTimeReference()->addHours(2);

Or calling eTime methods directly through time field object:

$Task->start_time->addHours(2);

Modify time

You can create a time and then change its value with modifier -methods:

Two hours from now is  $this->get('time','now')->addHours(2);
Time + duration        $this->get('time','02:15')->addTime('00:45'); // --> 03:00
Full hours             $this->get('time','02:15')->setMinutes(0); // --> 02:00

Add time periods

Add multiple times                $this->get('time')->addValues(time1,time2);
Add difference of two times       $this->get('time')->addTimePeriod(start,end);
Subtract difference of two times  $this->get('time')->subTimePeriod(start,end);

Full method list

Setting time

Method Return type Description
setValue(value) this Set time from value.
clear() this Set time as 0.

Modifying time

Method Return type Description
addValue(value) this Add time from value.
addValues(value,value,...) this Add multiple values to time.
addTime(value) this Add time from value.
subtractTime(value) this Add time from value.
addTimePeriod(start,end) this Add difference from two time -values.
subtractTimePeriod(start,end) this Subtract difference from two time -values.
addHour() this Add 1 hour to time.
addMinute() this Add 1 minute to time.
addSecond() this Add 1 second to time.
addHours(int) this Add hours to time.
addMinutes(int) this Add minutes to time.
addSeconds(int) this Add seconds to time.
setHours(int) this Set time hours to given value.
setMinutes(int) this Set time minutes to given value.
setSeconds(int) this Set time seconds to given value.
addOverlap(min,max,start,end) this Count seconds from start-end that overlaps with min-max and add them to time.

Getting time information

Method Return type Description
isGiven() bool Return TRUE, if time has a value.
getTime() string Time in hh:m[:ss] format. (Seconds are shown if seconds > 0)
getHm() string Time in hh:mm
getHours() int Get h:m:s hours.
getMinutes() int Get h:m:s minutes.
getSeconds() int Get h:m:s seconds.
toHours() float Get time in hours.
toMinutes() float Get time in minutes.
toSeconds() float Get time in seconds.

Comparing times

Compare to other time Return type Description
isSame(time,[unit]) bool TRUE, if time is same as given time.
isUnder(time,[unit]) bool TRUE, if date is before given date.
isUnderOr(time,[unit]) bool TRUE, if date is before or the given date.
isOver(time,[unit]) bool TRUE, if date is after given date.
isOverOr(time,[unit]) bool TRUE, if date is after or the given date.
isBetween(time,time,[unit]) bool TRUE, if date is between or a given date.
time
Comparison time in any eTime create -format.
unit
Comparison unit: second, minute, hour, day
Default: minute
Comparison value Return type Description
getDayValue() int Comparison value in accuracy of full days.
getHourValue() int Comparison value in accuracy of full hours.
getMinuteValue() int Comparison value in accuracy of full minutes.
getSecondValue() int Comparison value in accuracy of second.

Static helper functions

Method Return type Description
::getOverlap($min,$max,$start,$end) int Count seonds from start-end that overlaps with min-max.
::getTimeArrayFrom($val) array Get Array(h,m,s) from given time value.
::getSecondsFrom($val) int Get seconds from given time value.
::getMinutesFrom($val) int Get minutes from given time value.
::getTimeFromSeconds($sec) string Seconds to hh:mm:ss
::getSecondsFrom(value) int Get seconds from various time formats. See setValue()
::hoursToTime($hours) string Hours to hh:mm:ss