[wp-trac] [WordPress Trac] #38342: Quick Draft: Leverage REST API endpoints
WordPress Trac
noreply at wordpress.org
Fri Dec 9 19:05:20 UTC 2016
#38342: Quick Draft: Leverage REST API endpoints
-------------------------------------+-------------------------------------
Reporter: adamsilverstein | Owner: joehoyle
Type: enhancement | Status: assigned
Priority: normal | Milestone: Future Release
Component: Administration | Version:
Severity: normal | Resolution:
Keywords: has-patch 4.8-early | Focuses: accessibility,
needs-refresh has-unit-tests | javascript, rest-api
-------------------------------------+-------------------------------------
Comment (by aduth):
Latest diff includes:
- Unit tests for `wp.formatting.trimWords`
([https://github.com/adamsilverstein/wordpress-
develop/commit/4681d3f06a5890b68a87805dd6c0bf683dada1bb 4681d3f on
GitHub])
- New `wp.formatting.date` date formatting utility
([https://github.com/adamsilverstein/wordpress-
develop/commit/4314aec9e793cbde9e66f561d423cf8c5dd9f2b5 4314aec on
GitHub])
The idea with the date formatting utility is to try to mimic the behavior
of [http://php.net/manual/en/function.date.php PHP `date`]. This was
sparked by @pento 's suggestion at ticket:38342#comment:69 . It succeeds
at this to some degree, but is really only a rough approximation. This
becomes obvious when either trying to customize the separators (`/` vs.
`-`) or when the site is configured to show day-first dates in an en-US
locale (where Intl will format month-first). `Intl.DateTimeFormat` doesn't
give much control over this, except perhaps through its
[https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
`formatToParts` method] which has abysmal browser support.
As implemented, it should solve two present issues:
- The date respects the current user locale (via 4.7.0's
[https://developer.wordpress.org/reference/functions/get_user_locale/
get_user_locale])
- (Tries to) format date according to site-configured setting, at least
working between numeric/written month
I had considered also some attempts to port `date` directly to JavaScript,
like [http://locutus.io/php/datetime/date/ that of the Locutus project].
The downside here is trying to handle localization of month and weekday
names.
Considering Moment.js again, there are similar concerns with localization
([http://momentjs.com/docs/#/i18n/ though includes proper support]), and
also incompatibilities between PHP date formats (which could be
[https://gist.github.com/phpmypython/f97c5f5f59f2a934599d resolved with
mappings]).
I haven't yet written tests for `wp.formatting.date` since I wasn't sure
yet whether this is a direction we'd want to take.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38342#comment:84>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list