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 parseDateTime(value, field, options) {
    if (!value) {
        return false;
    }
    var datePattern = time.getLangDateFormat(),
        timePattern = time.getLangTimeFormat();
    var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D'),
        timePatternWoZero = timePattern.replace('HH','H').replace('mm','m').replace('ss','s');
    var pattern1 = datePattern + ' ' + timePattern;
    var pattern2 = datePatternWoZero + ' ' + timePatternWoZero;
    var datetime;
    if (options && options.isUTC) {
        datetime = moment.utc(value.replace(' ', 'T') + 'Z');
    } else {
        datetime = moment.utc(value, [pattern1, pattern2, moment.ISO_8601]);
        if (options && options.timezone) {
            datetime.add(-session.getTZOffset(datetime), 'minutes');
        }
    }
    if (datetime.isValid()) {
        if (datetime.year() === 0) {
            datetime.year(moment.utc().year());
        }
        if (datetime.year() >= 1900) {
            datetime.toJSON = function () {
                return this.clone().locale('en').format('YYYY-MM-DD HH:mm:ss');
            };
            return datetime;
        }
    }
    throw new Error(_.str.sprintf(core._t("'%s' is not a correct datetime"), value));
}
function parseDateTime ( value , field , options ) { if ( ! value ) { return false ; } var datePattern = time . getLangDateFormat ( ) , timePattern = time . getLangTimeFormat ( ) ; var datePatternWoZero = datePattern . replace ( 'MM' , 'M' ) . replace ( 'DD' , 'D' ) , timePatternWoZero = timePattern . replace ( 'HH' , 'H' ) . replace ( 'mm' , 'm' ) . replace ( 'ss' , 's' ) ; var pattern1 = datePattern + ' ' + timePattern ; var pattern2 = datePatternWoZero + ' ' + timePatternWoZero ; var datetime ; if ( options && options . isUTC ) { datetime = moment . utc ( value . replace ( ' ' , 'T' ) + 'Z' ) ; } else { datetime = moment . utc ( value , [ pattern1 , pattern2 , moment . ISO_8601 ] ) ; if ( options && options . timezone ) { datetime . add ( - session . getTZOffset ( datetime ) , 'minutes' ) ; } } if ( datetime . isValid ( ) ) { if ( datetime . year ( ) === 0 ) { datetime . year ( moment . utc ( ) . year ( ) ) ; } if ( datetime . year ( ) >= 1900 ) { datetime . toJSON = function ( ) { return this . clone ( ) . locale ( 'en' ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ; } ; return datetime ; } } throw new Error ( _ . str . sprintf ( core . _t ( "'%s' is not a correct datetime" ) , 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
// phatomjs crash if we don't use this format