

function ts2time(ts) {
    function addZero(m) {
        return m < 10 ? '0' + m : m;
    }
    if (ts) {
        ts *= 1000;
        var time = new Date(ts);
        var y = time.getFullYear();
        var M = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var m = time.getMinutes();
        var s = time.getSeconds();
        return addZero(h) + ':' + addZero(m) + ':' + addZero(s);
    } else {
        return '';
    }
}

function sendMail() { 

    var zoneid = 1;
    var uid = $("#i-uid").val(); // "D51D63CA040982E406BDE9898AD757AE";
    var ts = moment($("#i-date").val()).format('YYYYMMDD') ; //"20201119";
  
    var data = {
        zoneid: zoneid,
        uid: uid,
        ts: ts
    };

    post(
        getProviderUrl("GameContinuedTs"), {
            date: data
        },
        function(ret) {  
            $("canvas#myChart").remove();
            $("div.chart_wrap").append('<canvas id="myChart" class="animated fadeIn" ></canvas>');
            ctx = $("#myChart"); 
            lbls = [];
            ds = [];
            for (var i in ret) {
                info = ret[i];
                l = ts2time(info.startTs) + "-" + ts2time(info.endTs);
                lbls.push(l);
                ds.push(Math.floor(info.durationTs/60) );
            }  
            chat = new Chart(ctx, {
                type: 'bar',                
                data: { labels: lbls,
                    datasets:[{label:"持续时长(分钟)",data: ds}]},
                options: {}
            }); 
        }, 'json');
}
