Class: CiscoWebex::Toolbox::WebexTime
- Inherits:
-
Object
- Object
- CiscoWebex::Toolbox::WebexTime
- Defined in:
- lib/Toolbox/Toolbox.rb
Class Method Summary collapse
-
.consistent_timestamp(timestamp = "now") ⇒ Object
converts possible time type to `Time` format for easier parsing.
- .error ⇒ Object
-
.format(timestamp, time_format = "control_hub") ⇒ Object
Format time based on default for Controlhub CC open for epoch.
- .now ⇒ Object
-
.round(timestamp = "now", interval = 15, time_format = "control_hub") ⇒ Object
round time to nearest 15min default.
-
.shift(timestamp = "now", shift_seconds = 60, time_format = "control_hub", round = 0) ⇒ Object
shift curret time by X seconds round if required.
Class Method Details
.consistent_timestamp(timestamp = "now") ⇒ Object
converts possible time type to `Time` format for easier parsing
37 38 39 40 41 42 43 44 |
# File 'lib/Toolbox/Toolbox.rb', line 37 def self.(="now") return if .class == Time return Time.now() if .class == String && .downcase == "now" return Time.parse() if .class == String return Time.at() if .class == Integer return Time.parse(.to_s) if .class == DateTime return self.error() end |
.error ⇒ Object
27 28 29 30 |
# File 'lib/Toolbox/Toolbox.rb', line 27 def self.error() STDERR.puts "Error CiscoWebex::Toolbox::WebexTime: Could not format/transform time from timestamp" return false end |
.format(timestamp, time_format = "control_hub") ⇒ Object
Format time based on default for Controlhub CC open for epoch
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/Toolbox/Toolbox.rb', line 47 def self.format(, time_format="control_hub") = self.() if time_format.downcase() == "cc" || time_format.downcase() =~ /contact.*/ return .strftime("%s").to_i rescue self.error() elsif time_format.downcase() == "epoch" || time_format.downcase() == "ms" return .strftime("%s").to_i * 1000 else return .strftime("%Y-%m-%dT%H:%M:%S.000Z") rescue self.error() end end |
.now ⇒ Object
32 33 34 |
# File 'lib/Toolbox/Toolbox.rb', line 32 def self.now() return Time.now() end |
.round(timestamp = "now", interval = 15, time_format = "control_hub") ⇒ Object
round time to nearest 15min default
71 72 73 74 75 |
# File 'lib/Toolbox/Toolbox.rb', line 71 def self.round(="now", interval=15, time_format="control_hub") = self.() interval = interval.to_i return self.format(Time.at((.to_i / (interval*60)).round * interval*60).to_i, time_format) rescue self.error() end |
.shift(timestamp = "now", shift_seconds = 60, time_format = "control_hub", round = 0) ⇒ Object
shift curret time by X seconds round if required
63 64 65 66 67 68 |
# File 'lib/Toolbox/Toolbox.rb', line 63 def self.shift(="now", shift_seconds=60, time_format="control_hub", round=0) = self.() = self.(.to_i + shift_seconds) = self.round(, round, time_format) if round.to_i > 0 return self.format(, time_format) rescue self.error() end |