Skip to content

Commit

Permalink
Make getDownloadFilename() work correctly with start/end parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Aug 17, 2022
1 parent 47cd5c7 commit ec4e1c7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 47 deletions.
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/rest-api",
"version": "3.19.4",
"version": "3.19.5",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal"
Expand All @@ -21,8 +21,8 @@
"url": "https://github.com/hebcal/hebcal-rest-api/issues"
},
"dependencies": {
"@hebcal/core": "^3.42.1",
"@hebcal/leyning": "^4.17.0"
"@hebcal/core": "^3.42.2",
"@hebcal/leyning": "^4.19.1"
},
"scripts": {
"build": "rollup -c",
Expand Down Expand Up @@ -52,11 +52,11 @@
"@rollup/plugin-node-resolve": "^13.3.0",
"ava": "^4.3.1",
"core-js": "^3.24.1",
"eslint": "^8.21.0",
"eslint": "^8.22.0",
"eslint-config-google": "^0.14.0",
"jsdoc": "^3.6.11",
"jsdoc-to-markdown": "^7.1.1",
"rollup": "^2.77.3",
"rollup": "^2.78.0",
"rollup-plugin-terser": "^7.0.2"
}
}
33 changes: 23 additions & 10 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {flags, Zmanim} from '@hebcal/core';
import {flags, Zmanim, HDate} from '@hebcal/core';
import * as leyning from '@hebcal/leyning';
import holidayDescription from './holidays.json';
import countryNames from './countryNames.json';
Expand Down Expand Up @@ -51,14 +51,27 @@ export function makeAnchor(s) {
* @return {string}
*/
export function getDownloadFilename(options) {
let fileName = 'hebcal_' + options.year;
if (options.isHebrewYear) {
fileName += 'h';
}
if (options.month) {
fileName += '_' + options.month;
let fileName = 'hebcal';
if (options.year) {
fileName += '_' + options.year;
if (options.isHebrewYear) {
fileName += 'h';
}
if (options.month) {
fileName += '_' + options.month;
}
} else if (typeof options.start === 'object' && typeof options.end === 'object') {
const start = new HDate(options.start);
const end = new HDate(options.end);
const y1 = start.greg().getFullYear();
const y2 = end.greg().getFullYear();
if (y1 === y2) {
fileName += '_' + y1;
} else {
fileName += '_' + y1 + '_' + y2;
}
}
if (options.location) {
if (typeof options.location === 'object') {
const loc = options.location;
const name = loc.zip || loc.asciiname || loc.getShortName();
if (name) {
Expand All @@ -76,7 +89,7 @@ export function pad2(number) {
if (number < 10) {
return '0' + number;
}
return String(number);
return '' + number;
}

/**
Expand All @@ -93,7 +106,7 @@ export function pad4(number) {
} else if (number < 1000) {
return '0' + number;
}
return String(number);
return '' + number;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/common.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,26 @@ test('shouldRenderBrief', (t) => {
new Date(), Location.lookup('Boston'))), true);
t.is(shouldRenderBrief(new DafYomiEvent(new HDate(25, 'Sivan', 5782))), true);
});

test('getDownloadFilename-nodate', (t) => {
t.is(getDownloadFilename({}), 'hebcal');
});

test('getDownloadFilename-year-month', (t) => {
t.is(getDownloadFilename({year: 1993, month: 6}), 'hebcal_1993_6');
});

test('getDownloadFilename-start-end', (t) => {
t.is(getDownloadFilename({
start: new Date(1995, 10, 10),
end: new Date(1996, 2, 2),
}), 'hebcal_1995_1996');
t.is(getDownloadFilename({
start: new Date(2022, 10, 10),
end: new Date(2022, 11, 11),
}), 'hebcal_2022');
t.is(getDownloadFilename({
start: new HDate(new Date(2021, 1, 13)),
end: new HDate(new Date(2021, 11, 13)),
}), 'hebcal_2021');
});

0 comments on commit ec4e1c7

Please sign in to comment.