Here is a simple 8th sample on how to get sunrise/sunset times for given location. I use this stuff in my home automation software.
needs astro/sunrise
needs geo/cities
\ Set location
: location! \ m --
["lat", "lon"] m:_@ a:open
astro:longitude ! astro:latitude ! ;
: d:tzoffset? \ -- n
"%Z" d:new d:format ":" s:/ ' >n a:map
[60,1] ' n:* a:2map ' n:+ 0 a:reduce ;
: astro \ d -- sunrise sunset
"%Y-%M-%DT" over d:format >r astro:sunrise 2 a:close
( 60 n:* 60 n:/mod "%02d:%02d:00+00:00" s:strfmt r@ swap s:+ d:parse d:tzoffset? d:tzadjust ) a:map
rdrop a:open ;
: sunrise? \ d -- d
astro drop ;
: sunset? \ d -- d
astro nip ;
: app:main
argc 2 n:= !if
"Requires city and country code as params" throw
then
0 args 1 args loc:city_country 0 a:_@ null? if
"Could not find location" throw
else
location! d:new astro 2 a:close ["Sunrise at: %H:%T:%S%Z", "and sunset at: %H:%T:%S%Z.\n"] ' d:format a:2map
" " a:join .
then ;
Sample takes city and country code as input parameters from command line and outputs sunrise and sunset times as local time:
ohjaus@raspberrypi:~ $ /opt/8th/bin/rpi64/8th astro.8th Hämeenlinna FI
Sunrise at: 06:15:00+03:00 and sunset at: 20:26:00+03:00.
ohjaus@raspberrypi:~ $