Hi!
Currently, I am doing something like this:
{exp:myplug}{entry_date}{/exp:myplug}I then manipulate entry_date and return a value. Pretty basic.
What I would like to do:
{exp:myplug timestamp="%Y %m %d"}{date}, {time}, {other}{/exp:myplug}…and:
{exp:myplug timestamp="entry_date"}{date}, {time}, {other}{/exp:myplug}…and/or:
{exp:myplug timestamp="{some_date_variable}"}{date}, {time}, {other}{/exp:myplug}Where I then return values to the tags inside the plugin tag pair for more flexibility.
Basically I want to give the users the most flexibility for when it comes to passing my plugin a valid timestamp (not necessarily from the channel entries tag) and then I want to make it easy for them to use the return values in their template.
I just don’t know how to handle the “timestamp” parameters like I show above… Is the above example even a good idea?
Any tips would be spectacular!
I am currently trying to dissect as many date/time plugs as I can… Could you point me towards a plugin, or docs, that do something similar to my examples above?
Alternatively, is there a better/standardized approach to what I am trying to do?
Thanks! Micky
Ugh, when I use php’s date() function on {entry_date}, the date/time value is several hours off… I tried using some of the EE built-in localize methods, but it seems like they all want to localize to the current logged-in user, and not the TZ of the EE installation.
I am guessing that I don’t know enough about how dates work in EE to figure this one out… I am sure I could find a PHP solution to get the TZ corrected, but there has to be an easy way to get EE to help me out on this one?
Any tips?
Thanks! Micky
When I replace PHP’s date() with $this->EE->localize->decode_date() I get the localized time…
I guess I am confused about how decode_date() works. When I log out of EE, the date value printed on the page stays the same… I assumed that the localization of decode_date() was based on the current logged-in user?
decode_date calls set_localized_time() which says this:
“Converts GMT time to the localized values of the current logged-in user”
So, why does the date stay the same when I log out? Can I use this to localize the date to the EE installation and not the “current logged-in user”?
Anyone out there? :D
Thanks! Micky
After having thought about it a little more, I think my problem is with my understanding of how localization is supposed to work.
After a little bit of sleuthing, I discovered that my installation’s localization server timezone was not set to the timezone of the physical location of the server… I had it set to -8 pacific time (my timezone), when it should have been -5 eastern (server timezone)!
Next, I checked my login timezone, and that was set to -8 pacific. This is how it should be… No problems here.
When I change my login TZ to another timezone, the date output generated by $this->EE->localize->decode_date() changes with the change in zone.
Not sure if I am making any sense… Part of me feels like date() is much cleaner to write than $this->EE->localize->decode_date(), but the latter appears to be giving me the results I want vs. the former.
For example:
$t = date('H:i', $this->timestamp);$t = $this->EE->localize->decode_date('%H:%i', $this->timestamp);I use the decode_date method in several locations (in place of date()) and it just seems like I might be going overboard with its usage… Then again, it is just a simple method call.
Anyway, I will post a link to my plugin as soon as I have it finished just in case someone wants to give me a little feedback.
Cheers, Micky
Anyway, I will post a link to my plugin as soon as I have it finished just in case someone wants to give me a little feedback.
Not that anyone is listening… But what the heck! Here’s the plugin.
I call it APStylee… Brief description:
This ExpressionEngine v2 plugin converts a timestamp into an Associated Press style formatted date and time.
I am open to feedback.
Cheers! Micky
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.