import dayjs from 'dayjs';
import durationPlugin from 'dayjs/plugin/duration';
import utcPlugin from 'dayjs/plugin/utc';

dayjs.extend(utcPlugin);
dayjs.extend(durationPlugin);

export const getFileName = (fileName: string, extension: string, customDate: Date) => {
  const date = customDate || new Date();

  return `${fileName}-${dayjs(date).format('DD-MM-YYYY')}.${extension}`;
};

export const formatTagLogTime = (timestamp: number) => {
  let totalMinutes = Math.floor(dayjs.duration(timestamp).asMinutes()).toString();

  if (totalMinutes.length === 1) {
    totalMinutes = `00${totalMinutes}`;
  }

  if (totalMinutes.length === 2) {
    totalMinutes = `0${totalMinutes}`;
  }

  return `${totalMinutes}:${dayjs(timestamp).utc().format('ss:SSS').toString()}`;
};

export default {};
