From ec4e1c7f142335183fa77c6bdd1584101eb30117 Mon Sep 17 00:00:00 2001 From: "Michael J. Radwin" Date: Wed, 17 Aug 2022 15:41:11 -0700 Subject: [PATCH] Make getDownloadFilename() work correctly with start/end parameters --- package-lock.json | 64 +++++++++++++++++++++++----------------------- package.json | 10 ++++---- src/common.js | 33 ++++++++++++++++-------- src/common.spec.js | 23 +++++++++++++++++ 4 files changed, 83 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8a060bd..7de1b0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@hebcal/rest-api", - "version": "3.19.3", + "version": "3.19.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hebcal/rest-api", - "version": "3.19.3", + "version": "3.19.5", "license": "BSD-2-Clause", "dependencies": { - "@hebcal/core": "^3.42.1", - "@hebcal/leyning": "^4.17.0" + "@hebcal/core": "^3.42.2", + "@hebcal/leyning": "^4.19.1" }, "devDependencies": { "@babel/core": "^7.18.10", @@ -22,11 +22,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" } }, @@ -1680,19 +1680,19 @@ } }, "node_modules/@hebcal/core": { - "version": "3.42.1", - "resolved": "https://registry.npmjs.org/@hebcal/core/-/core-3.42.1.tgz", - "integrity": "sha512-f26fLbilLDifcTPa3U9aKnoSj0aUx5OqPriJaUKEjlUz1SiN6DM2e1IRXyqJ/E20u+2GBesemXQS4/Xzxz+tpw==", + "version": "3.42.2", + "resolved": "https://registry.npmjs.org/@hebcal/core/-/core-3.42.2.tgz", + "integrity": "sha512-JaXBhlAr3Pquw/uTL58oRTG5W14B60AUEO68nmhWSTgwPJ/GyhF0S3dk/iRJ2UdMouhdlSCRyuiqSf9X7NmYag==", "engines": { "node": ">=10.21.0" } }, "node_modules/@hebcal/leyning": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/@hebcal/leyning/-/leyning-4.17.0.tgz", - "integrity": "sha512-dbqevYNcUgw2AO8QX1+sq8FJEb6TlCceGpscY0284xbvDpPUKoskzgktoLUExU6vMw8VZFQkh590zxQulm9CZA==", + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/@hebcal/leyning/-/leyning-4.19.1.tgz", + "integrity": "sha512-XiXHrzHkXliqevTgzNdmsRClpxWYqzzpeslSOiRA6Jg4HV8K0WMhHhz2eWj013O1ORXTLQ+UcRWDGXPDtTOuhw==", "dependencies": { - "@hebcal/core": "^3.42.1" + "@hebcal/core": "^3.42.2" }, "bin": { "leyning-csv": "bin/leyning-csv" @@ -3216,9 +3216,9 @@ } }, "node_modules/eslint": { - "version": "8.21.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.21.0.tgz", - "integrity": "sha512-/XJ1+Qurf1T9G2M5IHrsjp+xrGT73RZf23xA1z5wB1ZzzEAWSZKvRwhWxTFp1rvkvCfwcvAUNAP31bhKTTGfDA==", + "version": "8.22.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.22.0.tgz", + "integrity": "sha512-ci4t0sz6vSRKdmkOGmprBo6fmI4PrphDFMy5JEq/fNS0gQkJM3rLmrqcp8ipMcdobH3KtUP40KniAE9W19S4wA==", "dev": true, "dependencies": { "@eslint/eslintrc": "^1.3.0", @@ -5618,9 +5618,9 @@ } }, "node_modules/rollup": { - "version": "2.77.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.77.3.tgz", - "integrity": "sha512-/qxNTG7FbmefJWoeeYJFbHehJ2HNWnjkAFRKzWN/45eNBBF/r8lo992CwcJXEzyVxs5FmfId+vTSTQDb+bxA+g==", + "version": "2.78.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.78.0.tgz", + "integrity": "sha512-4+YfbQC9QEVvKTanHhIAFVUFSRsezvQF8vFOJwtGfb9Bb+r014S+qryr9PSmw8x6sMnPkmFBGAvIFVQxvJxjtg==", "dev": true, "bin": { "rollup": "dist/bin/rollup" @@ -7703,16 +7703,16 @@ } }, "@hebcal/core": { - "version": "3.42.1", - "resolved": "https://registry.npmjs.org/@hebcal/core/-/core-3.42.1.tgz", - "integrity": "sha512-f26fLbilLDifcTPa3U9aKnoSj0aUx5OqPriJaUKEjlUz1SiN6DM2e1IRXyqJ/E20u+2GBesemXQS4/Xzxz+tpw==" + "version": "3.42.2", + "resolved": "https://registry.npmjs.org/@hebcal/core/-/core-3.42.2.tgz", + "integrity": "sha512-JaXBhlAr3Pquw/uTL58oRTG5W14B60AUEO68nmhWSTgwPJ/GyhF0S3dk/iRJ2UdMouhdlSCRyuiqSf9X7NmYag==" }, "@hebcal/leyning": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/@hebcal/leyning/-/leyning-4.17.0.tgz", - "integrity": "sha512-dbqevYNcUgw2AO8QX1+sq8FJEb6TlCceGpscY0284xbvDpPUKoskzgktoLUExU6vMw8VZFQkh590zxQulm9CZA==", + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/@hebcal/leyning/-/leyning-4.19.1.tgz", + "integrity": "sha512-XiXHrzHkXliqevTgzNdmsRClpxWYqzzpeslSOiRA6Jg4HV8K0WMhHhz2eWj013O1ORXTLQ+UcRWDGXPDtTOuhw==", "requires": { - "@hebcal/core": "^3.42.1" + "@hebcal/core": "^3.42.2" } }, "@humanwhocodes/config-array": { @@ -8865,9 +8865,9 @@ "dev": true }, "eslint": { - "version": "8.21.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.21.0.tgz", - "integrity": "sha512-/XJ1+Qurf1T9G2M5IHrsjp+xrGT73RZf23xA1z5wB1ZzzEAWSZKvRwhWxTFp1rvkvCfwcvAUNAP31bhKTTGfDA==", + "version": "8.22.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.22.0.tgz", + "integrity": "sha512-ci4t0sz6vSRKdmkOGmprBo6fmI4PrphDFMy5JEq/fNS0gQkJM3rLmrqcp8ipMcdobH3KtUP40KniAE9W19S4wA==", "dev": true, "requires": { "@eslint/eslintrc": "^1.3.0", @@ -10623,9 +10623,9 @@ } }, "rollup": { - "version": "2.77.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.77.3.tgz", - "integrity": "sha512-/qxNTG7FbmefJWoeeYJFbHehJ2HNWnjkAFRKzWN/45eNBBF/r8lo992CwcJXEzyVxs5FmfId+vTSTQDb+bxA+g==", + "version": "2.78.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.78.0.tgz", + "integrity": "sha512-4+YfbQC9QEVvKTanHhIAFVUFSRsezvQF8vFOJwtGfb9Bb+r014S+qryr9PSmw8x6sMnPkmFBGAvIFVQxvJxjtg==", "dev": true, "requires": { "fsevents": "~2.3.2" diff --git a/package.json b/package.json index 390628f..4a8dff5 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", @@ -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" } } diff --git a/src/common.js b/src/common.js index 2e854e2..226236d 100644 --- a/src/common.js +++ b/src/common.js @@ -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'; @@ -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) { @@ -76,7 +89,7 @@ export function pad2(number) { if (number < 10) { return '0' + number; } - return String(number); + return '' + number; } /** @@ -93,7 +106,7 @@ export function pad4(number) { } else if (number < 1000) { return '0' + number; } - return String(number); + return '' + number; } /** diff --git a/src/common.spec.js b/src/common.spec.js index 7d11ef1..3032128 100644 --- a/src/common.spec.js +++ b/src/common.spec.js @@ -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'); +});