2023-10-08 14:43:07 +02:00
|
|
|
#!/bin/bash
|
2023-10-08 18:38:58 +02:00
|
|
|
# Correct Time to give the real 20H12 time (on UTC table) at a given longitude
|
2023-10-08 14:43:07 +02:00
|
|
|
# Input longitude in degrees (positive for East, negative for West)
|
2023-10-08 17:07:21 +02:00
|
|
|
longitude=$1
|
|
|
|
|
|
|
|
# Check if longitude is numeric
|
|
|
|
if ! [[ $longitude =~ ^[+-]?[0-9]+(\.[0-9]+)?$ ]]; then
|
|
|
|
echo "Invalid longitude input. Please provide a valid numeric value."
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-10-08 14:43:07 +02:00
|
|
|
|
|
|
|
# Determine if it's East or West longitude
|
2023-10-08 17:07:21 +02:00
|
|
|
if [ $(echo "$longitude >= 0" | bc) -eq 1 ]; then
|
2023-10-08 14:43:07 +02:00
|
|
|
direction="East"
|
|
|
|
else
|
|
|
|
direction="West"
|
|
|
|
fi
|
|
|
|
|
2023-10-08 17:07:21 +02:00
|
|
|
# Calculate the time offset in minutes using awk for floating-point arithmetic
|
|
|
|
offset_minutes=$(echo "$longitude * 4" | bc)
|
2023-10-08 14:43:07 +02:00
|
|
|
|
|
|
|
# Determine if it's ahead or behind UTC
|
|
|
|
if [ "$direction" == "West" ]; then
|
2023-10-08 17:07:21 +02:00
|
|
|
offset_minutes=$(echo "$offset_minutes * -1" | bc)
|
2023-10-08 14:43:07 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Calculate the solar noon time in UTC (12:00 PM)
|
|
|
|
solar_noon_utc_seconds=$((12 * 3600))
|
|
|
|
|
|
|
|
# Adjust the solar noon time by the offset in seconds
|
2023-10-08 17:07:21 +02:00
|
|
|
local_solar_noon_seconds=$(echo "$solar_noon_utc_seconds + ( $offset_minutes * 60 )" | bc | cut -d '.' -f 1)
|
2023-10-08 14:43:07 +02:00
|
|
|
|
|
|
|
# Convert the local solar noon time to hours, minutes, and seconds
|
|
|
|
local_solar_noon_time=$(date -u -d "@$local_solar_noon_seconds" +%H:%M:%S)
|
|
|
|
|
|
|
|
# Add 8 hours and 12 minutes to the local solar noon time
|
|
|
|
new_time_seconds=$((local_solar_noon_seconds + 8*3600 + 12*60))
|
|
|
|
new_time=$(date -u -d "@$new_time_seconds" +%H:%M:%S)
|
|
|
|
|
2023-10-08 17:07:21 +02:00
|
|
|
echo "Longitude: $longitude degrees $direction"
|
2023-10-08 14:43:07 +02:00
|
|
|
echo "Time Offset: $offset_minutes minutes"
|
|
|
|
echo "Local Solar Noon (midday) Time: $local_solar_noon_time"
|
2023-10-08 18:38:58 +02:00
|
|
|
echo "Local Solar Noon + 8h 12mn:
|
|
|
|
$new_time"
|