Class: Playbook::PbKit::PbDateTime

Inherits:
Object
  • Object
show all
Defined in:
app/pb_kits/playbook/pb_kit/pb_date_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, zone = "America/New_York") ⇒ PbDateTime

Returns a new instance of PbDateTime.



8
9
10
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 8

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

Instance Attribute Details

#valueObject

Returns the value of attribute value.



6
7
8
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 6

def value
  @value
end

#zoneObject

Returns the value of attribute zone.



6
7
8
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 6

def zone
  @zone
end

Instance Method Details

#convert_to_timestampObject



17
18
19
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 17

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

#convert_to_timestamp_and_zone(value, zone) ⇒ Object



12
13
14
15
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 12

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

#convert_to_timezone(zone = "America/New_York") ⇒ Object



21
22
23
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 21

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

#to_dayObject



58
59
60
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 58

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

#to_day_of_weekObject



25
26
27
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 25

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

#to_day_of_week_compactObject



29
30
31
32
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 29

def to_day_of_week_compact
  abbr_days = %w[SU M T W TH F S]
  abbr_days[@value.strftime("%w").to_i]
end

#to_full_hourObject



70
71
72
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 70

def to_full_hour
  @value.strftime("%I")
end

#to_hourObject



66
67
68
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 66

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

#to_isoObject



86
87
88
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 86

def to_iso
  @value.iso8601
end

#to_meridianObject



78
79
80
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 78

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

#to_minutesObject



74
75
76
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 74

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

#to_monthObject



38
39
40
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 38

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

#to_month_downcaseObject



50
51
52
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 50

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

#to_month_fullObject



54
55
56
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 54

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

#to_month_numberObject



42
43
44
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 42

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

#to_timezoneObject



82
83
84
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 82

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

#to_unpadded_dayObject



62
63
64
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 62

def to_unpadded_day
  @value.strftime("%-d")
end

#to_unpadded_month_numberObject



46
47
48
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 46

def to_unpadded_month_number
  @value.strftime("%-m")
end

#to_yearObject



34
35
36
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 34

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