set a time zone when parsing a datetime with the Chronic parser
did
committed Dec 28, 2015
commit 7825b47c40f9b80ff3c7611498ddf3d770cebc78
Showing 2
changed files with
9 additions
and 1 deletions
locomotive/steam/entities/content_entry.rb b/lib/locomotive/steam/entities/content_entry.rb
+8
-1
| @@ | @@ -144,7 +144,14 @@ module Locomotive::Steam |
| def _cast_time(field, end_method) | |
| _cast_convertor(field.name) do |value| | |
| - | value.is_a?(String) ? Chronic.parse(value).send(end_method) : value |
| + | if value.is_a?(String) |
| + | # context: time from a YAML file (String). |
| + | # In that case, use the timezone defined by the site. |
| + | Chronic.time_class = Time.zone |
| + | Chronic.parse(value).send(end_method) |
| + | else |
| + | value |
| + | end |
| end | |
| end | |
spec/unit/entities/content_entry_spec.rb
+1
-0
| @@ | @@ -155,6 +155,7 @@ describe Locomotive::Steam::ContentEntry do |
| end | |
| context 'a date time' do | |
| + | before { Time.zone = 'UTC' } |
| let(:field_type) { :date_time } | |
| let(:value) { '2007/06/29 10:00:00' } | |
| let(:datetime) { DateTime.parse('2007/06/29 10:00:00') } | |