[wp-trac] [WordPress Trac] #39222: Add JavaScript date helpers

WordPress Trac noreply at wordpress.org
Fri Jun 2 14:11:17 UTC 2017


#39222: Add JavaScript date helpers
-------------------------------------------------+-------------------------
 Reporter:  rmccue                               |       Owner:  rmccue
     Type:  feature request                      |      Status:  assigned
 Priority:  normal                               |   Milestone:  Future
Component:  Date/Time                            |  Release
 Severity:  normal                               |     Version:  4.7
 Keywords:  needs-docs has-unit-tests needs-     |  Resolution:
  patch                                          |     Focuses:  rest-api
-------------------------------------------------+-------------------------

Comment (by aduth):

 In addition to formatting, should we include date parsing utilities? As an
 example, in the Gutenberg project we've adapted the latest patch and have
 found we need to be able to determine whether a date received for a post
 from the REST API occurs in the future.

 https://github.com/WordPress/gutenberg/blob/691ec08/editor/selectors.js#L73-L76

 I can see a few ways we approach this:

 - Use GMT fields instead of site-localized, e.g. `moment.utc( dateGmt
 ).isAfter( moment.utc() )`
 - Configure `moment` to a default timezone offset with `moment.tz`
 ([https://github.com/WordPress/gutenberg/blob/691ec0805c486b2333205346832f64f5fdc00f81/editor/index.js#L22-L36
 example])
 - Include in `wp.date` parsing utilities complementing formatters

 The last option is most relevant to this ticket and has a few
 implications:

 - It would return a moment instance and therefore tie us more strongly to
 Moment
 - What would we name the function? `dateParse` for
 [http://php.net/manual/en/function.date-parse.php equivalence to PHP
 functions]? Wondering whether we're doing ourselves any benefit by
 pretending to mimic PHP functions in JavaScript, vs. more natural naming
 like `parse` and `format`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39222#comment:35>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list