Advertisement
plirof2

tsiknopempti_calc.sh 230614-240307 pasxa-easter

Jun 14th, 2023 (edited)
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.17 KB | None | 0 0
  1. ##########ok chatgpt function
  2.  
  3. ############## STATIC CASE##################
  4. #!/bin/bash
  5.  
  6. # Συνάρτηση για εύρεση εβδομάδας του χρόνου του Πάσχα v03 -240307
  7. function get_easter_week() {
  8.     local year=$1
  9. #   declare -A easter_dates
  10. # Προσθέστε ζευγάρια έτος-εβδομάδας για το Πάσχα (Manual corrected 2028,33,36,38)
  11. #easter_dates+=([2025]="16" [2026]="15" [2027]="18" [2028]="16" [2029]="14")
  12. #easter_dates+=([2030]="17" [2031]="16" [2032]="14" [2033]="16" [2034]="16")
  13. #easter_dates+=([2035]="18" [2036]="16" [2037]="15" [2038]="17" [2039]="16")
  14.     year=$((year-2000))
  15.     case $year in
  16.       29|32) echo 14; ;; 26|37) echo 15; ;;
  17.       38|30) echo 17; ;; 27|35) echo 18; ;;
  18.       *) echo 16; ;;
  19.     esac
  20.     return;
  21. }
  22.  
  23. # Επιλογή έτους
  24. #read -p "Δώστε το έτος: " input_year
  25. input_year="2026";
  26. #echo "input_year="$input_year;
  27. get_easter_week $input_year
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #################STATIC case older#############
  34. #!/bin/bash
  35.  
  36. # Συνάρτηση για εύρεση εβδομάδας του χρόνου του Πάσχα v03 -240307
  37. function get_easter_week() {
  38.     local year=$1
  39. #   declare -A easter_dates
  40. # Προσθέστε ζευγάρια έτος-εβδομάδας για το Πάσχα (Manual corrected 2028,33,36,38)
  41. #easter_dates+=([2025]="16" [2026]="15" [2027]="18" [2028]="16" [2029]="14")
  42. #easter_dates+=([2030]="17" [2031]="16" [2032]="14" [2033]="16" [2034]="16")
  43. #easter_dates+=([2035]="18" [2036]="16" [2037]="15" [2038]="17" [2039]="16")
  44.     case $year in
  45.       2029|2032) echo 14; ;;
  46.       2026|2037) echo 15; ;;
  47.       2025|2028|2031|2033|2034|2036|2039) echo 16; ;;
  48.       2038|2030) echo 17; ;;
  49.       2027|2035) echo 18; ;;
  50.       *) echo 16; ;;
  51.     esac
  52.     return;
  53. }
  54.  
  55. # Επιλογή έτους
  56. #read -p "Δώστε το έτος: " input_year
  57. input_year="2027";
  58. #echo "input_year="$input_year;
  59. get_easter_week $input_year
  60.  
  61.  
  62.  
  63.  
  64.  
  65. ################STATIC################
  66. #!/bin/bash
  67.  
  68. # Συνάρτηση για εύρεση εβδομάδας του χρόνου του Πάσχα
  69. function get_easter_week() {
  70.     local year=$1
  71.     declare -A easter_dates
  72.  
  73.     # Προσθέστε ζευγάρια έτος-εβδομάδας για το Πάσχα (Manuall corrected 2028,33,36,38)
  74. # Try easter_dates+=([2025]="16" [2026]="15" [2027]="18" [2028]="16" [2029]="14" [2030]="17" [2031]="16" [2032]="14" [2033]="16" [2034]="16" [2035]="18" [2036]="16" [2037]="15" [2038]="17" [2039]="16")
  75. #SORTED
  76. #[2029]=14, [2032]=14
  77. #[2026]=15, [2037]=15
  78. #[2025]=16, [2028]=16, [2031]=16, [2033]=16, [2034]=16, [2036]=16, [2039]=16
  79. #[2038]=17, [2030]=17
  80. #[2027]=18, [2035]=18,
  81.  
  82.     easter_dates[2025]=16
  83.     easter_dates[2026]=15
  84.     easter_dates[2027]=18
  85.     easter_dates[2028]=16
  86.     easter_dates[2029]=14
  87.     easter_dates[2030]=17
  88.     easter_dates[2031]=16
  89.     easter_dates[2032]=14
  90.     easter_dates[2033]=16
  91.     easter_dates[2034]=16
  92.     easter_dates[2035]=18
  93.     easter_dates[2036]=16
  94.     easter_dates[2037]=15
  95.     easter_dates[2038]=17
  96.     easter_dates[2039]=16
  97.  
  98.     # Επιστροφή του αριθμού της εβδομάδας για το συγκεκριμένο έτος
  99.     echo ${easter_dates[$year]}
  100. }
  101.  
  102. # Επιλογή έτους
  103. read -p "Δώστε το έτος: " input_year
  104.  
  105. # Έλεγχος αν το έτος υπάρχει στον πίνακα
  106. if [[ $(get_easter_week $input_year) ]]; then
  107.     echo "Το Πάσχα του έτους $input_year πέφτει στην εβδομάδα $(get_easter_week $input_year) του χρόνου."
  108. else
  109.     echo "Το έτος δεν βρέθηκε στον πίνακα."
  110. fi
  111.  
  112. ##########################################################################
  113.  
  114.  
  115.  
  116. #######################easter_calc_typeD_function_ok3.sh#################
  117. #show easter is 22/4/2024
  118. #!/bin/bash
  119.  
  120. year=$(date +'%Y')
  121.  
  122. a=$(( $year % 19 ))
  123. b=$(( $year % 4 ))
  124. c=$(( $year % 7 ))
  125.  
  126. d=$(( (19*$a + 15) % 30 ))
  127. e=$(( (2*$b + 4*$c + 6*$d + 6) % 7 ))
  128.  
  129. if (( $d + $e < 10 )); then
  130.     day=$(( $d + $e + 22 ))
  131.     month=3
  132. else
  133.     day=$(( $d + $e - 9 ))
  134.     month=4
  135. fi
  136.  
  137. if (( $day > 31 )); then
  138.     day=$(( $day - 31 ))
  139.     month=4
  140. fi
  141.  
  142. echo "Ημερομηνία Πάσχα για το έτος $year είναι: $day/$month/$year"
  143.  
  144.  
  145.  
  146. ___________________________________________________________
  147.  
  148.  
  149. ALL show wrong date 31/3/2024 XXX
  150. #######################ok works smaller#################
  151. #!/bin/bash
  152. #easter_calc_typeC2_function_ok3.sh
  153. clear
  154. calculate_easter_week() {
  155.     # Get current year
  156.     current_year=$(date +%Y)
  157.  
  158.     # Calculate Easter Sunday date for current year using ncal
  159.     easter_date=$(ncal -e | awk '{print $NF}')
  160.  
  161.     # Convert dd/mm/yyyy to mm/dd/yyyy
  162.     input_date=$easter_date
  163.     formatted_date=$(date -d "$(echo $input_date | awk -F'/' '{print $2"/"$1"/"$3}')" "+%Y-%m-%d")
  164.  
  165.     # Calculate the week number of Easter Sunday
  166.     week_number=$(date -d "$formatted_date" +%V)
  167.  
  168.     # Print Easter Sunday date and week number
  169.     echo "Easter Sunday for $current_year is on: $easter_date"
  170.     echo "Week number of Easter Sunday: $week_number"
  171. }
  172.  
  173. # Call the function
  174. calculate_easter_week
  175. # To return a value from a function :
  176. #EASTER_WEEK=$(calculate_easter_week); # EASTER_WEEK will get all the "echoes" of the function
  177. # echo "EASTERWEEK="$EASTER_WEEK ;
  178.  
  179.  
  180. #####################################ok works#############
  181. #!/bin/bash
  182. #easter_calc_typeC_function_ok2.sh
  183. calculate_easter_week() {
  184.     # Get current year
  185.     current_year=$(date +%Y)
  186.  
  187.     # Calculate Easter Sunday date for current year using ncal
  188.     easter_date=$(ncal -e | awk '{print $NF}')
  189.  
  190.     # Convert dd/mm/yyyy to mm/dd/yyyy
  191.     input_date=$easter_date
  192.     day=$(echo $input_date | cut -d'/' -f1)
  193.     month=$(echo $input_date | cut -d'/' -f2)
  194.     year=$(echo $input_date | cut -d'/' -f3)
  195.     formatted_date="$month/$day/$year"
  196.  
  197.     # Calculate the week number of Easter Sunday
  198.     week_number=$(date -d "$formatted_date" +%V)
  199.  
  200.     # Print Easter Sunday date and week number
  201.     echo "Easter Sunday for $current_year is on: $easter_date"
  202.     echo "Week number of Easter Sunday: $week_number"
  203. }
  204.  
  205. # Call the function
  206. calculate_easter_week
  207.  
  208.  
  209.  
  210. ###### Full calucation test (chatgpt works - BUT its BIG)#####
  211. #!/bin/bash
  212. clear
  213. #!/bin/bash
  214.  
  215. # Function to calculate the date of Easter Sunday for a given year
  216. calculate_easter_date() {
  217.     local year=$1
  218.     local a=$(( year % 19 ))
  219.     local b=$(( year / 100 ))
  220.     local c=$(( year % 100 ))
  221.     local d=$(( b / 4 ))
  222.     local e=$(( b % 4 ))
  223.     local f=$(( (b + 8) / 25 ))
  224.     local g=$(( (b - f + 1) / 3 ))
  225.     local h=$(( (19 * a + b - d - g + 15) % 30 ))
  226.     local i=$(( c / 4 ))
  227.     local k=$(( c % 4 ))
  228.     local l=$(( (32 + 2 * e + 2 * i - h - k) % 7 ))
  229.     local m=$(( (a + 11 * h + 22 * l) / 451 ))
  230.     local month=$(( (h + l - 7 * m + 114) / 31 ))
  231.     local day=$(( ((h + l - 7 * m + 114) % 31) + 1 ))
  232.     echo "$month/$day/$year"
  233. }
  234.  
  235. # Get current year
  236. current_year=$(date +%Y)
  237.  
  238. # Calculate Easter Sunday date for current year
  239. easter_date=$(calculate_easter_date $current_year)
  240.  
  241. # Print Easter Sunday date
  242. echo "Easter Sunday for $current_year is on: $easter_date"
  243.  
  244. # Calculate the week number of Easter Sunday
  245. week_number=$(date -d "$easter_date" +%V)
  246.  
  247. # Print the week number
  248. echo "Week number of Easter Sunday: $week_number"
  249.  
  250.  
  251. ############# OLD TEST ###########
  252. #Tsiknopempti calculator - or megali ebdomada (so we can calculater easter/apokries ktl)
  253. echo " we should enter MEGALI EBDOMADA variable and then sustract dates"
  254.  
  255. echo ncal -e | date +%W --
  256. echo "------------------"
  257. OUTPUT=$(ncal -e)
  258. echo "EASTER date="$OUTPUT
  259.  
  260. echo "2------------------"
  261. date  +%W -d "$OUTPUT" --
  262. date  +%W -d "$OUTPUT" --
  263.  
  264. echo "3------------------"
  265. ncal -e 2023 | date +%W --
  266. date  -d "09/04/2023" +%W --
  267.  
  268. echo "4------------------"
  269.  
  270. echo "5------------------"
  271.  
  272. echo "6------------------"
  273.  
  274. echo "7------------------"
  275.  
  276. echo "8------------------"
  277. OUTPUT=$(ncal -e)
  278. echo "aaaaaaaa ${OUTPUT}"
  279.  
  280. now2 =$("ncal -e")
  281. echo "EASTER date="$now2
  282. now=$(date)
  283. echo "NOW="$now
  284.  
  285. OUTPUT=$(date +%W)
  286.  
  287.  
  288. echo "------------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement