Can get proper format at form/controller of entities

Hi,

I am using afterFetch() to manipulate my data for my needs. Example: I convert the English date to a German date:

        public function afterFetch() {
            $this->date = (new \DateTime($this->date))->format('d.m.Y');
        }

How can I get the original date now without to reconvert it? I need the original English date from my database. afterFetch seems to overwrite all other methods I am trying to set.

Thanks!

edited Aug '16

You just need to reconvert it, you can't have both values at once in one property.... You can either store object or string in model or display string in view etc.

Yo just need to change your LOGIC, model has don't ANYTHING about how you store your date, it shouldn't matter if you have string or object beacause you are working on it somewhere else.



3.9k
edited Aug '16

Hey again,

you got some nice endurance ;)

I allready followed your logic: I don't use setters and getters anymore, but converting my properties just feels so ugly :) When I have the original date available in my database. It' like:

Y-m-d->d.m.Y->Y-m-d->d.m.Y
// Database->Model->Calculations->View

But if you say that there is no other way, I have to do it.

I mean change your logic to store always one type of date. Why exactly in calculations you need Y-m-d ?



3.9k

True, I could that for the date but do you remember my duration entity? You can only store time in format hh:mm:ss:msmsmsms, which I don't need.

edited Aug '16

Then change it to store in other format. Just change your whole logic.



3.9k
edited Aug '16

Sorry, that doesn't really help. I am trying to get an answer what logic would be sophisticate for my problem.