Skip to content

Commit dc6fb4a

Browse files
style(Rails/TimeZone): manual
1 parent 61ab07e commit dc6fb4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+161
-199
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -756,51 +756,6 @@ Rails/SkipsModelValidations:
756756
- 'spec/mongoid/touchable_spec.rb'
757757
- 'spec/support/models/server.rb'
758758

759-
# Offense count: 159
760-
# This cop supports unsafe autocorrection (--autocorrect-all).
761-
# Configuration parameters: EnforcedStyle.
762-
# SupportedStyles: strict, flexible
763-
Rails/TimeZone:
764-
Exclude:
765-
- 'lib/mongoid/criteria/queryable/extensions/date.rb'
766-
- 'lib/mongoid/criteria/queryable/extensions/string.rb'
767-
- 'lib/mongoid/extensions/array.rb'
768-
- 'lib/mongoid/extensions/date.rb'
769-
- 'lib/mongoid/extensions/float.rb'
770-
- 'lib/mongoid/extensions/integer.rb'
771-
- 'lib/mongoid/extensions/string.rb'
772-
- 'lib/mongoid/extensions/time.rb'
773-
- 'lib/mongoid/timestamps/created.rb'
774-
- 'lib/mongoid/timestamps/updated.rb'
775-
- 'lib/mongoid/touchable.rb'
776-
- 'spec/integration/criteria/date_field_spec.rb'
777-
- 'spec/integration/criteria/raw_value_spec.rb'
778-
- 'spec/integration/persistence/range_field_spec.rb'
779-
- 'spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb'
780-
- 'spec/mongoid/association/referenced/has_many_spec.rb'
781-
- 'spec/mongoid/attributes/readonly_spec.rb'
782-
- 'spec/mongoid/attributes_spec.rb'
783-
- 'spec/mongoid/copyable_spec.rb'
784-
- 'spec/mongoid/criteria/queryable/extensions/array_spec.rb'
785-
- 'spec/mongoid/criteria/queryable/extensions/date_spec.rb'
786-
- 'spec/mongoid/criteria/queryable/extensions/date_time_spec.rb'
787-
- 'spec/mongoid/criteria/queryable/extensions/range_spec.rb'
788-
- 'spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb'
789-
- 'spec/mongoid/criteria/queryable/selectable_logical_spec.rb'
790-
- 'spec/mongoid/criteria/queryable/selectable_spec.rb'
791-
- 'spec/mongoid/criteria/queryable/selector_spec.rb'
792-
- 'spec/mongoid/extensions/range_spec.rb'
793-
- 'spec/mongoid/extensions/time_spec.rb'
794-
- 'spec/mongoid/extensions/time_with_zone_spec.rb'
795-
- 'spec/mongoid/mongoizable_spec.rb'
796-
- 'spec/mongoid/persistable/savable_spec.rb'
797-
- 'spec/mongoid/persistable/updatable_spec.rb'
798-
- 'spec/mongoid/timestamps/updated/short_spec.rb'
799-
- 'spec/mongoid/timestamps/updated_spec.rb'
800-
- 'spec/mongoid/timestamps_spec.rb'
801-
- 'spec/mongoid/touchable_spec.rb'
802-
- 'spec/support/models/post.rb'
803-
804759
# Offense count: 5
805760
# Configuration parameters: Include.
806761
# Include: spec/**/*.rb, test/**/*.rb

docs/reference/associations.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ help of MongoDB projection operation:
589589
# {"find"=>"bands",
590590
# "filter"=>{"started_on"=>{"$gt"=>2018-07-01 00:00:00 UTC}},
591591
# "projection"=>{"_id"=>1, "label"=>1}}
592-
Band.where(started_on: {'$gt' => Time.now - 1.year}).only(:label).map(&:label).compact.uniq
592+
Band.where(started_on: {'$gt' => Time.zone.now - 1.year}).only(:label).map(&:label).compact.uniq
593593

594594
Setting Stale Values on Referenced Associations
595595
```````````````````````````````````````````````

docs/reference/crud.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ are:
455455
end
456456

457457
post = Post.create!
458-
post.set('metadata.published_at' => Time.now)
458+
post.set('metadata.published_at' => Time.zone.now)
459459
post.metadata['published_at'] # => Time instance
460460

461461
post.set('metadata.approved.today' => true)

lib/mongoid/criteria/queryable/extensions/date.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __evolve_date__
2525
#
2626
# @return [ Time | ActiveSupport::TimeWithZone ] The date as a local time.
2727
def __evolve_time__
28-
::Time.configured.local(year, month, day)
28+
::Time.zone.local(year, month, day)
2929
end
3030

3131
module ClassMethods

lib/mongoid/criteria/queryable/extensions/string.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module String
1515
#
1616
# @return [ Time ] The time at UTC midnight.
1717
def __evolve_date__
18-
time = ::Time.parse(self)
18+
time = ::Time.zone.parse(self)
19+
return nil if time.nil?
20+
1921
::Time.utc(time.year, time.month, time.day, 0, 0, 0, 0)
2022
end
2123

@@ -26,6 +28,8 @@ def __evolve_date__
2628
#
2729
# @return [ Time ] The string as a time.
2830
def __evolve_time__
31+
return nil if __evolve_date__.nil?
32+
2933
__mongoize_time__.utc
3034
end
3135

lib/mongoid/extensions/array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __mongoize_object_id__
5050
# configured default time zone corresponding to date/time components
5151
# in this array.
5252
def __mongoize_time__
53-
::Time.configured.local(*self)
53+
::Time.zone.local(*self)
5454
end
5555

5656
# Checks whether conditions given in this array are known to be

lib/mongoid/extensions/date.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Date
1616
# configured default time zone corresponding to local midnight of
1717
# this date.
1818
def __mongoize_time__
19-
::Time.configured.local(year, month, day)
19+
::Time.zone.local(year, month, day)
2020
end
2121

2222
# Turn the object from the ruby type we deal with to a Mongo friendly
@@ -71,7 +71,7 @@ def mongoize(object)
7171
begin
7272
time = if object.is_a?(String)
7373
# https://jira.mongodb.org/browse/MONGOID-4460
74-
::Time.parse(object)
74+
::Time.zone.parse(object)
7575
else
7676
object.__mongoize_time__
7777
end

lib/mongoid/extensions/float.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Float
1313
#
1414
# @return [ Time | ActiveSupport::TimeWithZone ] The time.
1515
def __mongoize_time__
16-
::Time.configured.at(self)
16+
::Time.zone.at(self)
1717
end
1818

1919
# Is the float a number?

lib/mongoid/extensions/integer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Integer
1313
#
1414
# @return [ Time | ActiveSupport::TimeWithZone ] The time.
1515
def __mongoize_time__
16-
::Time.configured.at(self)
16+
::Time.zone.at(self)
1717
end
1818

1919
# Is the integer a number?

lib/mongoid/extensions/string.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def __mongoize_time__
4444
# either returns nil or Time.now if the string is empty or invalid,
4545
# which is a regression from pre-3.0 and also does not agree with
4646
# the core Time API.
47-
parsed = ::Time.parse(self)
48-
if ::Time.configured == ::Time
47+
parsed = ::Time.zone.parse(self)
48+
if ::Time.zone == ::Time
4949
parsed
5050
else
51-
::Time.configured.parse(self)
51+
::Time.zone.parse(self)
5252
end
5353
end
5454

0 commit comments

Comments
 (0)