class MilitaryTime
	attr_reader :hours, :minutes   # others can read but not write

	def initialize(str)
		@hours = 0
		@minutes = 0

		if str =~ /(\d\d)(\d\d)/ then
			@hours = $1.to_i
			@minutes = $2.to_i
#			hours = hours.sub(/^0/, "")		# get rid of the preceding 0, if there is one
											# e.g., 8:00 AM would be "0800"

#			@minutes = minutes.to_i
#			@hours = hours.to_i
		end
	end

	# Convert something like "1324" to "1:24 PM"
	def to_s()
		am_or_pm = "AM"
		hours = @hours % 12
		if @hours >= 12
			am_or_pm = "PM"
		end

		if hours == 0
			hours = 12
		end

		sprintf "%d:%.2d #{am_or_pm}", hours, @minutes
	end

	def minutes_until(other)
		ttl_mins = (@hours * 60) + @minutes
		o_ttl_mins = (other.hours * 60) + other.minutes
		diff = o_ttl_mins - ttl_mins
		while diff < 0
			diff += 24 * 60
		end
		return diff
	end

	def hours_until(other)
		return minutes_until(other).to_f / 60
	end
end
