Sha256: 21b908fd720a2a5bcaba2dcd1840b951df9603b1bc6746217ffd0aade05789f2

Contents?: true

Size: 1.72 KB

Versions: 1359

Compression:

Stored size: 1.72 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_day_of_week_compact
        abbr_days = %w[SU M T W TH F S]
        abbr_days[@value.strftime("%w").to_i]
      end

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

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

      def to_month_number
        @value.strftime("%m")
      end

      def to_unpadded_month_number
        @value.strftime("%-m")
      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_unpadded_day
        @value.strftime("%-d")
      end

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

      def to_full_hour
        @value.strftime("%I")
      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

1,359 entries across 1,359 versions & 1 rubygems

Version Path
playbook_ui-14.11.1.pre.alpha.PLAY17445539 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR798datepickerturbo5537 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.pbntr703collapsiblerowsrails5536 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PLAY1751pbcontenttagpt25529 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR7495495 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.11 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.10 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.9 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.8 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.7 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.play1724darkmodeauditmap5437 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR719listdraggablesimple5432 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR768stickyrightcolumn5431 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.6 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR718simiplifieddraggablereact5415 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.play1724darkmodeauditmap5413 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.12.0.pre.rc.5 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.play1724darkmodeauditmap5409 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR718simiplifieddraggablereact5400 app/pb_kits/playbook/pb_kit/pb_date_time.rb
playbook_ui-14.11.1.pre.alpha.PBNTR718simiplifieddraggablereact5392 app/pb_kits/playbook/pb_kit/pb_date_time.rb