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



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

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_hourObject



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

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

#to_isoObject



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

def to_iso
  @value.iso8601
end

#to_meridianObject



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

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

#to_minutesObject



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

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

#to_monthObject



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

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

#to_month_downcaseObject



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

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

#to_month_fullObject



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

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

#to_timezoneObject



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

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

#to_yearObject



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

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