Class: HungryHub::Time
- Inherits:
-
Object
- Object
- HungryHub::Time
- Defined in:
- app/my_lib/hungry_hub/time.rb
Constant Summary collapse
- DEFAULT_ZONE =
'Asia/Bangkok'- SINGAPORE_ZONE =
'Asia/Singapore'- MALAYSIA_ZONE =
'Asia/Kuala_Lumpur'
Class Method Summary collapse
Class Method Details
.human_readable_time(minutes) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/my_lib/hungry_hub/time.rb', line 31 def human_readable_time(minutes) return '0 seconds' if minutes.nil? || !minutes.is_a?(Numeric) begin total_seconds = minutes * 60 # Use ChronicDuration to handle positive time output = ChronicDuration.output(total_seconds.abs, format: :long) # Add negative sign back if the time was negative total_seconds.negative? ? "-#{output}" : output rescue ChronicDuration::DurationParseError => e APMErrorHandler.report('Failed to convert minutes to human readable format', minutes: minutes, exception: e) 'Invalid time format' end end |
.parse_to_db(time, addition = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/my_lib/hungry_hub/time.rb', line 12 def parse_to_db(time, addition = nil) return '00:00:00' if time.nil? begin if time.is_a?(::Time) time += addition if addition return time.strftime('%H:%M:%S') end parsed_time = Chronic.parse(time) raise 'Invalid time' if parsed_time.nil? parsed_time += addition if addition parsed_time.strftime('%H:%M:%S') rescue StandardError => e APMErrorHandler.report 'Failed parse time', time: time, exception: e raise e end end |