export function isLogin() {
    return !!localStorage.getItem('member_token');
}

export function formatGMT(t, format) {
  // 传入的格式 "2026-04-01T14:06:56.5879258"
  if (!t)
    return
  const index = t.indexOf('T');
  const date = t.substring(0, index).split('-')
  const time = t.substring(index + 1).split(':')

  const year = date[0].padStart(4, '0');
  const month = date[1].padStart(2, '0');
  const day = date[2].padStart(2, '0');

  const hour = time[0].padStart(2, '0')
  const minute = time[1].padStart(2, '0')

  const sctime = time[2].split('.')

  const second = sctime[0].padStart(2, '0')
  const millisecond = sctime[1].substring(0, 2).padStart(2, '0')
  return format
    .replace('yyyy', year)
    .replace('MM', month)
    .replace('dd', day)
    .replace('HH', hour)
    .replace('mm', minute)
    .replace('ss', second)
    .replace('ms', millisecond);
}

export default { isLogin, formatGMT };