"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var moment = require("moment");
var _ = require("lodash");
var default_1 = /** @class */ (function () {
    function default_1() {
    }
    //获取整个月份的数组
    // static monthTrend = (month) => {
    //     var from = new Date(month);
    //     let m = from.getMonth();
    //     let start = from.getTime();
    //     let now = _.now();
    //     var arr = [];
    //     for (let i = 0; i < 32; i++) {
    //         let tmp = start + i * 86400000;
    //         if (tmp > now) {
    //             break;
    //         }
    //         let t = moment(tmp);
    //         if (t.month() > m) {
    //             break;
    //         }
    //         arr.push(t.format('YYYY-MM-DD'));
    //     }
    //     return arr;
    // }
    default_1.toRange = function (month) {
        var start = month;
        var end = '';
        if (month.length == 7) {
            start = start + '-01';
        }
        end = moment(start).add(1, 'months').date(1).subtract(1, 'days').format('YYYY-MM-DD');
        return [start, end];
    };
    /**
     * 获取时间段的日期数组
    */
    default_1.dateArr = function (start, end, format) {
        if (end === void 0) { end = null; }
        if (format === void 0) { format = 'YYYY-MM-DD'; }
        // var _start = moment(start).hour(0)
        var _start = parseInt(moment(start).millisecond(0).second(0).minute(0).hour(0).format('x'));
        var _end = 0;
        if (end) {
            _end = parseInt(moment(end).millisecond(999).second(59).minute(59).hour(23).format('x'));
        }
        else {
            _end = parseInt(moment(start).add(1, 'months').date(1).subtract(1, 'days').millisecond(999).second(59).minute(59).hour(23).format('x'));
        }
        var arr = [];
        while (_start < _end) {
            arr.push(moment(_start).format(format));
            _start += 86400000;
        }
        return arr;
    };
    /**
     * 以批定日期和日期内数据填满一个默认为0的日期区间内的数据
    */
    default_1.sortDateData = function (dateArr, dataArr, field, def) {
        var defs = {};
        def.map(function (key) { return defs[key] = 0; });
        var arr = dateArr.map(function (date) {
            var _a;
            return __assign((_a = {}, _a[field] = date, _a), _.assign({}, defs));
        });
        arr.map(function (item) {
            var _a;
            var obj = _.find(dataArr, (_a = {}, _a[field] = item[field], _a));
            if (obj) {
                _.assign(item, obj);
            }
        });
        return _.orderBy(arr, field, 'asc');
    };
    return default_1;
}());
exports.default = default_1;
