Method: ALib::Util#stamptime
- Defined in:
-
lib/alib-0.5.0/util.rb,
lib/alib-0.5.0/util.rb
TODO - 1.8.4 parses usec but 1.8.2 does not. handle differently.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/alib-0.5.0/util.rb', line 296 def stamptime string, opts = {} #--{{{ tz = string[ %r/-\d\d:\d\d\s*$/ ] time = nil if opts.empty? or tz u = string[%r/\.\d+/] string[%r/\.\d+/] = '' if u time = Time::parse string time += u.to_f if u else local = getopt 'local', opts, false string = "#{ string }" pat = %r/^\s*(\d\d\d\d)-(\d\d)-(\d\d)[\s_tT]+(\d\d):(\d\d):(\d\d)(?:.(\d+))?\s*$/o match = pat.match string raise ArgumentError, "<#{ string.inspect }>" unless match yyyy,mm,dd,h,m,s,u = match.to_a[1..-1].map{|m| (m || 0).to_i} if local time = Time::local yyyy,mm,dd,h,m,s,u else time = Time::gm yyyy,mm,dd,h,m,s,u end end return time #--}}} end |