Sha256: 381f647f82e97eba9ddec2ec0ddb15d8f1127c3992a407234d1c4aa6ca9b764d

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'date'
require 'domainic/type/behavior'
require 'domainic/type/behavior/date_time_behavior'

module Domainic
  module Type
    # A type for validating DateTime objects
    #
    # This type ensures the value is a `DateTime` object and supports comprehensive
    # date-time validation through `DateTimeBehavior`. It is ideal for scenarios requiring
    # precise date-time constraints.
    #
    # Key features:
    # - Ensures the value is a `DateTime` object
    # - Supports chronological relationship validation (e.g., before, after)
    # - Provides range and equality checks
    #
    # @example Basic usage
    #   type = DateTimeType.new
    #   type.validate(DateTime.now)            # => true
    #   type.validate(Date.today)              # => false
    #
    # @example Range validation
    #   type = DateTimeType.new
    #     .being_between(DateTime.new(2024, 1, 1, 0, 0, 0), DateTime.new(2024, 12, 31, 23, 59, 59))
    #   type.validate(DateTime.new(2024, 6, 15, 12, 0, 0))  # => true
    #
    # @author {https://aaronmallen.me Aaron Allen}
    # @since 0.1.0
    class DateTimeType
      # @rbs! extend Behavior::ClassMethods

      include Behavior
      include Behavior::DateTimeBehavior

      intrinsically_constrain :self, :type, DateTime, abort_on_failure: true, description: :not_described
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
domainic-type-0.1.0.alpha.3.4.1 lib/domainic/type/types/datetime/date_time_type.rb
domainic-type-0.1.0.alpha.3.4.0 lib/domainic/type/types/datetime/date_time_type.rb
domainic-type-0.1.0.alpha.3.3.0 lib/domainic/type/types/datetime/date_time_type.rb
domainic-type-0.1.0.alpha.3.2.0 lib/domainic/type/types/datetime/date_time_type.rb