Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def es_bisiesto(anio)
- return (anio%4==0 && anio%100!=0)||(anio%400==0)
- end; #true si es bisiesto
- def cargardato()
- x=gets.chomp.to_i
- return x
- end
- def fecha_correcta(dia,mes,anio)
- fecha=false
- if (mes>=1) && (mes<=12) then
- case mes
- when 1,3,5,7,8,10,12 then
- max=31
- when 4,6,9,11 then
- max=30
- when 2 then
- if (es_bisiesto(anio)==true) then
- max=29
- else
- max=28
- end
- end
- end
- if (dia>=1) && (dia<=max)
- fecha=true
- end
- end
- #Primer fecha
- begin
- d1=cargardato()
- m1=cargardato()
- a1=cargardato()
- if (fecha_correcta(d1,m1,a1)==true)
- puts ">> La fecha es correcta"
- else
- puts ">> La fecha es incorrecta, ingrese otra"
- end
- if (es_bisiesto(a1)==true) then
- puts ">> El anio es bisiesto"
- else
- puts ">> El anio no es bisiesto"
- end
- end until (fecha_correcta(d1,m1,a1)==true)
- #Segunda fecha
- begin
- d2=cargardato()
- m2=cargardato()
- a2=cargardato()
- if (fecha_correcta(d2,m2,a2)==true)
- puts ">> La fecha es correcta"
- else
- puts ">> La fecha es incorrecta, ingrese otra"
- end
- if (es_bisiesto(a2)==true) then
- puts ">> El anio es bisiesto"
- else
- puts ">> El anio no es bisiesto"
- end
- end until (fecha_correcta(d2,m2,a2)==true)
- def comparar_fecha(a1,a2,d1,d2,m1,m2)
- if (a1<a2)
- return -1
- elsif(a1>a2)
- return 1
- else
- if (m1<m2)
- return -1
- elsif (m1>m2)
- return 1
- else
- if (d1<d2)
- return -1
- elsif(d1>d2)
- return 1
- else
- return 0
- end
- end
- end
- end
- if comparar_fecha(a1,a2,m1,m2,d1,d2) == 1
- puts "Fecha 1 es mas nueva que Fecha 2"
- elsif comparar_fecha(a1,a2,m1,m2,d1,d2) == -1
- puts "Fecha 2 es mas nueva que Fecha1"
- elsif comparar_fecha(a1,a2,m2,m2,d1,d2) == 0
- puts "Fecha 1 y fecha 2 son iguales"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement