Skip to content

Commit

Permalink
fix(cli): file name with hours and minutes (#160)
Browse files Browse the repository at this point in the history
* fix(cli): file name with hours and minutes
  • Loading branch information
Leo4815162342 authored Sep 17, 2023
1 parent e6b7c79 commit e52ff34
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import chalk from 'chalk';
import debug from 'debug';

import { version } from '../../package.json';
import { getDateString } from '../utils/date';
import { BatchStreamWriter } from '../stream-writer';
import { BufferObject } from '../buffer-fetcher/types';
import { formatTimeDuration } from '../utils/formatTimeDuration';
Expand Down Expand Up @@ -83,11 +82,29 @@ export async function run(argv: NodeJS.Process['argv']) {

const fileExtension = format === Format.csv ? Format.csv : Format.json;

const dateRangeStr = [startDate, endDate]
.map(date => {
let cutoff = 10;
const hasHours = date.getUTCHours() !== 0;
const hasMinutes = date.getUTCMinutes() !== 0;

if (hasHours) {
cutoff = 13;
}

if (hasMinutes) {
cutoff = 16;
}

return date.toISOString().slice(0, cutoff);
})
.join('-');

const fileName = customFileName
? `${customFileName}.${fileExtension}`
: `${instrument}-${timeframe}${timeframe === 'tick' ? '' : '-' + priceType}-${getDateString(
startDate
)}-${getDateString(endDate)}.${fileExtension}`;
: `${instrument}-${timeframe}${
timeframe === 'tick' ? '' : '-' + priceType
}-${dateRangeStr}.${fileExtension}`;
const folderPath = resolve(process.cwd(), dir);
const filePath = resolve(folderPath, fileName);

Expand Down
4 changes: 2 additions & 2 deletions src/cli/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const testCases = [
{
timeframe: 'tick',
options: '-i btcusd -from 2023-02-20T12:00:00.000Z -to 2023-02-20T13:00:00.000Z -t tick',
fileName: 'btcusd-tick-2023-02-20-2023-02-20.json'
fileName: 'btcusd-tick-2023-02-20T12-2023-02-20T13.json'
},
{
timeframe: 's1',
options: '-i btcusd -from 2023-02-20T12:00:00.000Z -to 2023-02-20T13:00:00.000Z -t s1',
fileName: 'btcusd-s1-bid-2023-02-20-2023-02-20.json'
fileName: 'btcusd-s1-bid-2023-02-20T12-2023-02-20T13.json'
},
{
timeframe: 'm1',
Expand Down

0 comments on commit e52ff34

Please sign in to comment.