From: Rover Rhubarb Date: 2007-04-10T23:34:42+09:00 Subject: Re: TZ bug in Date and DateTime.strftime formatter? Possible solution? I still have no idea why a parsed Time and Time.now seem to be different types of object - though .class returns the same class Time. So I still don’t understand why Time.now.zone gives me the zone in one form and the parsed time gives it in another. I'm still working on my own solution and this is what I've come up with. First a bit more experimenting: irb(main):042:0> t_summer = Time.parse("1 July 2006 15:25") => Sat Jul 01 15:25:00 GMT Daylight Time 2006 irb(main):051:0> t_summer.public_methods => ["instance_variable_get", "succ", "year", "to_f", "to_s", "getutc", "respond_to?", "clone", "utc", "nil?", "require_gem_with_options", "instance_variable_set", "wday", "__send__", "inspect", "asctime", "utc?", "to_yaml_style", "_dump", "dup", "equal?", "ctime", "yday", "methods", "gmt?", "pretty_print_cycle", "send", "sec", "taguri", "taint", "tv_sec", "eql?", "taguri=", "display", "hash", "isdst", "singleton_methods", "pretty_print", "instance_eval", "hour", "to_yaml", "instance_of?", "tv_usec", "pretty_print_instance_variables", "rfc2822", "id", "protected_methods", "mday", "tainted?", "to_yaml_properties", "kind_of?", "untaint", "usec", "localtime", "dst?", "rfc822", "__id__", "zone", "+", "private_methods", "day", "-", "freeze", "extend", "strftime", "is_a?", "gmtime", "min", "object_id", "gmtoff", "httpdate", "require_gem", "<=>", "==", "public_methods", "mon", "===", "between?", ">=", "<=", "getlocal", "gmt_offset", "pretty_print_inspect", "xmlschema", "type", "=~", "instance_variables", "<", "require", "frozen?", "month", "method", ">", "to_i", "to_a", "getgm", "iso8601", "class", "utc_offset"] irb(main):052:0> t_summer.httpdate => "Sat, 01 Jul 2006 14:25:00 GMT" irb(main):053:0> t_summer.rfc822 => "Sat, 01 Jul 2006 15:25:00 +0100" irb(main):054:0> t_summer.rfc2822 => "Sat, 01 Jul 2006 15:25:00 +0100" irb(main):055:0> t_summer.xmlschema => "2006-07-01T15:25:00+01:00" irb(main):056:0> t_summer.iso8601 => "2006-07-01T15:25:00+01:00" irb(main):057:0> t_summer.utc_offset => 3600 irb(main):058:0> t_summer.gmt_offset => 3600 irb(main):059:0> t_summer.zone => "GMT Daylight Time" So the most likely candidates are: 1. Parse the output of Time.xmlschema or Time.iso8601 (identical?) from the last + or - to the end and get rid of the colon (I want 0100, not 01:00) 2. Do the same but use rfc822 or rfc2822 (why do both exist, for goodness sake - they seem identical?). Actually this makes more sense, since there's a space before the + and no :. In fact I could just take the last 5 chars. 3. Use gmt_offset or utc_offset (identical?) and convert from seconds to hours I'm going with 2, it looks the surest and simplest. Here it is in action: irb(main):063:0> t_summer.rfc822[-5..-1] => "+0100" irb(main):065:0> t_winter.rfc822[-5..-1] => "+0000" That'll have to do me. Anyone else have any ideas? -- Posted via http://www.ruby-forum.com/.