URI: 
       day-70.sh - day-70 - Files related to Day 70, official gopher holy-day
   DIR Log
   DIR Files
   DIR Refs
       ---
       day-70.sh (842B)
       ---
            1 #!/bin/sh
            2 
            3 # day-70.sh
            4 #
            5 # Find the 70th day of a given year
            6 #
            7 # Author: ROYGBYTE
            8 # Date: 2023
            9 
           10 leap_year() {
           11         year=${1}
           12         rule_1=$((year%4))
           13         if [ ! $rule_1 -eq 0 ]; then
           14                 # Not divisable by 4, no leap.
           15                 return 1
           16         fi
           17         rule_2=$((year%100))
           18         rule_3=$((year%400))
           19         if [ $rule_2 -eq 0 ]; then
           20                 # Divisable by 100, maybe leap.
           21                 if [ ! $rule_3 -eq 0 ]; then
           22                         # Not divisable by 400, no leap.
           23                         return 1
           24                 fi
           25         fi
           26         return 0
           27 }
           28 
           29 # 70th day of year fluctuates depending on whether it's leap year or no.
           30 nth_day_march=11
           31 leap_year ${1}
           32 if [ $? -eq 0 ]; then
           33         nth_day_march=10
           34 fi
           35 
           36 # Sanity check: day num should be 70, duh.
           37 date_string="${1}-03-${nth_day_march}"
           38 day_num=$(date --date="${date_string}" +%j)
           39 if [ ! $day_num -eq 70 ]; then
           40         printf "Something went wrong\n"
           41         exit 1
           42 fi
           43 
           44 # Pretty print the date information
           45 date --date="${date_string}"