Class: Playbook::PbKit::PbDateTime
- Inherits:
-
Object
- Object
- Playbook::PbKit::PbDateTime
- Defined in:
- app/pb_kits/playbook/pb_kit/pb_date_time.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
-
#zone ⇒ Object
Returns the value of attribute zone.
Instance Method Summary collapse
- #convert_to_timestamp ⇒ Object
- #convert_to_timestamp_and_zone(value, zone) ⇒ Object
- #convert_to_timezone(zone = "America/New_York") ⇒ Object
-
#initialize(value, zone = "America/New_York") ⇒ PbDateTime
constructor
A new instance of PbDateTime.
- #to_day ⇒ Object
- #to_day_of_week ⇒ Object
- #to_hour ⇒ Object
- #to_iso ⇒ Object
- #to_meridian ⇒ Object
- #to_minutes ⇒ Object
- #to_month ⇒ Object
- #to_month_downcase ⇒ Object
- #to_month_full ⇒ Object
- #to_timezone ⇒ Object
- #to_year ⇒ Object
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 = (value, zone) end |
Instance Attribute Details
#value ⇒ Object
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 |
#zone ⇒ Object
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_timestamp ⇒ Object
17 18 19 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 17 def @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 (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_day ⇒ Object
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_week ⇒ Object
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_hour ⇒ Object
49 50 51 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 49 def to_hour @value.strftime("%l") end |
#to_iso ⇒ Object
65 66 67 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 65 def to_iso @value.iso8601 end |
#to_meridian ⇒ Object
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_minutes ⇒ Object
53 54 55 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 53 def to_minutes @value.strftime("%M") end |
#to_month ⇒ Object
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_downcase ⇒ Object
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_full ⇒ Object
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_timezone ⇒ Object
61 62 63 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 61 def to_timezone @value.strftime("%Z") end |
#to_year ⇒ Object
29 30 31 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 29 def to_year @value.strftime("%Y") end |