Class: Nydp::Builtin::Time
- Defined in:
- lib/nydp/builtin/time.rb
Instance Method Summary collapse
- #builtin_invoke(vm, args) ⇒ Object
- #builtin_invoke_1(vm) ⇒ Object
-
#builtin_invoke_2(vm, arg) ⇒ Object
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.
-
#builtin_invoke_3(vm, a0, a1) ⇒ Object
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
#builtin_invoke_4, #handle_error, #inspect, #invoke, #invoke_1, #invoke_2, #invoke_3, #invoke_4, #name, #nydp_type, #to_s
Instance Method Details
#builtin_invoke(vm, args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nydp/builtin/time.rb', line 40 def builtin_invoke vm, args # assume ruby Time constructor args y mo d h mi s ms y = args.car mo = args.cdr.car d = args.cdr.cdr.car h = args.cdr.cdr.cdr.car if args.size > 3 mi = args.cdr.cdr.cdr.cdr.car if args.size > 4 s = args.cdr.cdr.cdr.cdr.cdr.car if args.size > 5 ms = args.cdr.cdr.cdr.cdr.cdr.cdr.car if args.size > 6 vm.push_arg(Time.new(y,mo,d,h,mi,s,ms)) end |
#builtin_invoke_1(vm) ⇒ Object
5 6 7 |
# File 'lib/nydp/builtin/time.rb', line 5 def builtin_invoke_1 vm vm.push_arg ::Time.now end |
#builtin_invoke_2(vm, arg) ⇒ Object
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
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nydp/builtin/time.rb', line 13 def builtin_invoke_2 vm, arg case arg when Numeric # relative time in seconds vm.push_arg(Time.now + arg) when Nydp::Date vm.push_arg arg.to_ruby.to_time when ::Time vm.push_arg ::Time.now - arg else raise Nydp::Error.new "time : expected a number or a date or a time, got #{arg.inspect}" end end |
#builtin_invoke_3(vm, a0, a1) ⇒ Object
first arg is a Time if second arg is numeric, add to first arg if second arg is a Time, subtract from first arg
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nydp/builtin/time.rb', line 29 def builtin_invoke_3 vm, a0, a1 case a1 when Numeric # relative time in seconds vm.push_arg(a0 + a1) when ::Time vm.push_arg a0 - a1 else raise Nydp::Error.new "time : expected a number or a date, got #{a1.inspect}" end end |