{"size": 1550, "ext": "js", "max_stars_repo_path": "src/date.js", "max_stars_repo_name": "g0ngjie/alrale-cli", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/date.js", "max_issues_repo_name": "g0ngjie/alrale-cli", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/date.js", "max_forks_repo_name": "g0ngjie/alrale-cli", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 35.2272727273, "max_line_length": 116, "alphanum_fraction": 0.6206451613}
#!/usr/bin/env node

const { IsNumber, PrefixZero, GetTable } = require('./utils');

/**
 * 格式化时间戳
 * @param {String|Number} timestamp 
 */
function formatTs(timestamp) {
    if (!IsNumber(timestamp)) timestamp = Date.now()
    let ts = +timestamp;
    // 13位毫(秒) 10位(秒)
    const tsLen = String(timestamp).length
    if (tsLen === 10) ts *= 1000
    const _date = new Date(ts)
    const year = _date.getFullYear()
    const month = _date.getMonth() + 1
    const week = _date.getDay()
    const day = _date.getDate()
    const hour = _date.getHours()
    const minutes = _date.getMinutes()
    const seconds = _date.getSeconds()
    const milliseconds = _date.getMilliseconds()
    const fullMonth = PrefixZero(month)
    const fullDay = PrefixZero(day)
    const fullHour = PrefixZero(hour)
    const fullMinutes = PrefixZero(minutes)
    const fullSeconds = PrefixZero(seconds)

    const YMD = [year, '-', month, '-', day, ' ', hour, ':', minutes, ':', seconds].join('')
    const FullYMD = [year, '-', fullMonth, '-', fullDay, ' ', fullHour, ':', fullMinutes, ':', fullSeconds].join('')

    const rows = [
        ['简', year, month, day, week, hour, minutes, seconds, milliseconds, YMD, timestamp],
        ['繁', year, fullMonth, fullDay, week, fullHour, fullMinutes, fullSeconds, milliseconds, FullYMD, timestamp]
    ]
    const head = ['\\', '年', '月', '日', '星期', '时', '分', '秒', '毫秒', 'YMD Hms', 'timestamp']
    return GetTable(rows, head)
}

exports.FmtTimestamp = function (ts) {
    const msg = formatTs(ts)
    return { ok: true, msg }
}