Module: Quant::TimeMethods
- Included in:
- Quant::Ticks::OHLC, Quant::Ticks::Spot
- Defined in:
- lib/quant/time_methods.rb
Constant Summary collapse
- EPOCH_DATE =
Provides lower-bounds for dates and times. See
Quant::TimePeriodfor example use-case. Date.civil(1492, 10, 12).freeze
- EPOCH_TIME =
Time.new(EPOCH_DATE.year, EPOCH_DATE.month, EPOCH_DATE.day, 0, 0, 0, "+00:00").utc.freeze
Class Method Summary collapse
-
.epoch_date ⇒ Object
The epoch date is a NULL object
Datefor the library. -
.epoch_time ⇒ Object
The epoch time is a NULL object
Timefor the library.
Instance Method Summary collapse
-
#extract_time(value) ⇒ Object
When streaming or extracting a time entry from a payload, Time can already be parsed into a
Timeobject.
Class Method Details
.epoch_date ⇒ Object
The epoch date is a NULL object Date for the library. It is used to represent the beginning of time. That is, a date that is without bound and helps avoid nil checks, NULL database entries, and such when working with dates.
26 27 28 |
# File 'lib/quant/time_methods.rb', line 26 def self.epoch_date EPOCH_DATE end |
.epoch_time ⇒ Object
The epoch time is a NULL object Time for the library. It is used to represent the beginning of time. That is, a time that is without bound and helps avoid nil checks, NULL database entries, and such when working with time.
33 34 35 |
# File 'lib/quant/time_methods.rb', line 33 def self.epoch_time EPOCH_TIME end |
Instance Method Details
#extract_time(value) ⇒ Object
When streaming or extracting a time entry from a payload, Time can already be parsed into a Time object. Or it may be an Integer representing the number of seconds since the epoch. Or it may be a String that can be parsed into a Time object. This method normalizes the time into a Time object on the UTC timezone.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quant/time_methods.rb', line 40 def extract_time(value) case value when Time value.utc when Integer Time.at(value).utc when String Time.parse(value).utc else raise ArgumentError, "Invalid time: #{value.inspect}" end end |