Alla esimerkki auringonnousu -ja auringonlaskuaikojen selvittämiseen 8th ohjelmointikielellä. Käyttää 8th:n mukana tulevia dst -ja geo-tietokantoja hyödyksi. Haluaa komentoriviparametreinä paikkakunnan/kaupungin ja maatunnuksen.
Ajettessa komentoriviltä antaa tälle päivälle:
Koodi:
\
\ Requires at least Professional SKU.
\
needs astro/sunrise
needs date/utils
needs geo/cities
nullvar tz
: location! \ m --
["lat", "lon"] m:_@ a:open
astro:longitude ! astro:latitude ! ;
: 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 tz @ over d:dst-ofs d:tzadjust ) a:map
rdrop a:open ;
: sunrise? \ d -- d
astro drop ;
: sunset? \ d -- d
astro nip ;
: app:main
8thsku? 2 n:< if
"Requires at least Professional SKU.\n" .
;then
argc 2 n:= !if
"Requires city and country code as commandline arguments.\n" .
;then
0 args 1 args loc:city_country 0 a:_@ null? if
"Could not find location.\n" .
else
"tz" m:@ tz ! 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 ;
Ajettessa komentoriviltä antaa tälle päivälle:
Koodi:
C:\Users\Jali\Desktop\testi>8th sun.8th Hämeenlinna FI
Sunrise at: 09:32:00+02:00 and sunset at: 15:22:00+02:00.
C:\Users\Jali\Desktop\testi>
Viimeksi muokattu: