dype
December 19, 2016, 8:52pm
1
Cakephp 3
In the database, I have a TIME field “run” , the content of this field can be greater than 24:00:00, for example 54:22:11
How can I display this time ?
Cake always display the date of the day
Note thats it is ok for time value below 23:59:59
Thanks
A field that has the type TIME usually anticipates a time of day, for which values above 23:59:59 are invalid.
What you appear to have is an elapsed time, which may better be recorded as an INT for the number of seconds.
ah, reading the question properly, and you’re asking about the display of the value.
Most likely, the built in helpers will not assist, because they are expecting a time of day, rather than an elapsed time.
You’ll probably need to write your own function to convert seconds to an elapsed hours : minutes : seconds format.
dype
December 20, 2016, 6:44am
4
ok thanks, for your reply
I will have to write code, nothing magic with cake for my problem
Do i have a way to make a request withtime_to_sec
(the mysql command) ?
raz
December 20, 2016, 7:40am
5
You can define a custom accessor in your Entity such that every time you retrieve a row, it will automatically apply your changes to the data. (same with a mutator for saving your data)
Here is a link to the appropriate docs for CakePHP 3: http://book.cakephp.org/3.0/en/orm/entities.html#accessors-mutators
I’m looking for a similar solution. But the mutator is not doing what I expected. What’s wrong?
I have an integer duration field where I’m storing elapsed times in integer seconds.
For instance:
23 means 23 seconds
62 means 1 minute and 2 seconds
3600 means exactly one hour
I want to show the formatted elapsed time every time I’m showing this field, so I did this accesor:
protected function _getDuration($duration)
{
return isset($duration) ? (new FrozenTime($duration))->format('G:i:s') : '';
}
…and it works well with already saved data in the database.
So, th…