All files / src types.ts

100% Statements 100/100
100% Branches 0/0
100% Functions 0/0
100% Lines 100/100

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1011x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Compute topocentric zenith and azimuth angles only.
 * Does not compute sunrise, sunset, or solar noon.
 */
export const SPA_ZA = 0 as const;
 
/**
 * Compute zenith, azimuth, and incidence angle for a tilted surface.
 * Requires slope and azm_rotation in SpaOptions.
 */
export const SPA_ZA_INC = 1 as const;
 
/**
 * Compute sunrise, sunset, and sun transit (solar noon) in addition to
 * zenith and azimuth. This is the default function code.
 */
export const SPA_ZA_RTS = 2 as const;
 
/**
 * Compute all outputs: zenith, azimuth, incidence angle, sunrise, sunset,
 * and sun transit. Combines SPA_ZA_INC and SPA_ZA_RTS.
 */
export const SPA_ALL = 3 as const;
 
export type SpaFunctionCode =
  | typeof SPA_ZA
  | typeof SPA_ZA_INC
  | typeof SPA_ZA_RTS
  | typeof SPA_ALL;
 
export interface SpaOptions {
  /** Observer elevation in meters above sea level. Default: 0. */
  elevation?: number;
  /** Atmospheric pressure in millibars. Default: 1013. */
  pressure?: number;
  /** Temperature in degrees Celsius. Default: 15. */
  temperature?: number;
  /** UT1-UTC correction in seconds. Default: 0. */
  delta_ut1?: number;
  /** TT-UTC difference in seconds. Default: 67. */
  delta_t?: number;
  /** Surface slope in degrees from horizontal. Default: 0. */
  slope?: number;
  /** Surface azimuth rotation in degrees from south. Default: 0. */
  azm_rotation?: number;
  /** Atmospheric refraction at sunrise/sunset in degrees. Default: 0.5667. */
  atmos_refract?: number;
  /** SPA function code. Default: SPA_ZA_RTS (2). */
  function?: SpaFunctionCode;
}
 
export interface SpaResult {
  /** Topocentric zenith angle in degrees. */
  zenith: number;
  /** Topocentric azimuth angle, eastward from north (navigational convention), in degrees. */
  azimuth: number;
  /** Local sunrise time as fractional hours. */
  sunrise: number;
  /** Local sun transit time (solar noon) as fractional hours. */
  solarNoon: number;
  /** Local sunset time as fractional hours. */
  sunset: number;
}
 
export interface SpaFormattedResult {
  /** Topocentric zenith angle in degrees. */
  zenith: number;
  /** Topocentric azimuth angle, eastward from north (navigational convention), in degrees. */
  azimuth: number;
  /** Local sunrise time as HH:MM:SS string. "N/A" during polar day/night. */
  sunrise: string;
  /** Local sun transit time as HH:MM:SS string. "N/A" during polar day/night. */
  solarNoon: string;
  /** Local sunset time as HH:MM:SS string. "N/A" during polar day/night. */
  sunset: string;
}
 
export interface SpaAnglesResult {
  /** Sunrise time for this custom zenith angle. */
  sunrise: number;
  /** Sunset time for this custom zenith angle. */
  sunset: number;
}
 
export interface SpaResultWithAngles extends SpaResult {
  /** Custom angle results, one per angle in the input array. */
  angles: SpaAnglesResult[];
}
 
export interface SpaFormattedAnglesResult {
  /** Sunrise time for this custom zenith angle, formatted as HH:MM:SS. */
  sunrise: string;
  /** Sunset time for this custom zenith angle, formatted as HH:MM:SS. */
  sunset: string;
}
 
export interface SpaFormattedResultWithAngles extends SpaFormattedResult {
  /** Custom angle results with formatted times. */
  angles: SpaFormattedAnglesResult[];
}