diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f96a52..e72e4a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,12 @@ All notable changes to this project will be documented in this file. ## [1.0.0] - 2023-11-11 - Initial release + +## [1.1.0] - 2023-11-11 + +- Unignored "dist" folder in git (major) + +## [1.2.1] - 2023-11-12 + +- Moved timezone to main args and changed default behavior (major) +- Updated test cases and readme to reflect new usage (minor) diff --git a/README.md b/README.md index 368e86f..9ff5b58 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,47 @@ npm install nrel-spa Basic usage examples: ```javascript -const { calcSpa } = require('nrel-spa'); +const { getSpa, calcSpa } = require('./index'); -const myLat = 40.7128; // Latitude for New York City -const myLng = -74.006; // Longitude for New York City -const myDate = new Date(); // Current date +const date = new Date(); +console.log(date) -const solarData = calcSpa(myDate, myLat, myLng); -console.log(solarData); +// NYC - minimum params +const city = "New York" +const lat = 40.7128; +const lng = -74.006; +const tz = null // optional +const params = null // optional +const angles = [] // optional + +/* Jakarta - all params +const city = "Jakarta" +const lat = -6.2088 +const lng = 106.8456 +const tz = 0 +const elevation = 18 +const temperature = 26.56 +const pressure = 1017 +const params = {elevation, temperature, pressure} +const angles = [63.435] */ + +// Get results +const get = getSpa(date, lat, lng); // minimum args +const calc = calcSpa(date, lat, lng, tz, params, angles); + +// Print results +console.log(`\nTest: ${city} with current Date():\n`) +console.log("getSpa =", get, "\n"); +console.log("calcSpa =", calc, "\n"); ``` ## API -Describe the functions and their parameters briefly. +Exporting getSpa, calcSpa, and fractalTime. Only date, lat, lng are required but if timezone (tz) is null, will return in UTC. + +- getSpa(date, lat, lng, tz, params, angles) // returns SPA results in fractal times +- getSpa(date, lat, lng, tz, params, angles) // returns SPA results in formatted times +- fractalTime(fractionalHour) // formats time from 10.767407706732804 to 10:46:02.667 ## Contributing diff --git a/index.js b/index.js index 7dbcc4a..4cb200c 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ function adjustForCustomAngle(baseSpaData, zenithAngle) { return adjustedData; } -function getSpa(date, lat, lng, tz, params = null, angles = []) { +function getSpa(date, lat, lng, tz = 0, params = null, angles = []) { let data = new spa.SpaData(); data.year = date.getFullYear(); data.month = date.getMonth() + 1; // JavaScript months are 0-indexed @@ -64,7 +64,7 @@ function getSpa(date, lat, lng, tz, params = null, angles = []) { return output; } -function calcSpa(date, lat, lng, tz, params = null, angles = []) { +function calcSpa(date, lat, lng, tz = 0, params = null, angles = []) { let rawData = getSpa(date, lat, lng, tz, params, angles); rawData.sunrise = fractalTime(rawData.sunrise); rawData.solarNoon = fractalTime(rawData.solarNoon); diff --git a/package.json b/package.json index a32c0b3..5e61399 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nrel-spa", - "version": "1.2.0", + "version": "1.2.1", "description": "NREL SPA native implementation in JS", "main": "index.js", "scripts": { diff --git a/test.js b/test.js index c3ffe54..0892d57 100644 --- a/test.js +++ b/test.js @@ -16,7 +16,7 @@ const angles = [] const city = "Jakarta" const lat = -6.2088 const lng = 106.8456 -const tz = 7 +const tz = 0 const elevation = 18 const temperature = 26.56 const pressure = 1017