Class: MegliHelper::TimeHelper
- Inherits:
-
Object
- Object
- MegliHelper::TimeHelper
- Defined in:
- lib/helpers/time_helper.rb
Class Method Summary collapse
-
.change_timezone(time, timezone = '+00:00') ⇒ Time
Change timezone of a time passed.
-
.format_date(time, format) ⇒ String
Format a time according to format passed by param.
-
.get_time(format = :iso8601, add_minutes = 0) ⇒ String
Get time now with addinional minutes and convert it to format passed.
Class Method Details
.change_timezone(time, timezone = '+00:00') ⇒ Time
Change timezone of a time passed
9 10 11 12 |
# File 'lib/helpers/time_helper.rb', line 9 def self.change_timezone(time, timezone = '+00:00') time = Time.parse(time) if time.class == String time.localtime(timezone) end |
.format_date(time, format) ⇒ String
Format a time according to format passed by param
18 19 20 21 |
# File 'lib/helpers/time_helper.rb', line 18 def self.format_date(time, format) time = Time.parse(time) if time.class == String time.strftime(format) end |
.get_time(format = :iso8601, add_minutes = 0) ⇒ String
Get time now with addinional minutes and convert it to format passed
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/helpers/time_helper.rb', line 27 def self.get_time(format = :iso8601, add_minutes = 0) return nil if add_minutes.nil? add_minutes = add_minutes.to_i if add_minutes.class == String time = Time.now + (60 * add_minutes) unless format.nil? time = time.iso8601 if format == :iso8601 time = time.utc if format == :utc time = time.rfc822 if format == :rfc822 || format == :rfc2822 time = time.ctime if format == :ctime end time end |