Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/mongoid/tracking/core_ext/time.rb
Constant Summary collapse
- ONEHOUR =
Functions to construct the MongoDB field key for trackers
to_i_timestamp returns the computed UTC timestamp regardless of the timezone.
Examples:
2011-01-01 00:00:00 UTC ===> 14975 2011-01-01 23:59:59 UTC ===> 14975 2011-01-02 00:00:00 UTC ===> 14976to_i_hour returns the hour for the date, again regardless of TZ
2011-01-01 00:00:00 UTC ===> 0 2011-01-01 23:59:59 UTC ===> 23 60 * 60
- ONEDAY =
24 * ONEHOUR
Class Method Summary collapse
Instance Method Summary collapse
- #to_i_hour ⇒ Object
- #to_i_timestamp ⇒ Object
-
#to_key ⇒ Object
Returns an integer to use as MongoDB key.
- #to_key_hour ⇒ Object
- #to_key_timestamp ⇒ Object
-
#whole_day ⇒ Object
Returns a range to be enumerated using hours for the whole day.
Class Method Details
Instance Method Details
#to_i_hour ⇒ Object
30 31 32 |
# File 'lib/mongoid/tracking/core_ext/time.rb', line 30 def to_i_hour self.dup.utc.hour end |
#to_i_timestamp ⇒ Object
21 22 23 24 |
# File 'lib/mongoid/tracking/core_ext/time.rb', line 21 def #Adding a fix for case where the 'quo' is being used instead of Fixnum's '/' operator (self.dup.utc.to_i / ONEDAY).to_i end |
#to_key ⇒ Object
Returns an integer to use as MongoDB key
39 40 41 |
# File 'lib/mongoid/tracking/core_ext/time.rb', line 39 def to_key "#{}.#{to_i_hour}" end |
#to_key_hour ⇒ Object
34 35 36 |
# File 'lib/mongoid/tracking/core_ext/time.rb', line 34 def to_key_hour to_i_hour.to_s end |
#to_key_timestamp ⇒ Object
26 27 28 |
# File 'lib/mongoid/tracking/core_ext/time.rb', line 26 def .to_s end |
#whole_day ⇒ Object
Returns a range to be enumerated using hours for the whole day
48 49 50 51 |
# File 'lib/mongoid/tracking/core_ext/time.rb', line 48 def whole_day midnight = utc? ? Time.utc(year, month, day) : Time.new(year, month, day, 0, 0, 0, utc_offset) midnight...(midnight + ::Range::DAYS) end |