Skip to content

Commit a455c9d

Browse files
committed
OS-agnostic dates #26
1 parent e78e666 commit a455c9d

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"dependencies": {
4444
"chalk": "^5.0.1",
4545
"commander": "^9.3.0",
46+
"date-fns": "^2.29.3",
4647
"esbuild": "^0.15.7",
4748
"eventemitter3": "^4.0.7",
4849
"get-stdin": "^9.0.0",

scripts/date.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { format, sub } from 'date-fns';
2+
3+
const startOffset = { months: 1 };
4+
const arg = process.argv[2];
5+
const now = new Date();
6+
7+
let date;
8+
9+
switch (arg) {
10+
case 'start':
11+
date = sub(now, startOffset);
12+
break;
13+
case 'end':
14+
default:
15+
date = now;
16+
break;
17+
}
18+
19+
const formattedDate = format(date, 'yyyy-MM-dd');
20+
21+
console.log(formattedDate);

scripts/search.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ DATA_DIRECTORY="../example-data"
66
MEDRXIV_SOURCE="medrxiv"
77
BIORXIV_SOURCE="biorxiv"
88

9-
START_DATE=$(date -v -1m +%Y-%m-%d)
10-
END_DATE=$(date +%Y-%m-%d)
9+
START_DATE=$(node date.js start)
10+
END_DATE=$(node date.js end)
1111

1212
echo "Fetching from ${BIORXIV_SOURCE} between ${START_DATE} and ${END_DATE}"
1313
biorxivPapers=$(node ../src/cli.js download --output="${DATA_DIRECTORY}/${END_DATE}_${BIORXIV_SOURCE}.json" --source=${BIORXIV_SOURCE} ${START_DATE} ${END_DATE})

0 commit comments

Comments
 (0)