"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatUnixDateToHumanStringSSns = exports.formatUnixDateToHumanStringSSus = exports.formatUnixDateToHumanStringYYYY = exports.formatUnixDateToHumanStringDD = exports.formatUnixDateToHumanStringMMM = exports.formatUnixDateToHumanStringMMMDD = exports.formatUnixDateToHumanStringHHMM = exports.formatUnixDateToHumanStringSSms = exports.formatUnixDateToHumanStringHHMMSS = exports.formatUnixDateToHumanStringDDMM = exports.formatUnixDateToHumanStringDDMMHHMM = exports.formatUnixDateToHumanStringDDMMYY = exports.formatUnixDateToHumanString = void 0;
/**
 * Result 11/23/2018
 * @param unixTimestamp
 */
var formatUnixDateToHumanString = function (unixTimestamp, locale) {
    if (locale === void 0) { locale = "en-US"; }
    var res = new Date(unixTimestamp * 1000).toLocaleDateString(locale, {
        month: "numeric",
        year: "numeric",
        day: "numeric"
    });
    if (res === "Invalid Date") {
        return "";
    }
    return res;
};
exports.formatUnixDateToHumanString = formatUnixDateToHumanString;
var formatUnixDateToHumanStringDDMMYY = function (unixTimestamp) {
    var res = new Date(unixTimestamp * 1000).toLocaleDateString("en-GB", {
        timeZone: "utc",
        year: "2-digit",
        month: "2-digit",
        day: "2-digit"
    });
    if (res === "Invalid Date") {
        return "";
    }
    return res;
};
exports.formatUnixDateToHumanStringDDMMYY = formatUnixDateToHumanStringDDMMYY;
var formatUnixDateToHumanStringDDMMHHMM = function (unixTimestamp) {
    var ddmm = (0, exports.formatUnixDateToHumanStringDDMM)(unixTimestamp);
    var hhmm = (0, exports.formatUnixDateToHumanStringHHMM)(unixTimestamp);
    return "".concat(ddmm, " ").concat(hhmm);
};
exports.formatUnixDateToHumanStringDDMMHHMM = formatUnixDateToHumanStringDDMMHHMM;
var formatUnixDateToHumanStringDDMM = function (unixTimestamp) {
    var res = new Date(unixTimestamp * 1000).toLocaleDateString("en-GB", {
        timeZone: "utc",
        day: "numeric",
        month: "numeric"
    });
    if (res === "Invalid Date") {
        return "";
    }
    return res;
};
exports.formatUnixDateToHumanStringDDMM = formatUnixDateToHumanStringDDMM;
var formatUnixDateToHumanStringHHMMSS = function (unixTimestamp) {
    var date = new Date(unixTimestamp * 1000);
    var hours = date.getUTCHours();
    var minutes = date.getUTCMinutes();
    var seconds = date.getUTCSeconds();
    if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
        return "";
    }
    var hoursString = hours <= 9 ? "0".concat(hours) : hours.toString(10);
    var minutesString = minutes <= 9 ? "0".concat(minutes) : minutes.toString(10);
    var secondsString = seconds <= 9 ? "0".concat(seconds) : seconds.toString(10);
    return "".concat(hoursString, ":").concat(minutesString, ":").concat(secondsString);
};
exports.formatUnixDateToHumanStringHHMMSS = formatUnixDateToHumanStringHHMMSS;
var formatUnixDateToHumanStringSSms = function (unixSeconds, milliseconds) {
    var date = new Date(unixSeconds * 1000);
    var seconds = date.getUTCSeconds();
    // backward compatibility
    var ms = milliseconds !== undefined ? milliseconds : date.getUTCMilliseconds();
    if (isNaN(seconds) || isNaN(ms)) {
        return "";
    }
    var secondsString = seconds <= 9 ? "0".concat(seconds) : seconds.toString(10);
    var millisecondsString = pad(ms, 3);
    return "".concat(secondsString, ".").concat(millisecondsString);
};
exports.formatUnixDateToHumanStringSSms = formatUnixDateToHumanStringSSms;
var formatUnixDateToHumanStringHHMM = function (unixTimestamp) {
    var date = new Date(unixTimestamp * 1000);
    var hours = date.getUTCHours();
    var minutes = date.getUTCMinutes();
    if (isNaN(hours) || isNaN(minutes)) {
        return "";
    }
    var hoursString = hours <= 9 ? "0".concat(hours) : hours.toString(10);
    var minutesString = minutes <= 9 ? "0".concat(minutes) : minutes.toString(10);
    return "".concat(hoursString, ":").concat(minutesString);
};
exports.formatUnixDateToHumanStringHHMM = formatUnixDateToHumanStringHHMM;
var formatUnixDateToHumanStringMMMDD = function (unixTimestamp) {
    var date = new Date(unixTimestamp * 1000);
    var month = date.getUTCMonth();
    var day = date.getUTCDate();
    if (isNaN(month) || isNaN(day)) {
        return "";
    }
    return "".concat(getMonthString(month), " ").concat(day);
};
exports.formatUnixDateToHumanStringMMMDD = formatUnixDateToHumanStringMMMDD;
var formatUnixDateToHumanStringMMM = function (unixTimestamp) {
    var date = new Date(unixTimestamp * 1000);
    var month = date.getUTCMonth();
    if (isNaN(month)) {
        return "";
    }
    return getMonthString(month);
};
exports.formatUnixDateToHumanStringMMM = formatUnixDateToHumanStringMMM;
var formatUnixDateToHumanStringDD = function (unixTimestamp) {
    var date = new Date(unixTimestamp * 1000);
    var day = date.getUTCDate();
    if (isNaN(day)) {
        return "";
    }
    var strDay = day.toString();
    if (strDay.length === 2) {
        return strDay;
    }
    else if (strDay.length === 1) {
        return "0".concat(strDay);
    }
    else {
        return "";
    }
};
exports.formatUnixDateToHumanStringDD = formatUnixDateToHumanStringDD;
var formatUnixDateToHumanStringYYYY = function (unixTimestamp) {
    var date = new Date(unixTimestamp * 1000);
    var year = date.getUTCFullYear();
    if (isNaN(year)) {
        return "";
    }
    return year.toString(10);
};
exports.formatUnixDateToHumanStringYYYY = formatUnixDateToHumanStringYYYY;
var MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var getMonthString = function (month) {
    if (month < 0 || month > 11) {
        throw new Error("Invalid month index");
    }
    return MONTHS_SHORT[month];
};
/** Zero-pad helper (e.g. 5 -> "005")
 */
var pad = function (num, size) {
    var s = Math.floor(Math.abs(num)).toString();
    while (s.length < size)
        s = "0" + s;
    return s;
};
/**
 * Formats high-precision timestamp to SS.mmmmmm (Microseconds)
 * Logic: Uses Date for HH:MM:SS, appends raw microseconds
 */
var formatUnixDateToHumanStringSSus = function (unixSeconds, microseconds) {
    var date = new Date(unixSeconds * 1000);
    var s = date.getUTCSeconds();
    if (isNaN(s))
        return "";
    return "".concat(pad(s, 2), ".").concat(pad(microseconds, 6));
};
exports.formatUnixDateToHumanStringSSus = formatUnixDateToHumanStringSSus;
/**
 * Formats high-precision timestamp to SS.nnnnnnnnn (Nanoseconds)
 */
var formatUnixDateToHumanStringSSns = function (unixSeconds, nanoseconds) {
    var date = new Date(unixSeconds * 1000);
    var s = date.getUTCSeconds();
    if (isNaN(s))
        return "";
    return "".concat(pad(s, 2), ".").concat(pad(nanoseconds, 9));
};
exports.formatUnixDateToHumanStringSSns = formatUnixDateToHumanStringSSns;
