Module suntime

Module to calculate ephemeris and other times depending on the sun position

Maximal errors from 2020-2050 are:

  • 33.58° Casablanca: 24s
  • 37.97° Athene: 25s
  • 41.91° Rome: 28s
  • 47.25° Innsbruck: 14s
  • 52.32° Berlin: 32s
  • 64.14° Reykjavik: 113s
  • 65.69° Akureyri: <110s (except *)
  • 70.67° Hammerfest: <105s (except **)

*) A few days around beginning of summer (error <530s)

**) A few days after and befor midnight sun (error <1200s)

Usage:

    local SunTime = require("suntime")
    
    time_zone = 0
    altitude = 50
    degree = true
    SunTime:setPosition("Reykjavik", 64.14381, -21.92626, timezone, altitude, degree)
    
    SunTime:setAdvanced()
    
    SunTime:setDate()
    
    SunTime:calculateTimes()
    
    print(SunTime.rise, SunTime.set, SunTime.set_civil) -- or similar see calculateTime()
    

Functions

SunTime:setPosition (name, latitude, longitude, time_zone, altitude, degree) Set position for later calculations
SunTime:setSimple () Use a simple equation of time (valid for the years 2008-2027)
SunTime:setAdvanced () Use an advanced equation of time (valid for the years 1800-2200 at least)
SunTime:calculateTimes () Calculates the ephemeris and twilight times


Functions

SunTime:setPosition (name, latitude, longitude, time_zone, altitude, degree)
Set position for later calculations

Parameters:

  • name Name of the location
  • latitude Geographical latitude, North is positive
  • longitude Geographical longitude, West is negative
  • time_zone Timezone e.g. CET = +1
  • altitude Altitude of the location above the sea level
  • degree if nil latitude and longitue are in radian, else in decimal degree
SunTime:setSimple ()
Use a simple equation of time (valid for the years 2008-2027)
SunTime:setAdvanced ()
Use an advanced equation of time (valid for the years 1800-2200 at least)
SunTime:calculateTimes ()
Calculates the ephemeris and twilight times

Usage:

    SunTime:calculateTime()
    
    Times are in hours or nil if not applicable.
    
    You can then access:
        self.rise_astronomic
        self.rise_nautic
        self.rise_civil
        self.rise
    
        self.noon
    
        self.set
        self.set_civil
        self.set_nautic
        self.set_astronomic
    
        self.midnight
    
    Or as values in a table:
        self.times[1]  midnight - 24h
        self.times[2]  rise_astronomic
        self.times[3]  rise_nautic
        self.times[4]  rise_civil
        self.times[5]  rise
        self.times[6]  noon
        self.times[7]  set
        self.times[8]  set_civil
        self.times[9]  set_nautic
        self.times[10] set_astronomic
        self.times[11] midnight
generated by LDoc 1.4.6 Last updated 2021-12-04 18:04:16