import { compareAsc, format } from 'date-fns';
import { convertStringToDate } from './date-utils.service';

it('testar data YYYYMMDD', () => {
   const dateDFNS = convertStringToDate('20191122');

   expect(format(dateDFNS, 'yyyy-MM-dd')).toEqual(format(new Date(2019, 10, 22), 'yyyy-MM-dd'));
});

it('testar data YYYY/MM/DD', () => {
   const dateDFNS = convertStringToDate('2019/11/22');

   expect(format(dateDFNS, 'yyyy-MM-dd')).toEqual(format(new Date(2019, 10, 22), 'yyyy-MM-dd'));
});

it('testar data YYYY-MM-DD', () => {
   const dateDFNS = convertStringToDate('2019-11-22');

   expect(format(dateDFNS, 'yyyy-MM-dd')).toEqual(format(new Date(2019, 10, 22), 'yyyy-MM-dd'));
});

it('testar data YYYYMMDDHHmmss', () => {
   const dateDFNS = convertStringToDate('20140211113030');

   expect(format(dateDFNS, 'yyyy-MM-dd hh:mm:ss')).toEqual(
      format(new Date(2014, 1, 11, 11, 30, 30), 'yyyy-MM-dd hh:mm:ss'),
   );
});

it('testar data YYYY-MM-DD HH:mm:ss', () => {
   const dateDFNS = convertStringToDate('2014-02-11 11:30:30');

   expect(format(dateDFNS, 'yyyy-MM-dd hh:mm:ss')).toEqual(
      format(new Date(2014, 1, 11, 11, 30, 30), 'yyyy-MM-dd hh:mm:ss'),
   );
});

it('testar data ISO', () => {
   const dateDFNS = convertStringToDate('2014-02-11T11:30:30');

   expect(format(dateDFNS, 'yyyy-MM-dd hh:mm:ss')).toEqual(
      format(new Date(2014, 1, 11, 11, 30, 30), 'yyyy-MM-dd hh:mm:ss'),
   );
});
