DateTime about the zone

i'm reading a news server from ruby asking for DATE, it returns :
"20100612" for the date, that's ok for today
and :
"073429" for the time when it is 2 hours more

i want to return a correct datetime, taking into account the zone
5paris/france) i think it is + 2 H ?

but using datetime and the following :

text = ["20100612", "073429"] # returned by the server thru Net::NNTP

i translate to =
datetime_str =
text[0].gsub(/(\d\d\d\d)(\d\d)(\d\d)/,'\1-\2-\3')+'T'+text[1].gsub(/(\d\
d)(\d\d)(\d\d)/,'\1:\2:\3')+'-02:00'

giving :

datetime_str = '2010-06-12T07:34:29+02:00'

if i read back the hour by :

datetime = DateTime.parse('2010-06-12T07:34:29+02:00')

time = adatetime.strftime(fmt='%H%M%S')

i get always :
073429
regardless of the time decay i put by the end of string (ie '+02:00' or
'-02:00' or 'CEST'

clearly i don't understand...

···

--
« La gloire n'est pas de ne jamais tomber,
  mais de se relever chaque fois que l'on tombe. »
  (Proverbe chinois)

Une Bévue wrote:

datetime = DateTime.parse('2010-06-12T07:34:29+02:00')

time = adatetime.strftime(fmt='%H%M%S')

i get always :
073429
regardless of the time decay i put by the end of string (ie '+02:00' or
'-02:00' or 'CEST'

clearly i don't understand...

datetime = DateTime.parse('2010-06-12T07:34:29+02:00')

=> #<DateTime: 212143080869/86400,1/12,2299161>

datetime.offset

=> Rational(1, 12)

datetime.offset * 24.0

=> 2.0

datetime = DateTime.parse('2010-06-12T07:34:29+03:00')

=> #<DateTime: 212143077269/86400,1/8,2299161>

datetime.offset

=> Rational(1, 8)

datetime.offset * 24.0

=> 3.0

datetime = DateTime.parse('2010-06-12T07:34:29-02:00')

=> #<DateTime: 212143095269/86400,-1/12,2299161>

datetime.offset

=> Rational(-1, 12)

datetime.offset * 24.0

=> -2.0

datetime.strftime("%H%M%S")

=> "073429"

datetime.strftime("%H%M%S %z")

=> "073429 -0200"

···

--
Posted via http://www.ruby-forum.com/\.

Une Bévue wrote:

i'm reading a news server from ruby asking for DATE, it returns :
"20100612" for the date, that's ok for today
and :
"073429" for the time when it is 2 hours more

You mean it's 093429 local time in France?

That means that 073429 is UTC.

datetime = DateTime.parse('2010-06-12T07:34:29')

=> #<DateTime: 212143088069/86400,0,2299161>

I don't know how to ask a DateTime to change to the local timezone, but
I can do it with Time:

require 'time'

=> true

time = Time.parse('2010-06-12T07:34:29Z')

=> Sat Jun 12 07:34:29 UTC 2010

time.to_s

=> "Sat Jun 12 07:34:29 UTC 2010"

time.getlocal

=> Sat Jun 12 08:34:29 +0100 2010

···

--
Posted via http://www.ruby-forum.com/\.

You mean it's 093429 local time in France?

yes, it was )))

in France it's UTC + 2 hours now.

That means that 073429 is UTC.

>> datetime = DateTime.parse('2010-06-12T07:34:29')
=> #<DateTime: 212143088069/86400,0,2299161>

I don't know how to ask a DateTime to change to the local timezone, but
I can do it with Time:

>> require 'time'
=> true
>> time = Time.parse('2010-06-12T07:34:29Z')
=> Sat Jun 12 07:34:29 UTC 2010
>> time.to_s
=> "Sat Jun 12 07:34:29 UTC 2010"
>> time.getlocal
=> Sat Jun 12 08:34:29 +0100 2010

Thanks, fine, seems to be easier to do with Time than with DateTime
(strange enough!)

even i've corrected datetime with tzinfo, gave the correct hour with a
false time zone, strange...

here the datas :
utc_datetime_str = '2010-06-12T07:34:29UTC'
tz = TZInfo::Timezone.get('Europe/Paris')
local = tz.utc_to_local(utc_datetime)
# --> local = 2010-06-12T09:34:29+00:00

here the hour is correct BUT the time zone :
local_zone = local.strftime(fmt='%z')
# --> local_zone = local.strftime(fmt='%z') = +0000

I'll switch to Time )))

···

Brian Candler <b.candler@pobox.com> wrote:
--
« La gloire n'est pas de ne jamais tomber,
  mais de se relever chaque fois que l'on tombe. »
  (Proverbe chinois)