# ONE.rb

# $Id: ONE.rb,v 1.4 2002/05/01 14:33:47 hasimoto_fukui Exp $

# 2002/4/30  Ken-ichi HASHIMOTO <ken@po.ganseki.ne.jp>
# Copyright (C) 2002 Ken-ichi HASHIMOTO <ken@po.ganseki.ne.jp>
# This is free software with ABSOLUTELY NO WARRANTY.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


class RmpONE
	def setParameter( aParam )
		sd = aParam[1].split(/\//)
		st = aParam[2].split(/:/)
		et = aParam[3].split(/:/)

		# omittion of second
		if st.size == 2 then
			st << 00
		end
		if et.size == 2 then
			et << 00
		end

		@startTime = Time.mktime(sd[0],sd[1],sd[2],st[0],st[1],st[2])
		@endTime = Time.mktime(sd[0],sd[1],sd[2],et[0],et[1],et[2])

		# date line
		if (@startTime.to_i > @endTime.to_i ) then
			@endTime += 24*60*60
		end

		@parameter = aParam
	end

	def format( aTime )
		startTime = @startTime.to_i
		now = aTime.to_i
		tomorrow = now+60*60*24

		if (startTime > now) and (startTime < tomorrow)  then
			startDate = @startTime.strftime("%Y/%m/%d")
			startTime = @startTime.strftime("%H:%M:%S")
			endDate = @endTime.strftime("%Y/%m/%d")
			endTime = @endTime.strftime("%H:%M:%S")
			return "#{startDate} #{startTime} #{endDate} #{endTime} #{@parameter[4]} #{@parameter[5]} #{@parameter[6]}"
		else
			return nil
		end
	end
end

