Skip to content

Instantly share code, notes, and snippets.

@lucaspiller
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaspiller/98e48dbe41795fc832e4 to your computer and use it in GitHub Desktop.
Save lucaspiller/98e48dbe41795fc832e4 to your computer and use it in GitHub Desktop.
HMRC Residency Check
require 'active_support/core_ext'
in_out = :out
out_days = 0
in_days = 0
transit_days = 0
last = "2013-05-06".to_date
%w{
16/05/2013
17/05/2013
19/05/2013
20/05/2013
21/11/2013
10/01/2014
05/05/2014
}.each do |date|
date = date.to_date
transit_days += 1
days = (date - (last + 1.day)).to_i
if in_out == :out
out_days += days
puts "Out #{days}"
in_out = :in
elsif in_out == :in
in_days += days
puts "In #{days}"
in_out = :out
end
puts date
last = date
end
puts
puts "In: #{in_days}"
puts "Out: #{out_days}"
puts "Transit: #{transit_days}"
puts "Total: #{in_days + out_days + transit_days}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment