#!/bin/sh
#
# A little demo script that displays astronomical events
#
# Best used in a UTF-8 environment.
# SPDX-License-Identifier: GPL-2.0-only

# Set your latitude and longitude correctly for Sunrise/Sunset/Equinox/Solstice
#
# The values below are for Ottawa, Ontario, Canada
latitude="45.420556"
longitude="-75.689722"

remind -g "-i\$Latitude=\"$latitude\"" "-i\$Longitude=\"$longitude\"" -q -@2 - "$@" <<'EOF'
SET $AddBlankLines 0
BANNER %

REM FMT Today is <b>[$T]</b>, being the [ord($T-date(year($T),1,1)+1)] day of [year($T)].
MSG Not including today, the year [year($T)] has [date(year($T)+1, 1, 1)-$T-1] more [plural(date(year($T)+1, 1, 1)-$T-1, "day")] left.%_

IF $TerminalBackground == 0
   SPECIAL COLOR 255 255 0 Sunrise:               🌅 [sunrise()] today and [sunrise($T+1)] tomorrow
   SPECIAL COLOR 255 128 0 Sunset:                🌇 [sunset()] today and [sunset($T+1)] tomorrow%_
ELSE
   SPECIAL COLOR 128 128 0 Sunrise:               🌅 [sunrise()] today and [sunrise($T+1)] tomorrow
   SPECIAL COLOR 128 32 0 Sunset:                🌇 [sunset()] today and [sunset($T+1)] tomorrow%_

ENDIF
EOF

remind -g "-i\$Latitude=\"$latitude\"" "-i\$Longitude=\"$longitude\"" -q -@2 - "$@" <<'EOF'
SET $AddBlankLines 0
FSET angle_to_direction(x) \
IIF(x > 348 && x <= 11, "North", \
    x > 11 && x <= 34, "North North-East", \
    x > 34 && x <= 56, "North-East", \
    x > 56 && x <= 79, "East North-East", \
    x > 79 && x <= 101, "East", \
    x > 101 && x <= 124, "East South-East", \
    x > 124 && x <= 146, "South-East", \
    x > 146 && x <= 169, "South South-East", \
    x > 169 && x <= 191, "South", \
    x > 191 && x <= 214, "South South-West", \
    x > 214 && x <= 236, "South-West", \
    x > 236 && x <= 259, "West South-West", \
    x > 259 && x <= 281, "West", \
    x > 281 && x <= 304, "West North-West", \
    x > 304 && x <= 326, "North-West", \
    "North North-West")

BANNER %
set mr moonrise()
set ms moonset()
set mr_a moonrisedir()
set ms_a moonsetdir()

REM NOQUEUE [mr] MSG Moonrise:              %*3 in the [angle_to_direction(mr_a)] ([mr_a] degrees)
REM NOQUEUE [ms] MSG Moonset:               %*3 in the [angle_to_direction(ms_a)] ([ms_a] degrees)

IF (datepart(mr) != today())
    REM MSG Moonrise:              No moonrise today
ENDIF
IF (datepart(ms) != today())
    REM MSG Moonset:               No moonset today
ENDIF
EOF

echo ""


remind -g "-i\$Latitude=\"$latitude\"" "-i\$Longitude=\"$longitude\"" -q -@2 - "$@" <<'EOF'
SET $AddBlankLines 0
FSET angle_to_direction(x) \
IIF(x > 348 || x <= 11, "North", \
    x > 11 && x <= 34, "North North-East", \
    x > 34 && x <= 56, "North-East", \
    x > 56 && x <= 79, "East North-East", \
    x > 79 && x <= 101, "East", \
    x > 101 && x <= 124, "East South-East", \
    x > 124 && x <= 146, "South-East", \
    x > 146 && x <= 169, "South South-East", \
    x > 169 && x <= 191, "South", \
    x > 191 && x <= 214, "South South-West", \
    x > 214 && x <= 236, "South-West", \
    x > 236 && x <= 259, "West South-West", \
    x > 259 && x <= 281, "West", \
    x > 281 && x <= 304, "West North-West", \
    x > 304 && x <= 326, "North-West", \
    "North North-West")

BANNER %
IF $TerminalBackground == 0
   REM [moondatetime(0)] +60 SPECIAL COLOR 255 255 0 New moon:              🌑 [$T] %3 (%b)
   REM [moondatetime(1)] +60 SPECIAL COLOR 255 255 128 First Quarter:         🌓 [$T] %3 (%b)
   REM [moondatetime(2)] +60 SPECIAL COLOR 255 255 255 Full moon:             🌕 [$T] %3 (%b)
   REM [moondatetime(3)] +60 SPECIAL COLOR 255 255 128 Last Quarter:          🌗 [$T] %3 (%b)
ELSE
   REM [moondatetime(0)] +60 SPECIAL COLOR 128 128 0 New moon:              🌑 [$T] %3 (%b)
   REM [moondatetime(1)] +60 SPECIAL COLOR 128 128 64 First Quarter:         🌓 [$T] %3 (%b)
   REM [moondatetime(2)] +60 SPECIAL COLOR 0 0 0 Full moon:             🌕 [$T] %3 (%b)
   REM [moondatetime(3)] +60 SPECIAL COLOR 128 128 64 Last Quarter:          🌗 [$T] %3 (%b)
ENDIF
EOF

echo ""

remind -g "-i\$Latitude=\"$latitude\"" "-i\$Longitude=\"$longitude\"" -q -@2 - "$@" <<'EOF'
SET $AddBlankLines 0
BANNER %

IF $LatDeg >= 0
   REM [soleq(0)] +366 MSG Next Vernal Equinox:   🌼 [$T] %3 (%b)
   REM [soleq(1)] +366 MSG Next Summer Solstice:  😎 [$T] %3 (%b)
   REM [soleq(2)] +366 MSG Next Autumnal Equinox: 🍂 [$T] %3 (%b)
   REM [soleq(3)] +366 MSG Next Winter Solstice:  ❄️  [$T] %3 (%b)
ELSE
   REM [soleq(0)] +366 MSG Next Autumnal Equinox: 🍂 [$T] %3 (%b)
   REM [soleq(1)] +366 MSG Next Winter Solstice:  ❄️  [$T] %3 (%b)
   REM [soleq(2)] +366 MSG Next Vernal Equinox:   🌼 [$T] %3 (%b)
   REM [soleq(3)] +366 MSG Next Summer Solstice:  😎 [$T] %3 (%b)
ENDIF

EOF
