Sha256: a81ae9ff62ed790ba34f6a26ce061bd183ac4f6476562b148b88b1f51a46f69f

Contents?: true

Size: 1.45 KB

Versions: 27

Compression:

Stored size: 1.45 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# A Time object (does not include a date).
#

module Gloo
  module Objs
    class Time < Gloo::Core::Obj

      KEYWORD = 'time'.freeze
      KEYWORD_SHORT = 'time'.freeze
      DEFAULT_FORMAT = '%I:%M:%S %P'.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 )
        if DtTools.is_dt_type? new_value
          self.value = new_value
        else
          self.value = @engine.converter.convert( new_value, 'Time', nil )
        end

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

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

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

      #
      # Set to the current time.
      #
      def msg_now
        self.set_value( DateTime.now )
        @engine.heap.it.set_to self.value
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
gloo-3.9.1 lib/gloo/objs/dt/time.rb
gloo-3.9.0 lib/gloo/objs/dt/time.rb
gloo-3.8.0 lib/gloo/objs/dt/time.rb
gloo-3.7.0 lib/gloo/objs/dt/time.rb
gloo-3.6.2 lib/gloo/objs/dt/time.rb
gloo-3.6.1 lib/gloo/objs/dt/time.rb
gloo-3.6.0 lib/gloo/objs/dt/time.rb
gloo-3.5.0 lib/gloo/objs/dt/time.rb
gloo-3.4.1 lib/gloo/objs/dt/time.rb
gloo-3.4.0 lib/gloo/objs/dt/time.rb
gloo-3.3.0 lib/gloo/objs/dt/time.rb
gloo-3.2.0 lib/gloo/objs/dt/time.rb
gloo-3.1.1 lib/gloo/objs/dt/time.rb
gloo-3.1.0 lib/gloo/objs/dt/time.rb
gloo-3.0.1 lib/gloo/objs/dt/time.rb
gloo-3.0.0 lib/gloo/objs/dt/time.rb
gloo-2.5.0 lib/gloo/objs/dt/time.rb
gloo-2.4.3 lib/gloo/objs/dt/time.rb
gloo-2.4.2 lib/gloo/objs/dt/time.rb
gloo-2.4.1 lib/gloo/objs/dt/time.rb