<commit_before>"use strict";

var Data = require("lazuli-data/index.js");

/*
module.exports = Data.Composite.clone({
    id: "DateTime",
    part_fields: [
        Data.Date,
        Data.Time,
    ],
});
*/

/**
* To represent a date/time field
**/
module.exports = Data.Date.clone({
    id: "DateTime",
    css_type: "datetime",
    internal_format: "yyyy-MM-dd HH:mm:ss",
    update_format: "dd/MM/yy HH:mm",
    display_format: "dd/MM/yy HH:mm:ss",
    data_length: 20,
    regex_label1: "not a valid date",                                // client side
    regex_label2: "invalid time, please use the 24 hour clock",      // client side
    // regex_pattern1: "[0-3]?[0-9]/[0-1]?[0-9]/[0-9]{2}",                // client side
    // regex_pattern2: "^([01]?[0-9]|2[0-3]):[0-5][0-9]$",                // client side
    error_message: "not a valid date/time",
});


module.exports.defbind("setFormatsMasks", "cloneInstance", function () {
    this.internal_format_parts = this.internal_format.split(" ");
    if (this.internal_format_parts.length !== 2) {
        this.throwError("invalid internal_format for DateTime: " + this.internal_format);
    }
    this.update_format_parts = this.update_format.split(" ");
    if (this.update_format_parts.length !== 2) {
        this.throwError("invalid update_format for DateTime: " + this.update_format);
    }
    // this. display_format_parts = this. display_format.split(" ");
    // if (this. display_format_parts.length !== 2) {
    //     this.throwError("invalid  display_format for DateTime: " + this. display_format);
    // }
    this.input_mask_parts = this.update_format.replace(/\w/g, "9").split(" ");
    this.regex_pattern1 = "^" + this.update_format_parts[0].replace("dd", "[0-3]?[0-9]").replace("MM", "[0-1]?[0-9]").replace("yy", "[0-9]{2}") + "$";
    this.regex_pattern2 = "^" + this.update_format_parts[1].replace("HH", "([01]?[0-9]|2[0-3])").replace("mm", "[0-5][0-9]").replace("ss", "[0-5][0-9]") + "$";
    this.trace("setFormatsMasks(): " + this.internal_format_parts + ", " + this.update_format_parts);
});

/*
module.exports.override("isBefore", function (date) {
    var nThisSecond = Math.floor(Date.parse(this.get()).getTime() / 1000);
    var nOtherSecond = Math.floor(Date.parse(this.parse(date)).getTime() / 1000);
    return (nThisSecond < nOtherSecond);
});


module.exports.override("isAfter", function (date) {
    var nThisSecond = Math.floor(Date.parse(this.get()).getTime() / 1000);
    var nOtherSecond = Math.floor(Date.parse(this.parse(date)).getTime() / 1000);
    return (nThisSecond > nOtherSecond);
});


module.exports.override("beforeSet", function (val) {
    this.debug("beforeSet() start: " + val);
    if (!val || val === "|") {
        val = "";
    } else if (typeof val === "string") {
        val = val.replace("|", " ");
    }
    this.debug("beforeSet() end: " + val);
    return Data.Date.beforeSet.call(this, val);
});
*/

module.exports.override("appendClientSideProperties", function (obj) {
    Data.Date.appendClientSideProperties.call(this, obj);
    obj.min = this.min ? Date.parse(this.min) : null;
    obj.max = this.max ? Date.parse(this.max) : null;
    obj.regex_label1 = this.regex_label1;
    obj.regex_pattern1 = this.regex_pattern1;
    obj.input_mask1 = this.input_mask_parts[0];
    obj.regex_label2 = this.regex_label2;
    obj.regex_pattern2 = this.regex_pattern2;
    obj.input_mask2 = this.input_mask_parts[1];
});

module.exports.define("getDatePart", function () {
    var val_split = [];
    if (!this.isBlank()) {
        val_split = this.get().split(" ");
    }
    return (val_split.length > 0 ? val_split[0] : "");
});

// module.exports.define("getDatePartDisplay", function () {
//     return this.parse(this.getDatePart(), this.internal_format_parts[0],
//      this.display_format_parts[0]);
// });

module.exports.define("getDatePartUpdate", function () {
    var date_part = this.getDatePart();
    if (date_part) {
        date_part = this.parse(date_part, this.internal_format_parts[0],
            this.update_format_parts[0]);
    }
    return date_part;
});


module.exports.define("getTimePart", function () {
    var val_split = [];
    if (!this.isBlank()) {
        val_split = this.get().split(" ");
    }
    if (val_split.length > 1) {
        return val_split[1];
    } else if (val_split.length > 0 && val_split[0]) {
        return "00:00:00";
    }
    return "";
});

// module.exports.define("getTimePartDisplay", function () {
//     return this.parse(this.getTimePart(), this.internal_format_parts[1],
//      this.display_format_parts[1]);
// });

module.exports.define("getTimePartUpdate", function () {
    var time_part = this.getTimePart();
    if (time_part) {
        time_part = this.parse(time_part, this.internal_format_parts[1],
            this.update_format_parts[1]);
    }
    return time_part;
});


module.exports.override("renderUpdateControls", function (div) {
    div.makeInput("text", null, this.getDatePartUpdate(), "css_date_part input-mini", this.update_format_parts[0]);
    div.makeInput("text", null, this.getTimePartUpdate(), "css_time_part input-mini", this.update_format_parts[1]);
});<commit_msg>fix DateTime field styling<commit_after>"use strict";

var Data = require("lazuli-data/index.js");

/*
module.exports = Data.Composite.clone({
    id: "DateTime",
    part_fields: [
        Data.Date,
        Data.Time,
    ],
});
*/

