1 #From: damatex@CAM.ORG (Mario Boudreault)
2 #Newsgroups: comp.unix.shell
3 #Subject: JULIAN DATE CONVERSION SUB
4 #Date: 4 Aug 1995 10:23:28 -0400
5 #Message-ID: <3vtah0$jb3@ocean.CAM.ORG>
7 #For those using shells and who want to convert dates to a julian number
8 #here is a shell script (wihtout validation) that can be used as a base
9 #program for your shell scripts.
11 #Special thanks to Ed Ferguson@ti.com who sent me the algorithm to compute
15 # MODIFIED BY CHET RAMEY TO CONVERT TO bash v2 SYNTAX
18 # cnvdate - Conversion de dates en julienne et vice et versa...
20 # Par : Mario Boudreault Damatex Inc Montreal, Canada
25 # cvdate [-j] YYYMMDD pour convertir en nbre de jours
26 # cvdate -d {julian number} pour convertir en AAAAMMJJ
32 # Separe ANNEE, MOIS et JOUR...
34 YEAR
=`echo $DATE | awk ' { print substr($0,1,4) } '`
35 MONTH
=`echo $DATE | awk ' { print substr($0,5,2) } '`
36 DAY
=`echo $DATE | awk ' { print substr($0,7,2) } '`
38 # Execute la formule magique...
40 A
=$
(( $DAY - 32075 + 1461 * ( $YEAR + 4800 - ( 14 - $MONTH ) / 12 ) \
41 / 4 + 367 * ( $MONTH - 2 + ( 14 - $MONTH ) / 12 * 12 ) / 12 - \
42 3 * ( ( $YEAR + 4900 - ( 14 - $MONTH ) / 12 ) / 100 ) / 4 ))
48 TEMP1
=$
(( $DATE + 68569 ))
49 TEMP2
=$
(( 4 * $TEMP1 / 146097 ))
50 TEMP1
=$
(( $TEMP1 - ( 146097 * $TEMP2 + 3 ) / 4 ))
51 Y
=$
(( 4000 * ( $TEMP1 + 1 ) / 1461001 ))
52 TEMP1
=$
(( $TEMP1 - 1461 * $Y / 4 + 31 ))
53 M
=$
(( 80 * $TEMP1 / 2447 ))
54 D
=$
(( $TEMP1 - 2447 * $M / 80 ))
56 M
=$
(( $M + 2 - 12 * $TEMP1 ))
57 Y
=$
(( 100 * ( $TEMP2 - 49 ) + $Y + $TEMP1 ))
58 M
=`echo $M | awk ' { M=$0 ; if ( length($0) == 1 ) M="0"$0 } END { print M } '`
59 D
=`echo $D | awk ' { D=$0 ; if ( length($0) == 1 ) D="0"$0 } END { print D } '`
68 elif [ "$1" = '-j' ]; then
71 elif [ "$1" = '-d' ]; then