• The following issues have been present for a while and need to be addressed assuming that Moment.js will continue to be used indefinitely. The following code block is found inside the script-loader.php file inside the wp-includes directory:

    
    did_action( 'init' ) && $scripts->add_inline_script(
    	'moment',
    	sprintf(
    		"moment.updateLocale( '%s', %s );",
    		get_user_locale(),
    		wp_json_encode(
    			array(
    				'months'         => array_values( $wp_locale->month ),
    				'monthsShort'    => array_values( $wp_locale->month_abbrev ),
    				'weekdays'       => array_values( $wp_locale->weekday ),
    				'weekdaysShort'  => array_values( $wp_locale->weekday_abbrev ),
    				'week'           => array(
    					'dow' => (int) get_option( 'start_of_week', 0 ),
    				),
    				'longDateFormat' => array(
    					'LT'   => get_option( 'time_format', __( 'g:i a' ) ),
    					'LTS'  => null,
    					'L'    => null,
    					'LL'   => get_option( 'date_format', __( 'F j, Y' ) ),
    					'LLL'  => __( 'F j, Y g:i a' ),
    					'LLLL' => null,
    				),
    			)
    		)
    	),
    	'after'
    );
    

    Issue 1: Locales
    Each individual locale file for Moment.js is kebab-cased and not snake_cased.

    • Right: en-us
    • Wrong: en_US

    Issue 2: Improper Formats
    The values for time_format and date_format are those of PHP and not of the Moment.js library.

    Time

    • Right: h:mm a
    • Wrong: g:i a

    Date

    • Right: MMMM D[,] YYYY
    • Wrong: F j, Y

    Filter Request
    Is there any chance a filter can be added so that user’s can modify data that gets added via the wp_add_inline_script function?

    • This topic was modified 2 years, 10 months ago by DaveyJake.
    • This topic was modified 2 years, 10 months ago by DaveyJake.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Moment.js Library Inline Script Bugs’ is closed to new replies.