Skip to content

Instantly share code, notes, and snippets.

@solnic
Created August 13, 2010 14:31
Show Gist options
  • Select an option

  • Save solnic/522968 to your computer and use it in GitHub Desktop.

Select an option

Save solnic/522968 to your computer and use it in GitHub Desktop.
module DataMapper
class Property
class JustTime < Integer
primitive ::String
def dump(val)
case val
when String
h,m = val.split(':').map &:to_i
h % 24 * 60 + m % 60
else val
end if val.present?
end
def load(val)
if val.present?
h = val / 60
m = val - h * 60
"#{h}:#{m}"
end
end
def parse(val)
case val
when Integer then load(val)
else val
end if val.present?
end
def typecast_to_primitive(val)
parse(val)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment