All files / src/utils timestamp.ts

100% Statements 17/17
100% Branches 3/3
100% Functions 1/1
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x   1x 8x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x      
import dayjs, { Dayjs } from 'dayjs';
 
const timestampConverter = (timestamp: string | null): string => {
  if (timestamp === null) {
    return '';
  }
  const year: number = parseInt(timestamp.slice(0, 4));
  const month: number = parseInt(timestamp.slice(5, 7)) - 1;
  const date: number = parseInt(timestamp.slice(8, 10));
  const hour: number = parseInt(timestamp.slice(11, 13));
  const minute: number = parseInt(timestamp.slice(14, 16));
  // dayjs
  const jst: Dayjs = dayjs(new Date(year, month, date, hour, minute, 0, 0)).add(9, 'hour');
  const result: string = `${jst.get('year')}年 ${jst.get('month') + 1}月 ${jst.get('date')}日 ${jst.get(
    'hour'
  )}時${jst.get('minute')}分`;
  return result;
};
 
export { timestampConverter };