class CFPropertyList::CFDate
This class holds Time values. While Apple uses seconds since 2001, the rest of the world uses seconds since 1970. So if you access value directly, you get the Time class. If you access via #get_value you either geht the timestamp or the Apple timestamp
Constants
- DATE_DIFF_APPLE_UNIX
- TIMESTAMP_APPLE
- TIMESTAMP_UNIX
Public Class Methods
date_string(val)
click to toggle source
create a XML date strimg from a time object
# File lib/cfpropertylist/rbCFTypes.rb, line 148 def CFDate.date_string(val) # 2009-05-13T20:23:43Z val.getutc.strftime("%Y-%m-%dT%H:%M:%SZ") end
new(value = nil,format=CFDate::TIMESTAMP_UNIX)
click to toggle source
set value to defined state
# File lib/cfpropertylist/rbCFTypes.rb, line 162 def initialize(value = nil,format=CFDate::TIMESTAMP_UNIX) if(value.is_a?(Time) || value.nil?) then @value = value.nil? ? Time.now : value elsif value.instance_of? Date @value = Time.utc(value.year, value.month, value.day, 0, 0, 0) elsif value.instance_of? DateTime @value = value.to_time.utc else set_value(value,format) end end
parse_date(val)
click to toggle source
parse a XML date string
# File lib/cfpropertylist/rbCFTypes.rb, line 154 def CFDate.parse_date(val) # 2009-05-13T20:23:43Z val =~ %r{^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$} year,month,day,hour,min,sec = $1, $2, $3, $4, $5, $6 return Time.utc(year,month,day,hour,min,sec).getlocal end
Public Instance Methods
get_value(format=CFDate::TIMESTAMP_UNIX)
click to toggle source
get timestamp, either UNIX or Apple timestamp
# File lib/cfpropertylist/rbCFTypes.rb, line 184 def get_value(format=CFDate::TIMESTAMP_UNIX) if(format == CFDate::TIMESTAMP_UNIX) then @value.to_i else @value.to_f - CFDate::DATE_DIFF_APPLE_UNIX end end
set_value(value,format=CFDate::TIMESTAMP_UNIX)
click to toggle source
set value with timestamp, either Apple or UNIX
# File lib/cfpropertylist/rbCFTypes.rb, line 175 def set_value(value,format=CFDate::TIMESTAMP_UNIX) if(format == CFDate::TIMESTAMP_UNIX) then @value = Time.at(value) else @value = Time.at(value + CFDate::DATE_DIFF_APPLE_UNIX) end end
to_binary(bplist)
click to toggle source
convert to binary
# File lib/cfpropertylist/rbCFTypes.rb, line 200 def to_binary(bplist) bplist.date_to_binary(@value) end
to_plain(plist)
click to toggle source
# File lib/cfpropertylist/rbCFTypes.rb, line 204 def to_plain(plist) @value.strftime("%Y-%m-%d %H:%M:%S %z") end
to_xml(parser)
click to toggle source
convert to XML
# File lib/cfpropertylist/rbCFTypes.rb, line 193 def to_xml(parser) n = parser.new_node('date') n = parser.append_node(n, parser.new_text(CFDate::date_string(@value))) n end