Class: GlooLang::Objs::Datetime

Inherits:
Core::Obj show all
Defined in:
lib/gloo_lang/objs/dt/datetime.rb

Constant Summary collapse

KEYWORD =
'datetime'.freeze
KEYWORD_SHORT =
'dt'.freeze
DEFAULT_FORMAT =
'%Y.%m.%d %I:%M:%S %P'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #root?, #send_message, #set_parent, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from GlooLang::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



52
53
54
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 52

def self.messages
  return super + %w[now is_today is_future is_past is_yesterday is_tomorrow is_this_week]
end

.short_typenameObject

The short name of the object type.



26
27
28
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 26

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



19
20
21
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 19

def self.typename
  return KEYWORD
end

Instance Method Details

#msg_is_futureObject

Tell the datetime to check if it is in the future.



68
69
70
71
72
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 68

def msg_is_future
  today = DtTools.is_future?( self.value )
  @engine.heap.it.set_to today
  return today
end

#msg_is_pastObject

Tell the datetime to check if it is in the past.



77
78
79
80
81
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 77

def msg_is_past
  today = DtTools.is_past?( self.value )
  @engine.heap.it.set_to today
  return today
end

#msg_is_this_weekObject

Tell the datetime to check if it is this week.



104
105
106
107
108
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 104

def msg_is_this_week
  today = DtTools.is_this_week?( self.value )
  @engine.heap.it.set_to today
  return today
end

#msg_is_todayObject

Tell the datetime to check if it is today.



59
60
61
62
63
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 59

def msg_is_today
  today = DtTools.is_today?( self.value )
  @engine.heap.it.set_to today
  return today
end

#msg_is_tomorrowObject

Tell the datetime to check if it is tomorrow.



95
96
97
98
99
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 95

def msg_is_tomorrow
  today = DtTools.is_tomorrow?( self.value )
  @engine.heap.it.set_to today
  return today
end

#msg_is_yesterdayObject

Tell the datetime to check if it is yesterday.



86
87
88
89
90
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 86

def msg_is_yesterday
  today = DtTools.is_yesterday?( self.value )
  @engine.heap.it.set_to today
  return today
end

#msg_nowObject

Set to the current date and time.



113
114
115
116
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 113

def msg_now
  self.set_value( DateTime.now )
  @engine.heap.it.set_to self.value
end

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gloo_lang/objs/dt/datetime.rb', line 33

def set_value( new_value )
  if DtTools.is_dt_type? new_value
    self.value = new_value
  else
    self.value = @engine.converter.convert( new_value, 'DateTime', nil )
  end

  if DtTools.is_dt_type? self.value
    self.value = self.value.strftime( DEFAULT_FORMAT )
  end
end