-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjulian
41 lines (34 loc) · 1.38 KB
/
julian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#################################################################################################################################
# Modified Julian Date can be read about at http://en.wikipedia.org/wiki/Julian_day #
# #
# This realtime clock converts the current date to Modified JD and displays both in realtime. #
#################################################################################################################################
function juliantime()
{
# Get the current date and time components just once
todayis=$(date +"%F")
hourtime=$(date +"%H")
minutetime=$(date +"%M")
secondtime=$(date +"%S")
# Compute Julian Day once outside the loop
let julian=(`date +%s -d $todayis`-`date +%s -d 1968-05-24`)/86400+40000
# Infinite loop for real-time conversion
while true
do
# Re-fetch the time in the loop
hourtime=$(date +"%H")
minutetime=$(date +"%M")
secondtime=$(date +"%S.%N" | head -c10)
# Compute Julian time as a float
juliantime=$(echo "scale=9; ($hourtime / 24) + ($minutetime / 1440) + ($secondtime / 86400) + $julian" | bc -l)
# Clear the screen and display results
clear
echo "Standard Gregorian Date"
echo "$todayis $hourtime:$minutetime:$secondtime"
echo "Modified Julian"
echo "$juliantime"
# Sleep for a small fraction of a second (to update frequently without excessive CPU usage)
sleep 0.01
done
}