Advertisement
Guest User

Untitled

a guest
May 23rd, 2012
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.72 KB | None | 0 0
  1. def es_bisiesto(anio)
  2.     return (anio%4==0 && anio%100!=0)||(anio%400==0)
  3. end; #true si es bisiesto
  4.  
  5. def cargardato()
  6.     x=gets.chomp.to_i
  7.     return x
  8. end
  9.  
  10. def fecha_correcta(dia,mes,anio)
  11.     fecha=false
  12.     if (mes>=1) && (mes<=12) then
  13.         case mes
  14.         when 1,3,5,7,8,10,12 then
  15.             max=31
  16.         when 4,6,9,11 then
  17.             max=30
  18.         when 2 then
  19.             if (es_bisiesto(anio)==true) then
  20.                 max=29
  21.             else
  22.                 max=28
  23.             end
  24.         end
  25.     end
  26.     if (dia>=1) && (dia<=max)
  27.         fecha=true
  28.     end
  29. end
  30.  
  31. #Primer fecha  
  32. begin
  33.     d1=cargardato()
  34.     m1=cargardato()
  35.     a1=cargardato()
  36.     if (fecha_correcta(d1,m1,a1)==true)
  37.         puts ">> La fecha es correcta"
  38.     else
  39.         puts ">> La fecha es incorrecta, ingrese otra"
  40.     end
  41.     if (es_bisiesto(a1)==true) then
  42.         puts ">> El anio es bisiesto"
  43.     else
  44.         puts ">> El anio no es bisiesto"
  45.     end
  46. end until (fecha_correcta(d1,m1,a1)==true)
  47.        
  48. #Segunda fecha
  49. begin
  50.     d2=cargardato()
  51.     m2=cargardato()
  52.     a2=cargardato()
  53.     if (fecha_correcta(d2,m2,a2)==true)
  54.         puts ">> La fecha es correcta"
  55.     else
  56.         puts ">> La fecha es incorrecta, ingrese otra"
  57.     end
  58.     if (es_bisiesto(a2)==true) then
  59.         puts ">> El anio es bisiesto"
  60.     else
  61.         puts ">> El anio no es bisiesto"
  62.     end
  63. end until (fecha_correcta(d2,m2,a2)==true)
  64.  
  65. def comparar_fecha(a1,a2,d1,d2,m1,m2)
  66. if (a1<a2)
  67.     return -1
  68. elsif(a1>a2)
  69.     return 1
  70. else
  71.     if (m1<m2)
  72.         return -1
  73.     elsif (m1>m2)
  74.         return 1
  75.     else
  76.         if (d1<d2)
  77.             return -1
  78.         elsif(d1>d2)
  79.             return 1
  80.         else
  81.             return 0
  82.         end
  83.     end
  84. end
  85. end
  86.  
  87. if comparar_fecha(a1,a2,m1,m2,d1,d2) == 1
  88.     puts "Fecha 1 es mas nueva que Fecha 2"
  89. elsif comparar_fecha(a1,a2,m1,m2,d1,d2) == -1
  90.     puts "Fecha 2 es mas nueva que Fecha1"
  91. elsif comparar_fecha(a1,a2,m2,m2,d1,d2) == 0
  92.     puts "Fecha 1 y fecha 2 son iguales"
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement