aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use strings instead of symbols on calls to decorate_matching_attribute_typesDillon Welch2018-08-101-1/+1
| | | | | | The first thing this method does is run on the argument. This change passes in a string so we don't allocate a bunch of unnecessary extra strings by calling to_s on a symbol over and over.
* Add :nodoc: for ActiveRecord::AttributeMethods [ci skip]Yoshiyuki Hirano2017-08-261-1/+1
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-031-2/+1
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-5/+2
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Remove unused requireRyuta Kamizono2017-02-121-2/+0
| | | | | | These files are not using `strip_heredoc`. Closes #27976
* Set time as a timezone aware type and remove related deprecationRafael Mendonça França2016-12-291-23/+2
|
* fix datatime errorSen-Zhang2016-11-011-1/+1
|
* Fixes an issue where time_zone_conversion that causes an exception in ARs ↵Julian Nadeau2016-10-271-1/+1
| | | | | | | | | delegation Following off of https://github.com/rails/rails/issues/15945, I realized that super needs to be the first thing that is called in an AbstractModel's inherited method. I was receiving errors within the inherited method of time_zone_conversion, so I tested locally by moving super to the top of the method declaration. All exceptions went away.
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-8/+8
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-44/+44
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fixes multiparameter attributes conversion with time_zone_aware_attributes ↵alpaca-tc2016-07-191-1/+1
| | | | and invalid params
* Fix a tip in Active Record time attributes deprecationGenadi Samokovarov2016-03-241-1/+1
| | | | | | | | | | | | | | | I have hit this deprecation in a newly created Rails 5 application and the suggested tip lead me to a `NoMethodError`. It's not trivial to actually make the following work, because of the ActiveRecord::Base class attributes setting dance in the Active Record railtie. config.active_record.time_zone_aware_types << :time Decided to suggest setting it explicitly to the values we need. [ci skip]
* Ensure tz aware attributes continue to work with arraysSean Griffin2016-02-021-1/+1
| | | | There was a typo in the variable name leading to infinite recursion
* Avoid infinite recursion when bad values are passed to tz aware fieldsSean Griffin2016-02-021-2/+12
| | | | | | | | | | | | | | | We had previously updated this to attempt to map over whatever was passed in, so that additional types like range and array could benefit from this behavior without the time zone converter having to deal with every known type. However, the default behavior of a type is to just yield the given value to `map`, which means that if we don't actually know how to handle a value, we'll just recurse infinitely. Since both uses of `map` in this case occur in cases where we know receiving the same object will recurse, we can just break on reference equality. Fixes #23241.
* Fix the broken buildSean Griffin2016-01-081-0/+2
| | | | | | This is really strange, as it passes on Travis for 2.3, and it passes for me locally on 2.2. But on travis w/ 2.2, passing `Float::INFINITY` in is resulting in an infinite loop. This should resolve it.
* Refactor tz aware types, add support for PG rangesSean Griffin2016-01-081-7/+9
| | | | | | | | | | | | | | | | | This is an alternate implementation to #22875, that generalizes a lot of the logic that type decorators are going to need, in order to have them work with arrays, ranges, etc. The types have the ability to map over a value, with the default implementation being to just yield that given value. Array and Range give more appropriate definitions. This does not automatically make ranges time zone aware, as they need to be added to the `time_zone_aware` types config, but we could certainly make that change if we feel it is appropriate. I do think this would be a breaking change however, and should at least have a deprecation cycle. Closes #22875. /cc @matthewd
* remove extra spaces from deprecation messageyuuji.yaginuma2015-12-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` # before DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes `String`s to be parsed as if they were in `Time.zone`, and `Time`s to be converted to `Time.zone`. To keep the old behavior, you must add the following to your initializer: config.active_record.time_zone_aware_types = [:datetime] To silence this deprecation warning, add the following: config.active_record.time_zone_aware_types << :time ``` ``` # after DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes `String`s to be parsed as if they were in `Time.zone`, and `Time`s to be converted to `Time.zone`. To keep the old behavior, you must add the following to your initializer: config.active_record.time_zone_aware_types = [:datetime] To silence this deprecation warning, add the following: config.active_record.time_zone_aware_types << :time ```
* Apply subsecond precision on assignment when using TZ aware attributesSean Griffin2015-09-241-1/+1
| | | | | | | | | | | When a time object was assigned to a datetime column, the decorator for TZ aware attributes wouldn't call super, so when using a database without support for subsecond precision, the nanosecond would not be truncated, leading to the value being marked as changed. Interestingly, this also shows our new implementation of dirty checking to be more robust than the old one (with less code and better performance! :tada:!!!)
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-171-2/+2
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-1/+1
|
* rm `ActiveRecord::Type::Decorator`Sean Griffin2015-02-071-2/+0
| | | | | | | It only existed to make sure the subclasses of `Delegator` were YAML serializable. As of Ruby 2.2, these are YAML dumpable by default, as it includes https://github.com/tenderlove/psych/commit/2a4d9568f7d5d19c00231cf48eb855cc45ec3394
* Push multi-parameter assignement into the typesSean Griffin2015-02-071-0/+8
| | | | | | | | | | | | This allows us to remove `Type::Value#klass`, as it was only used for multi-parameter assignment to reach into the types internals. The relevant type objects now accept a hash in addition to their previous accepted arguments to `type_cast_from_user`. This required minor modifications to the tests, since previously they were relying on the fact that mulit-parameter assignement was reaching into the internals of time zone aware attributes. In reaility, changing those properties at runtime wouldn't change the accessor methods for all other forms of assignment.
* fix typo still cause -> still causesFelix Schäfer2015-01-271-1/+1
|
* [ci skip] fix typo sill -> stillAditya Kapoor2015-01-151-1/+1
|
* Time columns should support time zone aware attributesSean Griffin2015-01-151-4/+29
| | | | | | The types that are affected by `time_zone_aware_attributes` (which is on by default) have been made configurable, in case this is a breaking change for existing applications.
* Don't raise on out-of-range datetimes passed by a userGrey Baker2014-12-231-1/+5
|
* Allow custom handling of non-standard types in `time_zone_conversion`Sean Griffin2014-12-081-1/+1
| | | | | | | | | | | | PostgreSQL for example, allows infinity as a valid value for date time columns. The PG type has explicit handling for that case. However, time zone conversion will end up trampling that handling. Unfortunately, we can't call super and then convert time zones. However, if we get back nil from `.in_time_zone`, it's something we didn't expect so we can let the superclass handle it. Fixes #17971
* Use `DelegateClass` instead of `SimpleDelegator` for type decoratorsSean Griffin2014-11-141-1/+1
| | | | There is a significant performance difference between the two. Closes
* Allow YAML serialization when using TZ aware attributesSean Griffin2014-09-171-0/+2
|
* Stop using instance exec for type decoratorsSean Griffin & Sean Doyle2014-06-271-5/+15
| | | | | | | | We are moving this behavior out to an object that we would like to keep separated from `ActiveRecord::Base`, which means not passing the class object to it. As such, we need to stop using `instance_exec`, and instead close over the subclass on global type decorators that are applied in `Base`.
* Silence warning in testSean Griffin2014-06-241-2/+2
| | | | | We still had one file using `column_for_attribute` when it could return nil, causing deprecation warnings in the tests.
* Promote time zone aware attributes to a first class type decoratorSean Griffin2014-06-161-1/+6
| | | | | | | | | | | | | This refactoring revealed the need for another form of decoration, which takes a proc to select which it applies to (There's a *lot* of cases where this form can be used). To avoid duplication, we can re-implement the old decoration in terms of the proc-based decoration. The reason we're `instance_exec`ing the matcher is for cases such as time zone aware attributes, where a decorator is defined in a parent class, and a method called in the matcher is overridden by a child class. The matcher will close over the parent, and evaluate in its context, which is not the behavior we want.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Make `_before_type_cast` actually be before type castSean Griffin2014-06-091-40/+11
| | | | | | | | | | | | | - The following is now true for all types, all the time - `model.attribute_before_type_cast == given_value` - `model.attribute == model.save_and_reload.attribute` - `model.attribute == model.dup.attribute` - `model.attribute == YAML.load(YAML.dump(model)).attribute` - Removes the remaining types implementing `type_cast_for_write` - Simplifies the implementation of time zone aware attributes - Brings tz aware attributes closer to being implemented as an attribute decorator - Adds additional point of control for custom types
* Ensure time zones don't change after round trip with array columnsSean Griffin2014-06-071-1/+11
| | | | | The times would be equivalent, even if they were in different time zones. E.g. 12:00 UTC == 5:00 PDT
* changelog for #15556 and credit @kuldeepaggarwal [Kuldeep Aggarwal]Yves Senn2014-06-071-2/+0
| | | | | | This is a follow up to #15556 @kuldeepaggarwal did submit this patch way back (#13624).
* Add array support when time zone aware attributes are enabledSean Griffin2014-06-071-1/+13
|
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-1/+1
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* Add an interface for type objects to control Ruby => SQLSean Griffin2014-05-261-4/+2
| | | | | Adds the ability to save custom types, which type cast to non-primitive ruby objects.
* Remove :timestamp column typeSean Griffin2014-05-191-2/+2
| | | | | | | | | | | | The `:timestamp` type for columns is unused. All database adapters treat them as the same database type. All code in `ActiveRecord` which changes its behavior based on the column's type acts the same in both cases. However, when the type is passed to code that checks for the `:datetime` type, but not `:timestamp` (such as XML serialization), the result is unexpected behavior. Existing schema definitions will continue to work, and the `timestamp` type is transparently aliased to `datetime`.
* Perf: avoid array allocation where not neededSam2013-08-271-1/+1
|
* Simplify type casting code for timezone aware attributesAndrew White2013-01-261-10/+5
| | | | | | With the addition of String#in_time_zone and Date#in_time_zone we can simplify the type casting code by checking if the value has an `in_time_zone` method.
* Fix handling of dirty time zone aware attributesLilibeth De La Cruz2013-01-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, when `time_zone_aware_attributes` were enabled, after changing a datetime or timestamp attribute and then changing it back to the original value, `changed_attributes` still tracked the attribute as changed. This caused `[attribute]_changed?` and `changed?` methods to return true incorrectly. Example: in_time_zone 'Paris' do order = Order.new original_time = Time.local(2012, 10, 10) order.shipped_at = original_time order.save order.changed? # => false # changing value order.shipped_at = Time.local(2013, 1, 1) order.changed? # => true # reverting to original value order.shipped_at = original_time order.changed? # => false, used to return true end
* Revert "Round usec when writing timestamp attribute."Andrew White2013-01-221-13/+5
| | | | | | | | | | This reverts commit e9d2ad395ec2ef929d74752f3d71c80674044fbe. Closes #8460 Conflicts: activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb activerecord/test/cases/dirty_test.rb
* Don't call will_change! for datetime nil->"".Alisdair McDiarmid2012-11-251-0/+1
| | | | | | | Setting a nil datetime attribute to a blank string should not cause the attribute to be dirty. Fix #8310