Search code examples
javascriptjqueryjquery-ui-datepickergoogle-code-prettify

Why does Google Code Prettifier stop working when I use JQuery DatePicker (or vice versa)


If the Google Code Prettifier (or JQuery Syntax Highlighter) is being used in the same page as the JQuery DatePicker, neither will work properly. Why is this?


Solution

  • Because they both monkey patch a now method onto the native Date object!

    Prettify does this:

    var clock = Date;
    if (!clock['now']) {
      clock = { 'now': function () { return +(new Date); } };
    }
    

    DatePicker does this:

    Date.now=function(){return new Date();}
    

    So Prettify's returns an int representation of the Date (so that it can add on some ms) while DatePicker returns a Date.

    (IMO this kind of thing is outrageous in two such commonly-used libraries.)