I was "strptiming" this string:
19/05/2014 8:13:26 a.m.
A local timestamp, which is in my case is Auckland NZ without a timezone stamp in the string as can be seen.
As best I can tell Time.strptime
uses the server timezone as the base.
In my situation, and general good practice, my servers run in UTC timezone so every parse of the string ended up creating a time object, the time to +0000 (UTC):
2014-05-19 08:13:26 +0000
Then converting to in_time_zone(Time.zone)
gave:
Mon, 19 May 2014 20:13:26 NZST +12:00
Which as can be seen is 12 hours (the UTC offset) later than the actual time I wanted.
I tried to use the +' Auckland', '...%Z'
trick as per above without any change.
I then used the + '+1200', '...%Z'
trick as per above which worked correctly.
However I was concerned about summer time, then the parsing would be out by an hour, so this is what I've finshed with:
Time.strptime(call_data[:datetime].gsub(/\./, "").gsub(/am/, "AM").gsub(/pm/, "PM") + (Time.zone.now.time_zone.utc_offset/3600).to_s.ljust(4,'0').rjust(6,' +'), '%d/%m/%Y %I:%M:%S %p %Z').in_time_zone(Time.zone)
Result:
Mon, 19 May 2014 08:13:26 NZST +12:00
It's not particularly elegant but it works.