<commit_before>/*global require, module*/
var InvalidArgumentError = require("../error/invalid-argument-error"),
    easyGid = require("easy-guid"),
    validator = require('validator');

var TimeEntry = function (issueId, issueName, projectName, taskUrl) {
    "use strict";
    if (!validator.isInt(issueId)) {
        throw new InvalidArgumentError("Parameter issueId must be an integer.");
    }

    if (typeof issueName !== "string") {
        throw new InvalidArgumentError("Parameter issueName must be a string.");
    }

    if (typeof projectName !== "string") {
        throw new InvalidArgumentError("Parameter projectName must be a string.");
    }

    if (!validator.isURL(taskUrl)) {
        throw new InvalidArgumentError("Parameter taskUrl must be a URL.");
    }

    this.id = easyGid.new();
    this.issueId = issueId;
    this.issueName = issueName;
    this.projectName = projectName;
    this.taskUrl = taskUrl;
    this.spentOn = null;
    this.hours = null;
    this.activityId = null;
    this.comments = null;
    this.updated = false;
};

TimeEntry.prototype = (function () {
    "use strict";
    var dateFormatPattern = /^\d{4}-\d{2}-\d{2}$/,
        setSpentOn = function (spentOn) {
            if (typeof spentOn !== "string" || !spentOn.match(dateFormatPattern)) {
                throw new InvalidArgumentError("Parameter spentOn must be a string with format {YYYY-MM-DD}.");
            }

            this.spentOn = spentOn;
            return this;
        },
        isUpdated  = function () {
            return this.activityId !== null && this.hours !== null;
        },
        setHours = function (hours) {
            if (!(validator.isInt(hours, { min: 0 }) || validator.isFloat(hours, { min: 0.00 }))) {
                this.updated = false;
                return this;
            }

            this.hours = parseFloat(hours);
            this.updated = isUpdated.call(this);
            return this;
        },
        setActivityId = function (activityId) {
            if (!validator.isInt(activityId)) {
                this.updated = false;
                return this;
            }

            this.activityId = parseInt(activityId, 10);
            this.updated = isUpdated.call(this);
            return this;
        },
        setComments = function (comments) {
            this.comments = comments;
            return this;
        },
        clearTimeEntry = function () {
            this.spentOn = null;
            this.hours = null;
            this.activityId = null;
            this.comments = null;
            this.updated = false;
        },
        buildPostEntry = function () {
            return {
                time_entry: {
                    issue_id: this.issueId,
                    spent_on: this.spentOn,
                    hours: this.hours,
                    activity_id: this.activityId,
                    comments: this.comments
                }
            };
        };
    return {
        setHours: setHours,
        setActivityId: setActivityId,
        setComments: setComments,<commit_msg>Post time entry defect fix<commit_after>/*global require, module*/
var InvalidArgumentError = require("../error/invalid-argument-error"),
    easyGid = require("easy-guid"),
    validator = require('validator');

var TimeEntry = function (issueId, issueName, projectName, taskUrl) {
    "use strict";
    if (!validator.isInt(issueId)) {
        throw new InvalidArgumentError("Parameter issueId must be an integer.");
    }

    if (typeof issueName !== "string") {
        throw new InvalidArgumentError("Parameter issueName must be a string.");
    }

    if (typeof projectName !== "string") {
        throw new InvalidArgumentError("Parameter projectName must be a string.");
    }

    if (!validator.isURL(taskUrl)) {
        throw new InvalidArgumentError("Parameter taskUrl must be a URL.");
    }

    this.id = easyGid.new();
    this.issueId = issueId;
    this.issueName = issueName;
    this.projectName = projectName;
    this.taskUrl = taskUrl;
    this.spentOn = null;
    this.hours = null;
    this.activityId = null;
    this.comments = null;
    this.updated = false;
};

TimeEntry.prototype = (function () {
    "use strict";
    var dateFormat = "YYYY-MM-DD",
        setSpentOn = function (spentOn) {
            if (!spentOn || !spentOn._isAMomentObject) {
                throw new InvalidArgumentError("Parameter spentOn must be a moment object.");
            }

            this.spentOn = spentOn;
            return this;
        },
        isUpdated  = function () {
            return this.activityId !== null && this.hours !== null;
        },
        setHours = function (hours) {
            if (!(validator.isInt(hours, { min: 0 }) || validator.isFloat(hours, { min: 0.00 }))) {
                this.updated = false;
                return this;
            }

            this.hours = parseFloat(hours);
            this.updated = isUpdated.call(this);
            return this;
        },
        setActivityId = function (activityId) {
            if (!validator.isInt(activityId)) {
                this.updated = false;
                return this;
            }

            this.activityId = parseInt(activityId, 10);
            this.updated = isUpdated.call(this);
            return this;
        },
        setComments = function (comments) {
            this.comments = comments;
            return this;
        },
        clearTimeEntry = function () {
            this.spentOn = null;
            this.hours = null;
            this.activityId = null;
            this.comments = null;
            this.updated = false;
        },
        buildPostEntry = function () {
            return {
                time_entry: {
                    issue_id: this.issueId,
                    spent_on: this.spentOn.toString(dateFormat),
                    hours: this.hours,
                    activity_id: this.activityId,
                    comments: this.comments
                }
            };
        };
    return {
        setHours: setHours,
        setActivityId: setActivityId,
        setComments: setComments,
{'fraction_non_alphanumeric': 0.11224655312246554, 'fraction_numerical': 0.0024330900243309003, 'mean_word_length': 1.757602862254025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7458330', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1632, 'n_words': 391}