solar time calculator
This commit is contained in:
parent
6cd0fc7403
commit
207b28875d
|
@ -1,34 +1,34 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Input longitude in degrees (positive for East, negative for West)
|
# Input longitude in degrees (positive for East, negative for West)
|
||||||
longitude_deg=$1
|
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
|
||||||
|
|
||||||
# Determine if it's East or West longitude
|
# Determine if it's East or West longitude
|
||||||
if [ $longitude_deg -ge 0 ]; then
|
if [ $(echo "$longitude >= 0" | bc) -eq 1 ]; then
|
||||||
direction="East"
|
direction="East"
|
||||||
else
|
else
|
||||||
direction="West"
|
direction="West"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Calculate the time offset in minutes
|
# Calculate the time offset in minutes using awk for floating-point arithmetic
|
||||||
offset_minutes=$((longitude_deg * 4))
|
offset_minutes=$(echo "$longitude * 4" | bc)
|
||||||
|
|
||||||
# Determine if it's ahead or behind UTC
|
# Determine if it's ahead or behind UTC
|
||||||
if [ "$direction" == "West" ]; then
|
if [ "$direction" == "West" ]; then
|
||||||
offset_minutes=$((offset_minutes * -1))
|
offset_minutes=$(echo "$offset_minutes * -1" | bc)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the current UTC time in hours, minutes, and seconds
|
|
||||||
current_utc_time=$(date -u +%H:%M:%S)
|
|
||||||
|
|
||||||
# Convert the UTC time to seconds since midnight
|
|
||||||
current_utc_seconds=$(date -u -d "$current_utc_time" +%s)
|
|
||||||
|
|
||||||
# Calculate the solar noon time in UTC (12:00 PM)
|
# Calculate the solar noon time in UTC (12:00 PM)
|
||||||
solar_noon_utc_seconds=$((12 * 3600))
|
solar_noon_utc_seconds=$((12 * 3600))
|
||||||
|
|
||||||
# Adjust the solar noon time by the offset in seconds
|
# Adjust the solar noon time by the offset in seconds
|
||||||
local_solar_noon_seconds=$((solar_noon_utc_seconds + offset_minutes * 60))
|
local_solar_noon_seconds=$(echo "$solar_noon_utc_seconds + ( $offset_minutes * 60 )" | bc | cut -d '.' -f 1)
|
||||||
|
|
||||||
# Convert the local solar noon time to hours, minutes, and seconds
|
# 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)
|
local_solar_noon_time=$(date -u -d "@$local_solar_noon_seconds" +%H:%M:%S)
|
||||||
|
@ -37,7 +37,7 @@ local_solar_noon_time=$(date -u -d "@$local_solar_noon_seconds" +%H:%M:%S)
|
||||||
new_time_seconds=$((local_solar_noon_seconds + 8*3600 + 12*60))
|
new_time_seconds=$((local_solar_noon_seconds + 8*3600 + 12*60))
|
||||||
new_time=$(date -u -d "@$new_time_seconds" +%H:%M:%S)
|
new_time=$(date -u -d "@$new_time_seconds" +%H:%M:%S)
|
||||||
|
|
||||||
echo "Longitude: $longitude_deg degrees $direction"
|
echo "Longitude: $longitude degrees $direction"
|
||||||
echo "Time Offset: $offset_minutes minutes"
|
echo "Time Offset: $offset_minutes minutes"
|
||||||
echo "Local Solar Noon (midday) Time: $local_solar_noon_time"
|
echo "Local Solar Noon (midday) Time: $local_solar_noon_time"
|
||||||
echo "Local Solar Noon + 8h 12mn: $new_time"
|
echo "Local Solar Noon + 8h 12mn: $new_time"
|
||||||
|
|
Loading…
Reference in New Issue