Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Sessions.duration inside Model #1

Open
rogerpro opened this issue Jul 27, 2017 · 0 comments
Open

Format Sessions.duration inside Model #1

rogerpro opened this issue Jul 27, 2017 · 0 comments

Comments

@rogerpro
Copy link
Owner

The Sessions.duration field is saved in integer seconds. In order to be human readable, it needs to be converted to h:mm:ss format with:

(new FrozenTime($session->duration))->format('G:i:s')

It might happen that it has a null value. In this case, we need not to show a value (or show 0:00:00 at least). Without conversion, this null value will make FrozenTime constructor create a current timestamp value, which is not the goal here. This is solved like that:

isset($session->duration) ? (new FrozenTime($session->duration))->format('G:i:s') : ''

This conversion is done, right now, on the View layer, in many template files.

It would be more coherent, efficient and error-proof to get the final value right from the Model layer. With the only exception of model methods where we need to take the value to calculate with it. Anyway, right now the field is only summed inside custom finders, so since we take the value, we only need to pass it to the View.

TO DO: study the best way to achieve this, being it using a Behavior or other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant