Created
January 3, 2009 11:21
-
-
Save ravicious/42826 to your computer and use it in GitHub Desktop.
Skrypt Klisia [ http://klisiu.pl/blog/hello-php/ ] napisany w Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'parsedate' | |
def scan(text) | |
text =~ /^([0-9]{1,2})[-\.]([0-9]{1,2})[-\.]([0-9]{4})/ | |
end | |
d1 = '' | |
d2 = '' | |
loop do | |
loop do | |
puts "Podaj pierwsza date (format: dd-mm-rrrr)" | |
if scan(d1 = gets.chop!) | |
break | |
end | |
end | |
loop do | |
puts "Podaj druga date (format: dd-mm-rrrr)" | |
if scan(d2 = gets.chop!) | |
break | |
end | |
end | |
d1 = ParseDate::parsedate(d1) | |
d2 = ParseDate::parsedate(d2) | |
d1 = Date.new(d1[0], d1[1], d1[2]) | |
d2 = Date.new(d2[0], d2[1], d2[2]) | |
if d1 == d2 | |
puts "Wprowadz dwie rozne daty!" | |
else | |
if d1 > d2 | |
puts "Ilosc dni, jaka uplynela miedzy tymi datami: #{d1 - d2}" | |
else | |
puts "Ilosc dni, jaka uplynela miedzy tymi datami: #{d2 - d1}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment