Sha256: b7a6339518ad011f77781b7c6463407a43b5b2d198b8ef75a0ceb91cfb5d9a04

Contents?: true

Size: 1.32 KB

Versions: 33

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbKit
    class PbDateTime
      attr_accessor :value, :zone

      def initialize(value, zone = "America/New_York")
        @value = convert_to_timestamp_and_zone(value, zone)
      end

      def convert_to_timestamp_and_zone(value, zone)
        converted_time = value.is_a?(String) ? DateTime.parse(value) : value
        converted_time.in_time_zone(zone)
      end

      def convert_to_timestamp
        @value = @value.is_a?(String) ? DateTime.parse(@value) : @value
      end

      def convert_to_timezone(zone = "America/New_York")
        @value = @value.in_time_zone(zone)
      end

      def to_day_of_week
        @value.strftime("%a")
      end

      def to_year
        @value.strftime("%Y")
      end

      def to_month
        @value.strftime("%^b")
      end

      def to_month_downcase
        @value.strftime("%b")
      end

      def to_month_full
        @value.strftime("%B")
      end

      def to_day
        @value.strftime("%e")
      end

      def to_hour
        @value.strftime("%l")
      end

      def to_minutes
        @value.strftime("%M")
      end

      def to_meridian
        @value.strftime("%P")[0, 1]
      end

      def to_timezone
        @value.strftime("%Z")
      end

      def to_iso
        @value.iso8601
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
playbook_ui-4.11.0.pre.alpha3 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.11.0.pre.alpha.pre.2 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.10.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.10.0.pre.alpha1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.9.0.pre.alpha1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.9.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.8.2 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.8.1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.7.1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.7.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.6.1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.6.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.5.2 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.5.1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.5.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.4.1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.4.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.3.1 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.3.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-4.2.0 app/pb_kits/playbook/pb_kit/pb_date_time.rb