Created
December 2, 2009 11:58
-
-
Save oki/247165 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/local/bin/ruby | |
| # $ ruby czas.rb | |
| # Czas pracy (domyslnie 8h): | |
| # Na ktora przyszedles do pracy (ex: 8:00):8:25 | |
| # Wolny za: 3 hours, 1 minute and 9 seconds | |
| # gem install rails --no-ri --no-rdoc | |
| # gem install duration | |
| require 'rubygems' | |
| require 'activesupport' | |
| require 'duration' | |
| require 'pp' | |
| get_h_m = lambda do |line| | |
| h,m = line.chomp.split(/:/) | |
| h = !h ? 8 : h.to_i | |
| m = !m ? 0 : m.to_i | |
| return h,m | |
| end | |
| print "Czas pracy (domyslnie 8h): " | |
| time_work_h,time_work_m = get_h_m.call(gets) | |
| print "Na ktora przyszedles do pracy (ex: 8:00):" | |
| time_h,time_m = get_h_m.call(gets) | |
| start_work = Time.now.beginning_of_day + time_h.hours + time_m.minutes | |
| if start_work > Time.now | |
| puts "Blas" | |
| exit 1 | |
| end | |
| puts "Wolny za: #{Duration.new((Time.now.beginning_of_day + time_h.hours + time_work_h.hours + time_work_m.minutes) - Time.now)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment