diff options
Diffstat (limited to 'config/initializers/activesupport_duration_patch.rb')
| -rw-r--r-- | config/initializers/activesupport_duration_patch.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/config/initializers/activesupport_duration_patch.rb b/config/initializers/activesupport_duration_patch.rb new file mode 100644 index 0000000..c2b431d --- /dev/null +++ b/config/initializers/activesupport_duration_patch.rb | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | class Integer | ||
| 2 | def days | ||
| 3 | ActiveSupport::Duration.new(self * 86400, [[:days, self]]) | ||
| 4 | end | ||
| 5 | alias :day :days | ||
| 6 | |||
| 7 | def weeks | ||
| 8 | ActiveSupport::Duration.new(self * 7 * 86400, [[:days, self * 7]]) | ||
| 9 | end | ||
| 10 | alias :week :weeks | ||
| 11 | |||
| 12 | def hours | ||
| 13 | ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]]) | ||
| 14 | end | ||
| 15 | alias :hour :hours | ||
| 16 | |||
| 17 | def minutes | ||
| 18 | ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]]) | ||
| 19 | end | ||
| 20 | alias :minute :minutes | ||
| 21 | |||
| 22 | def seconds | ||
| 23 | ActiveSupport::Duration.new(self, [[:seconds, self]]) | ||
| 24 | end | ||
| 25 | alias :second :seconds | ||
| 26 | |||
| 27 | def months | ||
| 28 | ActiveSupport::Duration.new(self * 30 * 86400, [[:months, self]]) | ||
| 29 | end | ||
| 30 | alias :month :months | ||
| 31 | |||
| 32 | def years | ||
| 33 | ActiveSupport::Duration.new((self * 365.25 * 86400).to_i, [[:years, self]]) | ||
| 34 | end | ||
| 35 | alias :year :years | ||
| 36 | end | ||
| 37 | |||
| 38 | class Float | ||
| 39 | def days | ||
| 40 | ActiveSupport::Duration.new((self * 86400).to_i, [[:days, self]]) | ||
| 41 | end | ||
| 42 | alias :day :days | ||
| 43 | |||
| 44 | def hours | ||
| 45 | ActiveSupport::Duration.new((self * 3600).to_i, [[:seconds, (self * 3600).to_i]]) | ||
| 46 | end | ||
| 47 | alias :hour :hours | ||
| 48 | |||
| 49 | def minutes | ||
| 50 | ActiveSupport::Duration.new((self * 60).to_i, [[:seconds, (self * 60).to_i]]) | ||
| 51 | end | ||
| 52 | alias :minute :minutes | ||
| 53 | end | ||
