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_day_of_week_compact ⇒ Object
- #to_full_hour ⇒ 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_month_number ⇒ Object
- #to_timezone ⇒ Object
- #to_unpadded_day ⇒ Object
- #to_unpadded_month_number ⇒ 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
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_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_day_of_week_compact ⇒ Object
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_hour ⇒ Object
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_hour ⇒ Object
66 67 68 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 66 def to_hour @value.strftime("%l") end |
#to_iso ⇒ Object
86 87 88 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 86 def to_iso @value.iso8601 end |
#to_meridian ⇒ Object
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_minutes ⇒ Object
74 75 76 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 74 def to_minutes @value.strftime("%M") end |
#to_month ⇒ Object
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_downcase ⇒ Object
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_full ⇒ Object
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_number ⇒ Object
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_timezone ⇒ Object
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_day ⇒ Object
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_number ⇒ Object
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_year ⇒ Object
34 35 36 |
# File 'app/pb_kits/playbook/pb_kit/pb_date_time.rb', line 34 def to_year @value.strftime("%Y") end |