Skip to content

Instantly share code, notes, and snippets.

@jacobo
Created June 15, 2009 15:09
Show Gist options
  • Save jacobo/130159 to your computer and use it in GitHub Desktop.
Save jacobo/130159 to your computer and use it in GitHub Desktop.
define_field "Birthday (day/month/year)" do
|child, value|
if value == ""
child.birthdate = nil;
elsif value =~ /(\d+)\/(\d+)\/(\d+)/
#15/12/1997 -- which needs to be reversed to 12/15/1997 in order to be imported
child.birthdate = value.gsub(/(\d+)\/(\d+)\/(\d+)/) do | s |
year = $3;
if year.length == 2
if year[0..0] == 0
year = "20" + year
else
year = "19" + year
end
end
"#{$2}/#{$1}/#{year}"
end
elsif (value =~ /(\d){4}/) == 0
#1993 -- which needs to be expanded to 1/1/1993 in order to be imported
child.birthdate = "1/1/" + value
elsif (value =~ /(\d*)-*(\w+)-(\d+)/)
#May-93 -- which needs to be expanded into 1-May-93 in order to imported
#28-Apr-00 -- which needs to be expanded to 28-Apr-2000 in order to be imported
child.birthdate = value.gsub(/(\d*)-*(\w+)-(\d+)/) do | s |
day = $1
if day == ''
day = "1"
end
year = $3;
if year.length == 2
if year[0..0] == 0
year = "20" + year
else
year = "19" + year
end
end
"#{day}-#{$2}-#{year}"
end
else
puts "Don't know how to parse birthdate of: " + value;
end
puts "Pased birthday of " + value + " as: " + child.birthdate.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment