<commit_before>import Decimal from '../lib/decimal.min.js';

/**
 * Date and time operations.
 *
 * @author n1474335 [<EMAIL>]
 * @copyright Crown Copyright 2016
 * @license Apache-2.0
 *
 * @namespace
 */
const DateTime = {

    /**
     * @constant
     * @default
     */
    UNITS: ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"],

    /**
     * From UNIX Timestamp operation.
     *
     * @param {number} input
     * @param {Object[]} args
     * @returns {string}
     */
    runFromUnixTimestamp: function(input, args) {
        let units = args[0],
            d;

        input = parseFloat(input);

        if (units === "Seconds (s)") {
            d = moment.unix(input);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC";
        } else if (units === "Milliseconds (ms)") {
            d = moment(input);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else if (units === "Microseconds (μs)") {
            d = moment(input / 1000);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else if (units === "Nanoseconds (ns)") {
            d = moment(input / 1000000);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else {
            throw "Unrecognised unit";
        }
    },


    /**
     * @constant
     * @default
     */
    TREAT_AS_UTC: true,

    /**
     * To UNIX Timestamp operation.
     *
     * @param {string} input
     * @param {Object[]} args
     * @returns {number}
     */
    runToUnixTimestamp: function(input, args) {
        let units = args[0],
            treatAsUTC = args[1],
            d = treatAsUTC ? moment.utc(input) : moment(input);

        if (units === "Seconds (s)") {
            return d.unix();
        } else if (units === "Milliseconds (ms)") {
            return d.valueOf();
        } else if (units === "Microseconds (μs)") {
            return d.valueOf() * 1000;
        } else if (units === "Nanoseconds (ns)") {
            return d.valueOf() * 1000000;
        } else {
            throw "Unrecognised unit";
        }
    },


    /**
     * Converts a Windows FILETIME to Unix Epoch time.
     *
     * @param {string} input
     * @param {Object[]} args (not used)
     * @returns {string}
     */
    runFromFiletimeToUnix: function(input, args) {
        input = new Decimal(input);
        input = input.sub(116444736000000000).div(10000000);
        if(input.gte(0) && input.lt(Math.pow(2,31))){
            return input.toString();
        } else {
            throw "Date " + input + " is not a valid date";
        }
    },


    /**
     * Converts a Unix Epoch time to Windows FILETIME.
     *
     * @param {string} input
     * @param {Object[]} args (not used)
     * @returns {string}
     */
    runToFiletimeFromUnix: function(input, args) {
        input = new Decimal(input);
        if(input.gte(0) && input.lt(Math.pow(2,31))){
            return input.mul(10000000).add(116444736000000000).toHex();
        } else {
            throw "Date " + input + " is not a valid date";
        }
    },


    /**<commit_msg>Create DateTime.js<commit_after>import Decimal from "../lib/decimal.min.js";

/**
 * Date and time operations.
 *
 * @author n1474335 [<EMAIL>]
 * @copyright Crown Copyright 2016
 * @license Apache-2.0
 *
 * @namespace
 */
const DateTime = {

    /**
     * @constant
     * @default
     */
    UNITS: ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"],

    /**
     * From UNIX Timestamp operation.
     *
     * @param {number} input
     * @param {Object[]} args
     * @returns {string}
     */
    runFromUnixTimestamp: function(input, args) {
        let units = args[0],
            d;

        input = parseFloat(input);

        if (units === "Seconds (s)") {
            d = moment.unix(input);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC";
        } else if (units === "Milliseconds (ms)") {
            d = moment(input);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else if (units === "Microseconds (μs)") {
            d = moment(input / 1000);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else if (units === "Nanoseconds (ns)") {
            d = moment(input / 1000000);
            return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
        } else {
            throw "Unrecognised unit";
        }
    },


    /**
     * @constant
     * @default
     */
    TREAT_AS_UTC: true,

    /**
     * To UNIX Timestamp operation.
     *
     * @param {string} input
     * @param {Object[]} args
     * @returns {number}
     */
    runToUnixTimestamp: function(input, args) {
        let units = args[0],
            treatAsUTC = args[1],
            d = treatAsUTC ? moment.utc(input) : moment(input);

        if (units === "Seconds (s)") {
            return d.unix();
        } else if (units === "Milliseconds (ms)") {
            return d.valueOf();
        } else if (units === "Microseconds (μs)") {
            return d.valueOf() * 1000;
        } else if (units === "Nanoseconds (ns)") {
            return d.valueOf() * 1000000;
        } else {
            throw "Unrecognised unit";
        }
    },


    /**
     * Converts a Windows FILETIME to Unix Epoch time.
     *
     * @param {string} input
     * @param {Object[]} args (not used)
     * @returns {string}
     */
    runFromFiletimeToUnix: function(input, args) {
        input = new Decimal(input);
        input = input.sub(116444736000000000).div(10000000);
        if (input.gte(0) && input.lt(Math.pow(2, 31))){
            return input.toString();
        } else {
            throw "Date " + input + " is not a valid date";
        }
    },


    /**
     * Converts a Unix Epoch time to Windows FILETIME.
     *
     * @param {string} input
     * @param {Object[]} args (not used)
     * @returns {string}
     */
    runToFiletimeFromUnix: function(input, args) {
        input = new Decimal(input);
        if (input.gte(0) && input.lt(Math.pow(2, 31))){
            return input.mul(10000000).add(116444736000000000).toHex();
        } else {
            throw "Date " + input + " is not a valid date";
        }
    },


    /**
{'fraction_non_alphanumeric': 0.16031969910672308, 'fraction_numerical': 0.030716188685159067, 'mean_word_length': 1.842761692650334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '222744', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2047, 'n_words': 505}