/**
* To represent a date/time field
**/
module.exports = Data.Date.clone({
    id: "DateTime",
    css_type: "datetime",
    internal_format: "yyyy-MM-dd HH:mm:ss",
    update_format: "dd/MM/yy HH:mm",
    display_format: "dd/MM/yy HH:mm:ss",
    data_length: 20,
    regex_label1: "not a valid date",                                // client side
    regex_label2: "invalid time, please use the 24 hour clock",      // client side
    // regex_pattern1: "[0-3]?[0-9]/[0-1]?[0-9]/[0-9]{2}",                // client side
    // regex_pattern2: "^([01]?[0-9]|2[0-3]):[0-5][0-9]$",                // client side
    error_message: "not a valid date/time",
});


module.exports.defbind("setFormatsMasks", "cloneInstance", function () {
    this.internal_format_parts = this.internal_format.split(" ");
    if (this.internal_format_parts.length !== 2) {
        this.throwError("invalid internal_format for DateTime: " + this.internal_format);
    }
    this.update_format_parts = this.update_format.split(" ");
    if (this.update_format_parts.length !== 2) {
        this.throwError("invalid update_format for DateTime: " + this.update_format);
    }
    // this. display_format_parts = this. display_format.split(" ");
    // if (this. display_format_parts.length !== 2) {
    //     this.throwError("invalid  display_format for DateTime: " + this. display_format);
    // }
    this.input_mask_parts = this.update_format.replace(/\w/g, "9").split(" ");
    this.regex_pattern1 = "^" + this.update_format_parts[0].replace("dd", "[0-3]?[0-9]").replace("MM", "[0-1]?[0-9]").replace("yy", "[0-9]{2}") + "$";
    this.regex_pattern2 = "^" + this.update_format_parts[1].replace("HH", "([01]?[0-9]|2[0-3])").replace("mm", "[0-5][0-9]").replace("ss", "[0-5][0-9]") + "$";
    this.trace("setFormatsMasks(): " + this.internal_format_parts + ", " + this.update_format_parts);
});

/*
module.exports.override("isBefore", function (date) {
    var nThisSecond = Math.floor(Date.parse(this.get()).getTime() / 1000);
    var nOtherSecond = Math.floor(Date.parse(this.parse(date)).getTime() / 1000);
    return (nThisSecond < nOtherSecond);
});


module.exports.override("isAfter", function (date) {
    var nThisSecond = Math.floor(Date.parse(this.get()).getTime() / 1000);
    var nOtherSecond = Math.floor(Date.parse(this.parse(date)).getTime() / 1000);
    return (nThisSecond > nOtherSecond);
});


module.exports.override("beforeSet", function (val) {
    this.debug("beforeSet() start: " + val);
    if (!val || val === "|") {
        val = "";
    } else if (typeof val === "string") {
        val = val.replace("|", " ");
    }
    this.debug("beforeSet() end: " + val);
    return Data.Date.beforeSet.call(this, val);
});
*/

module.exports.override("appendClientSideProperties", function (obj) {
    Data.Date.appendClientSideProperties.call(this, obj);
    obj.min = this.min ? Date.parse(this.min) : null;
    obj.max = this.max ? Date.parse(this.max) : null;
    obj.regex_label1 = this.regex_label1;
    obj.regex_pattern1 = this.regex_pattern1;
    obj.input_mask1 = this.input_mask_parts[0];
    obj.regex_label2 = this.regex_label2;
    obj.regex_pattern2 = this.regex_pattern2;
    obj.input_mask2 = this.input_mask_parts[1];
});

module.exports.define("getDatePart", function () {
    var val_split = [];
    if (!this.isBlank()) {
        val_split = this.get().split(" ");
    }
    return (val_split.length > 0 ? val_split[0] : "");
});

// module.exports.define("getDatePartDisplay", function () {
//     return this.parse(this.getDatePart(), this.internal_format_parts[0],
//      this.display_format_parts[0]);
// });

module.exports.define("getDatePartUpdate", function () {
    var date_part = this.getDatePart();
    if (date_part) {
        date_part = this.parse(date_part, this.internal_format_parts[0],
            this.update_format_parts[0]);
    }
    return date_part;
});


module.exports.define("getTimePart", function () {
    var val_split = [];
    if (!this.isBlank()) {
        val_split = this.get().split(" ");
    }
    if (val_split.length > 1) {
        return val_split[1];
    } else if (val_split.length > 0 && val_split[0]) {
        return "00:00:00";
    }
    return "";
});

// module.exports.define("getTimePartDisplay", function () {
//     return this.parse(this.getTimePart(), this.internal_format_parts[1],
//      this.display_format_parts[1]);
// });

module.exports.define("getTimePartUpdate", function () {
    var time_part = this.getTimePart();
    if (time_part) {
        time_part = this.parse(time_part,
            this.internal_format_parts[1],
            this.update_format_parts[1]);
    }
    return time_part;
});


module.exports.override("renderUpdateControls", function (div) {
    div.makeInput("text", null, this.getDatePartUpdate(), "css_date_part form-control",
        this.update_format_parts[0])
        .attr("style", "display: inline; width: 100px;");
    div.makeInput("text", null, this.getTimePartUpdate(), "css_time_part form-control",
        this.update_format_parts[1])
        .attr("style", "display: inline; width: 100px;");
});
{'fraction_non_alphanumeric': 0.18423299497201404, 'fraction_numerical': 0.022199032349871927, 'mean_word_length': 3.3169533169533167, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4856848', 'n_tokens_mistral': 3657, 'n_tokens_neox': 3559, 'n_words': 573}