On 3/31/07, rhubarb <rover.rhubarb / gmail.com> wrote: > Is this a bug? > I'm trying to get ruby to format a date, time or datetime to the proper > format for xmltv. > they key is in the timezone - I want it in +0100 format. > > So look at this irb session. > > First create some summer and winter dates in the form of Date, Time and > DateTime - they all have a time component but this always comes out > zeroed in Date.strftime as expected. > > Im concentrating on the %z here because that's what's supposed to give > me the +0100 that I want. > > > Okay now lets create some summer and winter times: > > irb(main):001:0> require 'date' > => true > > ### Summer > > irb(main):005:0> d_summer = Date.parse("1 August 2006 15:25") > => #<Date: 4907897/2,0,2299161> > > irb(main):006:0> t_summer = Time.parse("1 August 2006 15:25") > => Tue Aug 01 15:25:00 GMT Daylight Time 2006 > > irb(main):007:0> dt_summer = DateTime.parse("1 August 2006 15:25") > => #<DateTime: 706737353/288,0,2299161> > > ### Winter > > irb(main):008:0> d_winter = Date.parse("1 November 2006 15:25") > => #<Date: 4908081/2,0,2299161> > > irb(main):009:0> t_winter = Time.parse("1 November 2006 15:25") > => Wed Nov 01 15:25:00 GMT Standard Time 2006 > > irb(main):010:0> dt_winter = DateTime.parse("1 November 2006 15:25") > => #<DateTime: 706763849/288,0,2299161> > > ### Now format the times > > irb(main):011:0> d_winter.strftime('%z') > => "+0000" > irb(main):012:0> d_summer.strftime('%z') > => "+0000" > irb(main):013:0> t_winter.strftime('%z') > => "GMT Standard Time" > irb(main):014:0> t_summer.strftime('%z') > => "GMT Daylight Time" > irb(main):015:0> dt_winter.strftime('%z') > => "+0000" > irb(main):016:0> dt_summer.strftime('%z') > => "+0000" > > > See what's happening: Time always gives the full string for the > timezone, and it correctly varies it for summer versus winter: "GMT > Standard Time" vs "GMT Daylight Time" > > Now Date, and DateTime give me the numeric format I wanted. The winter > format is correct for me - I'm on GMT in winter, but look at the Summer > format: _it's the same as for Winter_ > > It seems to me that if Time.strftime makes the difference, then Date and > DateTime should too. > I expected to see +0100 for the summer times. And so does my Media > Center for that matter, so this will cause my EPG to be off by an hour > unless I correct it myself. > > Anyone else noticed this? > > I understand the system strftime is used by ruby, so I guess it might be > in Windows (I'm using XP). I haven't programmed in C on this windows > box, but I have in C#, and there I get the correct result from > dateTime.ToString("yyyyMMddHHmmss zzzz"), which no-doubt is using some > .Net framework version of the time routine, not the same one as ruby. > > Anyway, this is a bug right? > Is it specific to windows (XP, SP2 is what I'm using) > > If it is a bug is it fixed or fixable? > Is there an easy way to correct - it? A different Time support class? > (I was thinking of just parsing the output from Time.strftime for the > "Daylight" and creating my own string. > > (I'm in Portugal by the way, and writing this during daylight savings at > the end of March, so my current tz is GMT Daylight Time - same as the > UK) I get the same results in my Fedora Core 6 system (ruby-1.8.5.35), except that I don't seem to have Time.parse. -- Felipe Contreras