Class: Nydp::Builtin::Time
- Defined in:
- lib/nydp/builtin/time.rb
Instance Method Summary collapse
-
#builtin_call(y = :unset, mo = :unset, d = :unset, h = nil, mi = nil, s = nil, ms = nil) ⇒ Object
when 0 arguments: return Time.now when 1 argument: either an offset in seconds from now, or a Date to convert to a time, or a Time to subtract and return offset in seconds from now when Numeric : return now + offset in seconds from now when Nydp::Date : convert date to time when Time : calculate and return now - Time offset in seconds when 2 arguments: first arg is a Time if second arg is numeric, add to first arg if second arg is a Time, subtract from first arg.
Methods included from Helper
#cons, #list, #literal?, #pair?, #sig, #sym, #sym?
Methods included from Converter
Methods included from Base
#call, #handle_error, ignore_errors, #inspect, #name, #nydp_type, #to_s
Instance Method Details
#builtin_call(y = :unset, mo = :unset, d = :unset, h = nil, mi = nil, s = nil, ms = nil) ⇒ Object
when 0 arguments:
return Time.now
when 1 argument:
either an offset in seconds from now, or a Date to convert to a time, or a Time to subtract and return offset in seconds from now
when Numeric : return now + offset in seconds from now
when Nydp::Date : convert date to time
when Time : calculate and return now - Time offset in seconds
when 2 arguments:
first arg is a Time
if second arg is numeric, add to first arg
if second arg is a Time, subtract from first arg
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nydp/builtin/time.rb', line 16 def builtin_call y=:unset, mo=:unset, d=:unset, h=nil, mi=nil, s=nil, ms=nil if y == :unset ::Time.now elsif mo == :unset case y when Numeric # relative time in seconds (Time.now + y) when ::Date y.to_time when ::Time ::Time.now - y else puts puts y.class raise Nydp::Error.new "time : expected a number or a date or a time, got #{y._nydp_inspect}" end elsif d == :unset # y is a date or time, mo is a number or time case mo when Numeric # relative time in seconds (y + mo) when ::Time y - mo else raise Nydp::Error.new "time : expected a number or a date, got #{mo._nydp_inspect}" end else Time.new(y,mo,d,h,mi,s,ms) end end |