Class: Gloo::Objs::Datetime

Inherits:
Core::Obj show all
Defined in:
lib/gloo/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, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #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 Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



61
62
63
64
65
66
# File 'lib/gloo/objs/dt/datetime.rb', line 61

def self.messages
  return super + %w[now is_today is_future 
    is_past is_yesterday is_tomorrow is_this_week
    begin_day end_day begin_week end_week
    begin_month end_month begin_year end_year]
end

.short_typenameObject

The short name of the object type.



26
27
28
# File 'lib/gloo/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/objs/dt/datetime.rb', line 19

def self.typename
  return KEYWORD
end

Instance Method Details

#msg_begin_dayObject

Set the value to the beginning of the day.



125
126
127
128
129
# File 'lib/gloo/objs/dt/datetime.rb', line 125

def msg_begin_day
  dt = self.value.to_time.beginning_of_day
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_begin_monthObject

Set the value to the beginning of the month.



71
72
73
74
75
# File 'lib/gloo/objs/dt/datetime.rb', line 71

def msg_begin_month
  dt = DtTools.beginning_of_month( self.value.to_time )
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_begin_weekObject

Set the value to the beginning of the week.



107
108
109
110
111
# File 'lib/gloo/objs/dt/datetime.rb', line 107

def msg_begin_week
  dt = self.value.to_time.beginning_of_week( start_day = :sunday )
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_begin_yearObject

Set the value to the beginning of the year.



89
90
91
92
93
# File 'lib/gloo/objs/dt/datetime.rb', line 89

def msg_begin_year
  dt = self.value.to_time.beginning_of_year
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_end_dayObject

Set the value to the end of the day.



134
135
136
137
138
# File 'lib/gloo/objs/dt/datetime.rb', line 134

def msg_end_day
  dt = self.value.to_time.end_of_day
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_end_monthObject

Set the value to the end of the month.



80
81
82
83
84
# File 'lib/gloo/objs/dt/datetime.rb', line 80

def msg_end_month
  dt = DtTools.end_of_month( self.value.to_time )
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_end_weekObject

Set the value to the end of the week.



116
117
118
119
120
# File 'lib/gloo/objs/dt/datetime.rb', line 116

def msg_end_week
  dt = self.value.to_time.end_of_week( start_day = :sunday )
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_end_yearObject

Set the value to the end of the year.



98
99
100
101
102
# File 'lib/gloo/objs/dt/datetime.rb', line 98

def msg_end_year
  dt = self.value.to_time.end_of_year
  self.set_value dt
  @engine.heap.it.set_to dt
end

#msg_is_futureObject

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



153
154
155
156
157
# File 'lib/gloo/objs/dt/datetime.rb', line 153

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.



162
163
164
165
166
# File 'lib/gloo/objs/dt/datetime.rb', line 162

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.



189
190
191
192
193
# File 'lib/gloo/objs/dt/datetime.rb', line 189

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.



144
145
146
147
148
# File 'lib/gloo/objs/dt/datetime.rb', line 144

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.



180
181
182
183
184
# File 'lib/gloo/objs/dt/datetime.rb', line 180

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.



171
172
173
174
175
# File 'lib/gloo/objs/dt/datetime.rb', line 171

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.



198
199
200
201
# File 'lib/gloo/objs/dt/datetime.rb', line 198

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/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

#sql_valueObject

Value for a SQL query.



48
49
50
51
52
# File 'lib/gloo/objs/dt/datetime.rb', line 48

def sql_value
  return nil if self.value.blank?
  
  return Chronic.parse( self.value )
end