rpl.rb/lib/language/time-date.rb

31 lines
682 B
Ruby
Raw Normal View History

require 'date'
module Rpl
2021-12-07 15:50:58 +01:00
module Lang
module Core
module_function
2021-12-07 15:50:58 +01:00
# time in local format
def time( stack )
stack << { type: :string,
value: Time.now.to_s }
end
2021-12-07 15:50:58 +01:00
# date in local format
def date( stack )
stack << { type: :string,
value: Date.today.to_s }
end
2021-12-07 15:50:58 +01:00
# system tick in µs
def ticks( stack )
ticks_since_epoch = Time.utc( 1, 1, 1 ).to_i * 10_000_000
now = Time.now
stack << { type: :numeric,
base: 10,
value: now.to_i * 10_000_000 + now.nsec / 100 - ticks_since_epoch }
end
end
end
end