Alex
Alex

Reputation: 5904

PHP time and date functional vs object

I do have an old piece of PHP code (approximate 9 years) with a lot of time() and strtotime() calls. The main reason for that it was because of users being located in different timezones.

Now, I do see that a lot of people say that the new objectified library of PHP should be used instead of old/plain functions.

My question is: Did anyone who migrated code from using functional "date and time" API to the new object-oriented one encounter some big drawbacks or problems?

Upvotes: 2

Views: 106

Answers (2)

animaacija
animaacija

Reputation: 180

I would just store timestamps as GMT(0) all over the place, and before outputting, based on, where user is located I would reformat time value to user-fit-needs. i would get rid of whole PHP's date time ancient stuff but I would use only this call to it. Date('YdmHis'); so I could as previously stated just store timestamps all over the place. And use my CUSTOM class before outputting values.

Uh, and make sure to store Timestamp as GMT-0 so the reference point was at least consistent, and there you go, the best part of ancient code restructuring is when a new bloodline is created (computing power in novadays lets you not to delete old code but just write over and around it ... joke,)

Upvotes: 0

hek2mgl
hek2mgl

Reputation: 158060

Basically the old functions are still working. Also they don't have been marked as deprecated. The advantage of the new DateTime API is the improved or simplified functionality. As long as your old application does not need this additional functionality you wouldn't need to migrate to the DateTime API.

If you want to review the code and further develop it, I would encourage you to migrate to the DateTime API for the above reasons. The only drawback that I could see is the fact that you would need to rewrite that parts of the code - and(!) test it.

Upvotes: 2

Related Questions