Skip to content

Commit

Permalink
Supported new date change format
Browse files Browse the repository at this point in the history
  • Loading branch information
Afgan0r committed Oct 10, 2024
1 parent 959c537 commit 3d85dee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/!tests/unit-tests/0 - utils/namesHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ test('getId without generating name changes should throw error', () => {
expect(getPlayerId).toThrow('Список смен ников не был инициализирован');
});

/* eslint-disable no-console */
test('prepareNamesList without file should send message', () => {
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => { throw new Error(); });

Expand All @@ -57,7 +56,6 @@ test('prepareNamesList without file should send message', () => {

resetNamesList();
});
/* eslint-enable no-console */

test('Prepare names changes list snapshot', () => {
jest.mock('csv-parse');
Expand Down
12 changes: 7 additions & 5 deletions src/0 - utils/namesHelper/prepareNamesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { configPath } from '../paths';
import pipe from '../pipe';
import { findNameInfo } from './findNameInfo';
import moscowDateToUTC from './moscowDateToUTC';
import { dateFormat, delimiter } from './utils/consts';
import { dateFormat, delimiter, nameChangeDateFormat } from './utils/consts';
import { NamesList } from './utils/types';

// accepted | declined
Expand Down Expand Up @@ -42,10 +42,12 @@ const filter = (records: RawCSVContentType[]) => records.filter(
(record) => record.Статус === 'Принято',
);
const order = (records: RawCSVContentType[]) => (
records.sort((first, second) => (
dayjsUTC(first['Дата смены ника'], dateFormat)
.isAfter(dayjsUTC(second['Дата смены ника'], dateFormat)) ? 1 : -1
))
records.sort((first, second) => {
const firstDate = dayjsUTC(first['Дата смены ника'], nameChangeDateFormat);
const secondDate = dayjsUTC(second['Дата смены ника'], nameChangeDateFormat);

return firstDate.isAfter(secondDate) ? 1 : -1;
})
);

export const prepareNamesList = (): void => {
Expand Down
2 changes: 2 additions & 0 deletions src/0 - utils/namesHelper/utils/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const dateFormat = 'DD.MM.YYYY HH:mm';

export const nameChangeDateFormat = 'DD.MM.YYYY H:mm';

export const delimiter = '_';

0 comments on commit 3d85dee

Please sign in to comment.