solar-spa/.github/wiki/api/functions/spaFormatted.md

1.8 KiB

solar-spa v2.0.1


solar-spa / spaFormatted

Function: spaFormatted()

spaFormatted(date, latitude, longitude, options?): Promise<SpaFormattedResult>

Defined in: index.ts:290

Purpose: Compute solar position with time fields formatted as HH:MM:SS strings. Inputs: same as spa(): date, latitude, longitude, options Outputs: Promise; sunrise/sunset/suntransit are strings, all other fields numbers Constraints: Delegates to spa() internally; throws under the same conditions. "N/A" is returned for sunrise/sunset/suntransit during polar day or polar night. SPORT: packages.md → solar-spa row

Parameters

date

Date

Date and time for the calculation

latitude

number

Observer latitude in degrees (-90 to 90)

longitude

number

Observer longitude in degrees (-180 to 180)

options?

SpaOptions

Optional observer and algorithm parameters

Returns

Promise<SpaFormattedResult>

Solar position result with sunrise, sunset, suntransit as HH:MM:SS strings

Throws

If date is not a valid Date, or if latitude/longitude/option fields are not numbers

Throws

If latitude/longitude are out of bounds, or if option fields are Infinity/NaN

Throws

If WASM memory allocation fails or SPA returns a non-zero error code

Example

import { spaFormatted } from 'solar-spa';
const result = await spaFormatted(new Date('2025-06-21T12:00:00Z'), 40.7128, -74.006, { timezone: -4 });
console.log(result.sunrise);    // "05:25:12"
console.log(result.suntransit); // "12:59:58"
console.log(result.sunset);     // "20:34:47"