Module: RplLang::Words::TimeAndDate

Includes:
Types
Included in:
Rpl
Defined in:
lib/rpl/words/time-date.rb

Instance Method Summary collapse

Methods included from Types

new_object

Instance Method Details

#populate_dictionaryObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rpl/words/time-date.rb', line 10

def populate_dictionary
  super

  @dictionary.add_word( ['time'],
                        'Time and date',
                        '( -- t ) push current time',
                        proc do
                          @stack << Types.new_object( RplString, "\"#{Time.now}\"" )
                        end )
  @dictionary.add_word( ['date'],
                        'Time and date',
                        '( -- d ) push current date',
                        proc do
                          @stack << Types.new_object( RplString, "\"#{Date.today}\"" )
                        end )
  @dictionary.add_word( ['ticks'],
                        'Time and date',
                        '( -- t ) push datetime as ticks',
                        proc do
                          ticks_since_epoch = Time.utc( 1, 1, 1 ).to_i * 10_000_000
                          now = Time.now
                          @stack << Types.new_object( RplNumeric, now.to_i * 10_000_000 + now.nsec / 100 - ticks_since_epoch )
                        end )
end