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
New functions to add to API #4
Comments
Some thoughts: the function wp_date( $format, $timestamp = null, $timezone = null, WP_Locale $locale = null ) {} Would If i understand correctly $datetime = get_post_datetime();
$datetime->setTimezone( wp_timezone() ); Maybe developers should have the following options for the $d1 = get_post_datetime( null, 'date' ); // timezone from settings
$d2 = get_post_datetime( null, 'date_gmt' ); // UTC timezone
$d3 = get_post_datetime( null, 'modified' ); // timezone from settings
$d4 = get_post_datetime( null, 'modified_gmt' ); // UTC timezone |
This is the intent and what inline doc says. :)
No, upstream function is
No, the intent is to return object set to local time zone. I'll adjust inline doc. Against having argument for it, if something else is needed then object should be manipulated for it. |
I mean: why have a
👍
👍 I think i was confused about the note below the code:
|
Because users can already switch locale via interface, which gives implicit handling for it. User timezone is still under discussion though. Honestly I am not married to having a timezone arg. But at the moment if you want to adjust timezone you need to filter
That's about post field, i.e. implementation should read |
For EDD3, we’ve opted not to change any UTC values from the database (to either local or WordPress timezones) so that no reversing is necessary. The only time we apply any offsets are immediately before output, basically treating it like an escaping function. This way, all variable values are UTC, and all date/time output caters to the reader. We plan on doing the same with APIs. Provide UTC values, and let the application decide how to manipulate them. |
I am not sure I follow about "reversing". That function will just return a native Having the object in WP time zone makes more sense to me in WP mechanics, which primarily deals with WP time. Also going to UTC timezone is easier than going from UTC time zone, which requires fecthing/figuring out local time zone, and potentially user time zone (which is being discussed). In regards to API personally I'd output timestamps (for which time zone doesn't matter) or RFC3339 (for which time zone is included). Unfortunately WP REST API went with timezone-less local time and possibly missing UTC time, which is quite fragile and needs addressing too. |
The problem we discovered with that approach, is there is no way to know which variables floating around during runtime already had an offset applied to them, and it’s easy to accidentally re-apply the offset more than once. Too many WordPress functions misguidingly apply offsets in too many unexpected places. Going to or from UTC is the same static math either way, but knowing when to do so is impossible without strict rules. Late-escaping is a good example, because late-date-offsetting would work exactly the same, for the same reasons, and avoiding the same problems (double escaping being bad and all that.) |
I really don't follow. We are talking
We are dropping all that shit from core once there is unified timezone object retrieval in place.
We are done with manual date offsetting. It has to go. |
Some updates assuming targeting PHP 5.6 bump:
|
Dropped the override immutable flag. |
Split out |
Added |
|
|
|
Shelved time tag, since it's quite involved to implement generically as function call, but easy to template. |
And we are done with API (for now)! 🎉 |
This is a broad collection of what I envision to be added to Date/Time API.
Progress
wp_timezone_string()
wp_timezone()
wp_date()
get_post_datetime()
get_post_timestamp()
the_time_tag()
current_datetime()
wp_timezone_string()
We badly need unified timezone retrieval (from
gmt_offset
ortimezone_string
either) to get rid of offset math.wp_timezone()
We badly need unified timezone retrieval (from
gmt_offset
ortimezone_string
either) to get rid of offset math.wp_date()
date_i18n()
replacement that works of actual real Unix timestamps and also a little more flexible about timezone.get_post_datetime()
Get a DateTimeImmutable object for the post. Implementation should default to
gmt
field of post data as first choice, so this will help with unknown timezone issue.get_post_timestamp()
Wrapper for datetime one. We need to deprecated
G
andU
formats in existing functions (so around lower levelget_post_time()
) and point to this one as replacement.the_time_tag()
Just a small helper for better machine–readable output, was requested before.
current_datetime()
Object alternative to
current_time()
, that is more friendly to compare and modify.The text was updated successfully, but these errors were encountered: