Skip to content

Instantly share code, notes, and snippets.

@mhussain
Created April 28, 2017 09:09
Show Gist options
  • Save mhussain/5b8a9a764985827f6b9bfc4abd68ee13 to your computer and use it in GitHub Desktop.
Save mhussain/5b8a9a764985827f6b9bfc4abd68ee13 to your computer and use it in GitHub Desktop.
100 #@logger.info 'Calculating start and end time frames'
101 time_frame = p[i].gsub(/\D/, '')
102 @logger.error time_frame
103 st_i = '%04i' % (time_frame[0..3].to_i)
104 st_m = time_frame[0..3].to_i < 1200 ? 'AM' : 'PM'
105 en_i = '%04i' % time_frame[4..7].to_i
106 en_m = time_frame[4..7].to_i < 1200 ? 'AM' : 'PM'
107
108 s = time_frame[0..3].to_i
109 e = time_frame[4..7].to_i
110
111 start_date = d
112 end_date = (s > 1200 && e < 1200) ? d.next_day : d
113
114 start_time = "#{DateTime.strptime(st_i , '%H%M').strftime('%l:%M')} #{st_m}"
115 end_time = "#{DateTime.strptime(en_i , '%H%M').strftime('%l:%M')} #{en_m}"
116
117 @logger.debug "Start #{start_date.to_s} #{start_time}"
118 @logger.debug "End #{end_date.to_s} #{end_time}"
119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment