Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##########ok chatgpt function
- ############## STATIC CASE##################
- #!/bin/bash
- # Συνάρτηση για εύρεση εβδομάδας του χρόνου του Πάσχα v03 -240307
- function get_easter_week() {
- local year=$1
- # declare -A easter_dates
- # Προσθέστε ζευγάρια έτος-εβδομάδας για το Πάσχα (Manual corrected 2028,33,36,38)
- #easter_dates+=([2025]="16" [2026]="15" [2027]="18" [2028]="16" [2029]="14")
- #easter_dates+=([2030]="17" [2031]="16" [2032]="14" [2033]="16" [2034]="16")
- #easter_dates+=([2035]="18" [2036]="16" [2037]="15" [2038]="17" [2039]="16")
- year=$((year-2000))
- case $year in
- 29|32) echo 14; ;; 26|37) echo 15; ;;
- 38|30) echo 17; ;; 27|35) echo 18; ;;
- *) echo 16; ;;
- esac
- return;
- }
- # Επιλογή έτους
- #read -p "Δώστε το έτος: " input_year
- input_year="2026";
- #echo "input_year="$input_year;
- get_easter_week $input_year
- #################STATIC case older#############
- #!/bin/bash
- # Συνάρτηση για εύρεση εβδομάδας του χρόνου του Πάσχα v03 -240307
- function get_easter_week() {
- local year=$1
- # declare -A easter_dates
- # Προσθέστε ζευγάρια έτος-εβδομάδας για το Πάσχα (Manual corrected 2028,33,36,38)
- #easter_dates+=([2025]="16" [2026]="15" [2027]="18" [2028]="16" [2029]="14")
- #easter_dates+=([2030]="17" [2031]="16" [2032]="14" [2033]="16" [2034]="16")
- #easter_dates+=([2035]="18" [2036]="16" [2037]="15" [2038]="17" [2039]="16")
- case $year in
- 2029|2032) echo 14; ;;
- 2026|2037) echo 15; ;;
- 2025|2028|2031|2033|2034|2036|2039) echo 16; ;;
- 2038|2030) echo 17; ;;
- 2027|2035) echo 18; ;;
- *) echo 16; ;;
- esac
- return;
- }
- # Επιλογή έτους
- #read -p "Δώστε το έτος: " input_year
- input_year="2027";
- #echo "input_year="$input_year;
- get_easter_week $input_year
- ################STATIC################
- #!/bin/bash
- # Συνάρτηση για εύρεση εβδομάδας του χρόνου του Πάσχα
- function get_easter_week() {
- local year=$1
- declare -A easter_dates
- # Προσθέστε ζευγάρια έτος-εβδομάδας για το Πάσχα (Manuall corrected 2028,33,36,38)
- # 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")
- #SORTED
- #[2029]=14, [2032]=14
- #[2026]=15, [2037]=15
- #[2025]=16, [2028]=16, [2031]=16, [2033]=16, [2034]=16, [2036]=16, [2039]=16
- #[2038]=17, [2030]=17
- #[2027]=18, [2035]=18,
- easter_dates[2025]=16
- easter_dates[2026]=15
- easter_dates[2027]=18
- easter_dates[2028]=16
- easter_dates[2029]=14
- easter_dates[2030]=17
- easter_dates[2031]=16
- easter_dates[2032]=14
- easter_dates[2033]=16
- easter_dates[2034]=16
- easter_dates[2035]=18
- easter_dates[2036]=16
- easter_dates[2037]=15
- easter_dates[2038]=17
- easter_dates[2039]=16
- # Επιστροφή του αριθμού της εβδομάδας για το συγκεκριμένο έτος
- echo ${easter_dates[$year]}
- }
- # Επιλογή έτους
- read -p "Δώστε το έτος: " input_year
- # Έλεγχος αν το έτος υπάρχει στον πίνακα
- if [[ $(get_easter_week $input_year) ]]; then
- echo "Το Πάσχα του έτους $input_year πέφτει στην εβδομάδα $(get_easter_week $input_year) του χρόνου."
- else
- echo "Το έτος δεν βρέθηκε στον πίνακα."
- fi
- ##########################################################################
- #######################easter_calc_typeD_function_ok3.sh#################
- #show easter is 22/4/2024
- #!/bin/bash
- year=$(date +'%Y')
- a=$(( $year % 19 ))
- b=$(( $year % 4 ))
- c=$(( $year % 7 ))
- d=$(( (19*$a + 15) % 30 ))
- e=$(( (2*$b + 4*$c + 6*$d + 6) % 7 ))
- if (( $d + $e < 10 )); then
- day=$(( $d + $e + 22 ))
- month=3
- else
- day=$(( $d + $e - 9 ))
- month=4
- fi
- if (( $day > 31 )); then
- day=$(( $day - 31 ))
- month=4
- fi
- echo "Ημερομηνία Πάσχα για το έτος $year είναι: $day/$month/$year"
- ___________________________________________________________
- ALL show wrong date 31/3/2024 XXX
- #######################ok works smaller#################
- #!/bin/bash
- #easter_calc_typeC2_function_ok3.sh
- clear
- calculate_easter_week() {
- # Get current year
- current_year=$(date +%Y)
- # Calculate Easter Sunday date for current year using ncal
- easter_date=$(ncal -e | awk '{print $NF}')
- # Convert dd/mm/yyyy to mm/dd/yyyy
- input_date=$easter_date
- formatted_date=$(date -d "$(echo $input_date | awk -F'/' '{print $2"/"$1"/"$3}')" "+%Y-%m-%d")
- # Calculate the week number of Easter Sunday
- week_number=$(date -d "$formatted_date" +%V)
- # Print Easter Sunday date and week number
- echo "Easter Sunday for $current_year is on: $easter_date"
- echo "Week number of Easter Sunday: $week_number"
- }
- # Call the function
- calculate_easter_week
- # To return a value from a function :
- #EASTER_WEEK=$(calculate_easter_week); # EASTER_WEEK will get all the "echoes" of the function
- # echo "EASTERWEEK="$EASTER_WEEK ;
- #####################################ok works#############
- #!/bin/bash
- #easter_calc_typeC_function_ok2.sh
- calculate_easter_week() {
- # Get current year
- current_year=$(date +%Y)
- # Calculate Easter Sunday date for current year using ncal
- easter_date=$(ncal -e | awk '{print $NF}')
- # Convert dd/mm/yyyy to mm/dd/yyyy
- input_date=$easter_date
- day=$(echo $input_date | cut -d'/' -f1)
- month=$(echo $input_date | cut -d'/' -f2)
- year=$(echo $input_date | cut -d'/' -f3)
- formatted_date="$month/$day/$year"
- # Calculate the week number of Easter Sunday
- week_number=$(date -d "$formatted_date" +%V)
- # Print Easter Sunday date and week number
- echo "Easter Sunday for $current_year is on: $easter_date"
- echo "Week number of Easter Sunday: $week_number"
- }
- # Call the function
- calculate_easter_week
- ###### Full calucation test (chatgpt works - BUT its BIG)#####
- #!/bin/bash
- clear
- #!/bin/bash
- # Function to calculate the date of Easter Sunday for a given year
- calculate_easter_date() {
- local year=$1
- local a=$(( year % 19 ))
- local b=$(( year / 100 ))
- local c=$(( year % 100 ))
- local d=$(( b / 4 ))
- local e=$(( b % 4 ))
- local f=$(( (b + 8) / 25 ))
- local g=$(( (b - f + 1) / 3 ))
- local h=$(( (19 * a + b - d - g + 15) % 30 ))
- local i=$(( c / 4 ))
- local k=$(( c % 4 ))
- local l=$(( (32 + 2 * e + 2 * i - h - k) % 7 ))
- local m=$(( (a + 11 * h + 22 * l) / 451 ))
- local month=$(( (h + l - 7 * m + 114) / 31 ))
- local day=$(( ((h + l - 7 * m + 114) % 31) + 1 ))
- echo "$month/$day/$year"
- }
- # Get current year
- current_year=$(date +%Y)
- # Calculate Easter Sunday date for current year
- easter_date=$(calculate_easter_date $current_year)
- # Print Easter Sunday date
- echo "Easter Sunday for $current_year is on: $easter_date"
- # Calculate the week number of Easter Sunday
- week_number=$(date -d "$easter_date" +%V)
- # Print the week number
- echo "Week number of Easter Sunday: $week_number"
- ############# OLD TEST ###########
- #Tsiknopempti calculator - or megali ebdomada (so we can calculater easter/apokries ktl)
- echo " we should enter MEGALI EBDOMADA variable and then sustract dates"
- echo ncal -e | date +%W --
- echo "------------------"
- OUTPUT=$(ncal -e)
- echo "EASTER date="$OUTPUT
- echo "2------------------"
- date +%W -d "$OUTPUT" --
- date +%W -d "$OUTPUT" --
- echo "3------------------"
- ncal -e 2023 | date +%W --
- date -d "09/04/2023" +%W --
- echo "4------------------"
- echo "5------------------"
- echo "6------------------"
- echo "7------------------"
- echo "8------------------"
- OUTPUT=$(ncal -e)
- echo "aaaaaaaa ${OUTPUT}"
- now2 =$("ncal -e")
- echo "EASTER date="$now2
- now=$(date)
- echo "NOW="$now
- OUTPUT=$(date +%W)
- echo "------------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement