views:

99

answers:

2

I'm currently given three values in a table

A date value in the format of %dd-%mname-%yy (i.e 06-may-05), and am parsing that using Date.parse(input,true) to fix the issue with the leading values.

I'm then given a time value in the form of %hh:%mm:%ss.%ms (the ms of which I can take or leave) and a third value of a GMT offset.

I can't really see anyway to convert these three values into a single DateTime object that would allow me to manipulate it using the range of ruby tools without first parsing the second value to time, somehow changing the offset ((given as a + or - n value) as in +2 or -6)to a signed int and then applying it and then parsing this all to a super dateTime object.

There's got to be a better way. Is there?

A: 

Chronic may be able to parse this (if you concatenate everything in one string, maybe with some modifications) but I haven't checked.

Evgeny Shadchnev
Chronic helps me but it won't allow me to fix the offset, either way thanks I'm way closer to a solution. When I get the chronic + datetime + offset solution I'll post it
Schroedinger
A: 

Okay in order to create a dateTime value with the time and the date given and to take into account an offset you need the following code

d =  DateTime.parse(dateVal+" "+TimeVal)
      offset = Rational(offset_val,24)
      d = d.new_offset(offset)

So take your date, given to you as say 05 May 2010 and a timeval in the form hh:mm:ss

With an offset of +- any value, for this instance say -8

Then this code will generate you a new date object, offset to the amount you require

Schroedinger