odoo-13.0/addons/web/static/src/js/fields/field_utils.js
/**
 * Create an Date object
 * The method toJSON return the formated value to send value server side
 *
 * @param {string} value
 * @param {Object} [field]
 *        a description of the field (note: this parameter is ignored)
 * @param {Object} [options] additional options
 * @param {boolean} [options.isUTC] the formatted date is utc
 * @param {boolean} [options.timezone=false] format the date after apply the timezone
 *        offset
 * @returns {Moment|false} Moment date object
 */
Create an Date object
The method toJSON return the formated value to send value server side


Create an Date object The method toJSON return the formated value to send value server side
function parseDate(value, field, options) {
    if (!value) {
        return false;
    }
    var datePattern = time.getLangDateFormat();
    var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D');
    var date;
    if (options && options.isUTC) {
        date = moment.utc(value);
    } else {
        date = moment.utc(value, [datePattern, datePatternWoZero, moment.ISO_8601]);
    }
    if (date.isValid()) {
        if (date.year() === 0) {
            date.year(moment.utc().year());
        }
        if (date.year() >= 1900) {
            date.toJSON = function () {
                return this.clone().locale('en').format('YYYY-MM-DD');
            };
            return date;
        }
    }
    throw new Error(_.str.sprintf(core._t("'%s' is not a correct date"), value));
}
function parseDate ( value , field , options ) { if ( ! value ) { return false ; } var datePattern = time . getLangDateFormat ( ) ; var datePatternWoZero = datePattern . replace ( 'MM' , 'M' ) . replace ( 'DD' , 'D' ) ; var date ; if ( options && options . isUTC ) { date = moment . utc ( value ) ; } else { date = moment . utc ( value , [ datePattern , datePatternWoZero , moment . ISO_8601 ] ) ; } if ( date . isValid ( ) ) { if ( date . year ( ) === 0 ) { date . year ( moment . utc ( ) . year ( ) ) ; } if ( date . year ( ) >= 1900 ) { date . toJSON = function ( ) { return this . clone ( ) . locale ( 'en' ) . format ( 'YYYY-MM-DD' ) ; } ; return date ; } } throw new Error ( _ . str . sprintf ( core . _t ( "'%s' is not a correct date" ) , value ) ) ; }
Create an Date object
 The method toJSON return the formated value to send value server side
Create an Date object The method toJSON return the formated value to send value server side