lib/gyoku/xml_value.rb in gyoku-0.4.5 vs lib/gyoku/xml_value.rb in gyoku-0.4.6
- old
+ new
@@ -3,16 +3,26 @@
module Gyoku
module XMLValue
class << self
- # xs:dateTime format.
+ # xs:date format
+ XS_DATE_FORMAT = "%Y-%m-%d"
+
+ # xs:time format
+ XS_TIME_FORMAT = "%H:%M:%S"
+
+ # xs:dateTime format
XS_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%Z"
# Converts a given +object+ to an XML value.
def create(object, escape_xml = true)
- if DateTime === object
+ if Time === object
+ object.strftime XS_TIME_FORMAT
+ elsif DateTime === object
object.strftime XS_DATETIME_FORMAT
+ elsif Date === object
+ object.strftime XS_DATE_FORMAT
elsif String === object
escape_xml ? CGI.escapeHTML(object) : object
elsif object.respond_to?(:to_datetime)
create object.to_datetime
elsif object.respond_to?(:call)