mirror of
https://github.com/acamarata/pray-calc.git
synced 2026-06-30 19:04:26 +00:00
Fixes for 1.6.1
This commit is contained in:
parent
b5ee3ca8b8
commit
6950f5a291
5 changed files with 149 additions and 63 deletions
16
CHANGELOG.md
16
CHANGELOG.md
|
|
@ -15,14 +15,24 @@ All notable changes to this project will be documented in this file.
|
|||
- Moved timezone to main args and changed default behavior (major)
|
||||
- Updated test cases and readme to reflect new usage (minor)
|
||||
|
||||
## [1.3.2] - 2013-11-13
|
||||
## [1.3.2] - 2023-11-13
|
||||
|
||||
- Major updates to getMoon with own functions
|
||||
|
||||
## [1.4.0] - 2013-11-14
|
||||
## [1.4.0] - 2023-11-14
|
||||
|
||||
- Renamed to "pray-calc" and removed old package
|
||||
- Improved Synodic accuracy slightly and lastKnownMoon
|
||||
|
||||
## [1.4.1] = 2013-12-01
|
||||
## [1.4.1] = 2023-12-01
|
||||
- Modified getMoonVisibility to use adjusted moon phase for end of cycle
|
||||
|
||||
## [1.6.0] = 2025-05-04
|
||||
- Major fixes for core files and calculations
|
||||
- Updated to use the new "nrel-spa" v1.3.0
|
||||
|
||||
## [1.6.1] - 2025-05-04
|
||||
### Fixed
|
||||
- Fixed missing modules and types definitions lost in last update
|
||||
- Locked `suncalc` dependency to `^1.9.0`
|
||||
- Clarified scripts: `build`, `test`, and `prepublishOnly` in `package.json`
|
||||
|
|
|
|||
22
LICENSE
22
LICENSE
|
|
@ -1,7 +1,21 @@
|
|||
ISC License
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023, [Your Full Name]
|
||||
Copyright (c) 2023 Ummat
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -75,4 +75,4 @@ Contributions are welcome!
|
|||
|
||||
## License
|
||||
|
||||
ISC License
|
||||
MIT License
|
||||
|
|
|
|||
66
package.json
66
package.json
|
|
@ -1,43 +1,45 @@
|
|||
{
|
||||
"name": "pray-calc",
|
||||
"version": "1.6.0",
|
||||
"description": "Prayer times calculator using nrel-spa and custom formula for Fajr and Isha angles (as well as traditional static angle methods)",
|
||||
"version": "1.6.1",
|
||||
"description": "Accurate prayer times using nrel-spa and moon functions via suncalc",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ummeco/pray-calc.git"
|
||||
},
|
||||
"keywords": [
|
||||
"prayer",
|
||||
"islam",
|
||||
"fajr",
|
||||
"dhuhr",
|
||||
"asr",
|
||||
"maghrib",
|
||||
"isha",
|
||||
"nrel-spa",
|
||||
"solar-position"
|
||||
],
|
||||
"author": "Ummat",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ummeco/pray-calc/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ummeco/pray-calc#readme",
|
||||
"dependencies": {
|
||||
"nrel-spa": "^1.3.0",
|
||||
"suncalc": "^1.9.0"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"getTimes.js",
|
||||
"getAsr.js",
|
||||
"getAngles.js",
|
||||
"calcTimesAll.js",
|
||||
"getQiyam.js",
|
||||
"getMoonPosition.js",
|
||||
"getMoonIllumination.js",
|
||||
"getMoonPhase.js",
|
||||
"getMoonVisibility.js",
|
||||
"getMoon.js",
|
||||
"getEarthSunDistance.js",
|
||||
"methods.json",
|
||||
"dist/",
|
||||
"README.md",
|
||||
"CHANGELOG.md"
|
||||
]
|
||||
}
|
||||
],
|
||||
"scripts": {
|
||||
"build": "babel src -d dist",
|
||||
"test": "mocha test/*.js",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"keywords": [
|
||||
"prayer-times",
|
||||
"Islam",
|
||||
"nrel-spa",
|
||||
"suncalc",
|
||||
"moon",
|
||||
"qiyam"
|
||||
],
|
||||
"author": "Your Name <you@example.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nrel-spa": "^1.3.0",
|
||||
"suncalc": "^1.9.0"
|
||||
}
|
||||
}
|
||||
106
test-year.js
106
test-year.js
|
|
@ -1,34 +1,94 @@
|
|||
// test-year.js
|
||||
const { calcTimes } = require('./index');
|
||||
|
||||
function formatTime(timeString) {
|
||||
return timeString.slice(0, -4); // Trims the last 4 characters (".427")
|
||||
/**
|
||||
* Get the DST‑aware offset (hours east of UTC) for America/New_York
|
||||
* at the given UTC date.
|
||||
*/
|
||||
function getNYCOffsetHours(dateUtc) {
|
||||
const str = dateUtc.toLocaleString('en-US', {
|
||||
timeZone: 'America/New_York',
|
||||
timeZoneName: 'shortOffset',
|
||||
hour12: false,
|
||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
||||
});
|
||||
// Matches "GMT-05:00" or "GMT-5"
|
||||
const m = str.match(/GMT([+-]\d{1,2})(?::(\d{2}))?$/);
|
||||
if (!m) throw new Error(`Cannot parse offset from "${str}"`);
|
||||
const hrs = parseInt(m[1], 10);
|
||||
const mins = m[2] ? parseInt(m[2], 10) : 0;
|
||||
return hrs + mins / 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a UTC date as "Mon D" (e.g. "Jan 1"), in NY time, padded to 7 chars.
|
||||
*/
|
||||
function formatLabel(dateUtc) {
|
||||
const parts = dateUtc.toLocaleString('en-US', {
|
||||
timeZone: 'America/New_York',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
}).split(' ');
|
||||
const mon = parts[0];
|
||||
const day = parts[1].padStart(2, ' ');
|
||||
return `${mon} ${day}`.padEnd(7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a prayer time (string "HH:MM:SS.xxx" or Date) as "HH:MM:SS" in NY time.
|
||||
*/
|
||||
function formatTime(val) {
|
||||
if (typeof val === 'string') {
|
||||
return val.slice(0, 8); // strip fractional seconds
|
||||
}
|
||||
const dt = new Date(val);
|
||||
if (isNaN(dt)) return 'Invalid';
|
||||
return dt.toLocaleTimeString('en-GB', {
|
||||
timeZone: 'America/New_York',
|
||||
hour12: false,
|
||||
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
||||
});
|
||||
}
|
||||
|
||||
function getNYCPrayerTimesForYear(year) {
|
||||
const lat = 40.7128; // Latitude for New York City
|
||||
const lng = -74.0060; // Longitude for New York City
|
||||
const elevation = 10; // Average elevation for NYC in meters
|
||||
const temperature = 15; // Average temperature for NYC in Celsius
|
||||
const pressure = 1013.25; // Average atmospheric pressure in millibars
|
||||
const lat = 40.7128, lng = -74.0060;
|
||||
const elevation = 10, temperature = 15, pressure = 1013.25;
|
||||
|
||||
let prayerTimesForYear = `NYC Prayer Times for ${year}:\n\n`;
|
||||
console.log(`\nNYC Prayer Times for ${year}\n`);
|
||||
const header = 'Date | Fajr | Sunrise | Dhuhr | Asr | Maghrib | Isha';
|
||||
console.log(header);
|
||||
console.log('-'.repeat(header.length));
|
||||
|
||||
for (let month = 0; month < 12; month++) {
|
||||
for (let day = 1; day <= new Date(year, month + 1, 0).getDate(); day++) {
|
||||
const date = new Date(year, month, day);
|
||||
const formattedDate = date.toDateString().substring(4, 10); // "Dec 31"
|
||||
const prayerTimes = calcTimes(date, lat, lng, elevation, temperature, pressure);
|
||||
for (let m = 0; m < 12; m++) {
|
||||
const daysInMonth = new Date(Date.UTC(year, m + 1, 0)).getUTCDate();
|
||||
for (let d = 1; d <= daysInMonth; d++) {
|
||||
// Use UTC midnight so we handle TZ separately
|
||||
const dateUtc = new Date(Date.UTC(year, m, d, 0, 0, 0));
|
||||
const tzOffset = getNYCOffsetHours(dateUtc);
|
||||
|
||||
prayerTimesForYear += `${formattedDate} = `;
|
||||
prayerTimesForYear += `${formatTime(prayerTimes.Fajr)} / `;
|
||||
prayerTimesForYear += `${formatTime(prayerTimes.Dhuhr)} / `;
|
||||
prayerTimesForYear += `${formatTime(prayerTimes.Asr)} / `;
|
||||
prayerTimesForYear += `${formatTime(prayerTimes.Maghrib)} / `;
|
||||
prayerTimesForYear += `${formatTime(prayerTimes.Isha)}\n`;
|
||||
}
|
||||
// calcTimes(date, lat, lng, tzOffset, elevation, temperature, pressure)
|
||||
const times = calcTimes(dateUtc, lat, lng, tzOffset, elevation, temperature, pressure);
|
||||
|
||||
// Support both PascalCase and camelCase keys
|
||||
const fajr = times.Fajr ?? times.fajr;
|
||||
const sunrise = times.Sunrise ?? times.sunrise;
|
||||
const dhuhr = times.Dhuhr ?? times.dhuhr;
|
||||
const asr = times.Asr ?? times.asr;
|
||||
const maghrib = times.Maghrib ?? times.maghrib;
|
||||
const isha = times.Isha ?? times.isha;
|
||||
|
||||
const cols = [fajr, sunrise, dhuhr, asr, maghrib, isha]
|
||||
.map(v => formatTime(v).padEnd(9));
|
||||
|
||||
console.log(
|
||||
`${formatLabel(dateUtc)}| ${cols[0]}| ${cols[1]}| ${cols[2]}| ${cols[3]}| ${cols[4]}| ${cols[5]}`
|
||||
);
|
||||
}
|
||||
|
||||
return prayerTimesForYear;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(getNYCPrayerTimesForYear(2023));
|
||||
// Accept a year argument, default to the current UTC year
|
||||
const arg = parseInt(process.argv[2], 10);
|
||||
const year = Number.isNaN(arg) ? new Date().getUTCFullYear() : arg;
|
||||
getNYCPrayerTimesForYear(year);
|
||||
Loading…
Reference in a new issue