Sha256: 83d4314e46dd32a9a1a4edee0ecac6d5d7bcd7e07c3d1162fd3b4f84f6852fa0

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# A Date and Time object.
#

module GlooLang
  module Objs
    class Datetime < GlooLang::Core::Obj

      KEYWORD = 'datetime'.freeze
      KEYWORD_SHORT = 'dt'.freeze

      #
      # The name of the object type.
      #
      def self.typename
        return KEYWORD
      end

      #
      # The short name of the object type.
      #
      def self.short_typename
        return KEYWORD_SHORT
      end

      #
      # Set the value with any necessary type conversions.
      #
      def set_value( new_value )
        unless new_value.is_a? DateTime
          self.value = $engine.converter.convert( new_value, 'DateTime', nil )
          return
        end

        self.value = new_value
      end

      # ---------------------------------------------------------------------
      #    Messages
      # ---------------------------------------------------------------------

      #
      # Get a list of message names that this object receives.
      #
      def self.messages
        return super + %w[now]
      end

      #
      # Set to the current date and time.
      #
      def msg_now
        t = DateTime.now.strftime( '%Y.%m.%d %I:%M:%S %P' )
        self.value = t
        $engine.heap.it.set_to t
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gloo-lang-0.9.8 lib/gloo_lang/objs/dt/datetime.rb
gloo-lang-0.9.7 lib/gloo_lang/objs/dt/datetime.rb
gloo-lang-0.9.6 lib/gloo_lang/objs/dt/datetime.rb
gloo-lang-0.9.5 lib/gloo_lang/objs/dt/datetime.rb
gloo-lang-0.9.4 lib/gloo_lang/objs/dt/datetime.rb
gloo-lang-0.9.3 lib/gloo_lang/objs/dt/datetime.rb