Module: PositiveTimeSupport::DateTimeExt::ClassMethods
- Defined in:
- lib/positive_time_support/date_time_ext.rb
Overview
日付・時刻を扱うクラス DateTime にクラスメソッドを追加するためのモジュール
Instance Method Summary collapse
-
#convert_str(str, time_now = ::DateTime.now, time_zone: "+09:00") ⇒ DateTime
hh:mm の形の文字列を、DateTime のインスタンスに変換するメソッド.
Instance Method Details
#convert_str(str, time_now = ::DateTime.now, time_zone: "+09:00") ⇒ DateTime
hh:mm の形の文字列を、DateTime のインスタンスに変換するメソッド
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/positive_time_support/date_time_ext.rb', line 13 def convert_str( str , time_now = ::DateTime.now , time_zone: "+09:00" ) rational_for_time_zone = ::Kernel.Rational(9,24) time_now = time_now.new_offset( rational_for_time_zone ) if str.string? and time_now.instance_of?( ::DateTime ) and ::PositiveStringSupport::RegexpLibrary.string_of_hour_and_min =~ str return ::DateTime.new( time_now.year , time_now.month , time_now.day , $1.to_i , $2.to_i , 0 , rational_for_time_zone ) end raise "Error: The variable(s) are not valid. (\'str\'\: #{str} / Class: #{str.class.name})" end |