examples/phonegap1/plugins/cordova-plugin-globalization/www/firefoxos/l10n_date.js
function prettyDate (time, useCompactFormat, maxDiff) {
        maxDiff = maxDiff || 86400 * 10; // default = 10 days

        switch (time.constructor) {
        case String: // timestamp
            time = parseInt(time);
            break;
        case Date:
            time = time.getTime();
            break;
        }

        var secDiff = (Date.now() - time) / 1000;
        if (isNaN(secDiff)) {
            return _('incorrectDate');
        }

        if (Math.abs(secDiff) > 60) {
            // round milliseconds up if difference is over 1 minute so the result is
            // closer to what the user would expect (1h59m59s300ms diff should return
            // "in 2 hours" instead of "in an hour")
            secDiff = secDiff > 0 ? Math.ceil(secDiff) : Math.floor(secDiff);
        }

        if (secDiff > maxDiff) {
            return localeFormat(new Date(time), '%x');
        }

        var f = useCompactFormat ? '-short' : '-long';
        var parts = relativeParts(secDiff);

        var affix = secDiff >= 0 ? '-ago' : '-until';
        for (var i in parts) {
            return _(i + affix + f, { value: parts[i] });
        }
    }
function prettyDate (time, useCompactFormat, maxDiff) {
        maxDiff = maxDiff || 86400 * 10; // default = 10 days

        switch (time.constructor) {
        case String: // timestamp
            time = parseInt(time);
            break;
        case Date:
            time = time.getTime();
            break;
        }

        var secDiff = (Date.now() - time) / 1000;
        if (isNaN(secDiff)) {
            return _('incorrectDate');
        }

        if (Math.abs(secDiff) > 60) {
            // round milliseconds up if difference is over 1 minute so the result is
            // closer to what the user would expect (1h59m59s300ms diff should return
            // "in 2 hours" instead of "in an hour")
            secDiff = secDiff > 0 ? Math.ceil(secDiff) : Math.floor(secDiff);
        }

        if (secDiff > maxDiff) {
            return localeFormat(new Date(time), '%x');
        }

        var f = useCompactFormat ? '-short' : '-long';
        var parts = relativeParts(secDiff);

        var affix = secDiff >= 0 ? '-ago' : '-until';
        for (var i in parts) {
            return _(i + affix + f, { value: parts[i] });
        }
    }
function prettyDate ( time , useCompactFormat , maxDiff ) { maxDiff = maxDiff || 86400 * 10 ; // default = 10 days switch ( time . constructor ) { case String : // timestamp time = parseInt ( time ) ; break ; case Date : time = time . getTime ( ) ; break ; } var secDiff = ( Date . now ( ) - time ) / 1000 ; if ( isNaN ( secDiff ) ) { return _ ( 'incorrectDate' ) ; } if ( Math . abs ( secDiff ) > 60 ) { // round milliseconds up if difference is over 1 minute so the result is // closer to what the user would expect (1h59m59s300ms diff should return // "in 2 hours" instead of "in an hour") secDiff = secDiff > 0 ? Math . ceil ( secDiff ) : Math . floor ( secDiff ) ; } if ( secDiff > maxDiff ) { return localeFormat ( new Date ( time ) , '%x' ) ; } var f = useCompactFormat ? '-short' : '-long' ; var parts = relativeParts ( secDiff ) ; var affix = secDiff >= 0 ? '-ago' : '-until' ; for ( var i in parts ) { return _ ( i + affix + f , { value : parts [ i ] } ) ; } }
Returns a translated string which respresents the
relative time before or after a date.
@param {String|Date} time before/after the currentDate.
@param {String} useCompactFormat whether to use a compact display format.
@param {Number} maxDiff returns a formatted date if the diff is greater.
Returns a translated string which respresents the relative time before or after a date .