Class: DateTimeWithZone::DateTime
- Inherits:
-
Object
- Object
- DateTimeWithZone::DateTime
- Defined in:
- lib/date_time_with_zone/date_time.rb
Constant Summary collapse
- DATE_FORMATTER =
"%Y-%m-%d"
- TIME_FORMATTER =
"%I:%M %p"
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#time ⇒ Object
Returns the value of attribute time.
-
#zone ⇒ Object
Returns the value of attribute zone.
Instance Method Summary collapse
-
#initialize(*args) ⇒ DateTime
constructor
A new instance of DateTime.
- #to_datetime ⇒ Object
Constructor Details
#initialize(*args) ⇒ DateTime
Returns a new instance of DateTime.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/date_time_with_zone/date_time.rb', line 8 def initialize(*args) time_or_hash = args.shift case time_or_hash when Hash initialize_with_hash(time_or_hash) when Time with_timezone = args.pop initialize_with_time(time_or_hash, with_timezone) else raise ArgumentError, "only accepts a Hash or Time object, got #{time_or_hash}" end end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
25 26 27 |
# File 'lib/date_time_with_zone/date_time.rb', line 25 def date @date end |
#time ⇒ Object
Returns the value of attribute time.
25 26 27 |
# File 'lib/date_time_with_zone/date_time.rb', line 25 def time @time end |
#zone ⇒ Object
Returns the value of attribute zone.
25 26 27 |
# File 'lib/date_time_with_zone/date_time.rb', line 25 def zone @zone end |
Instance Method Details
#to_datetime ⇒ Object
21 22 23 |
# File 'lib/date_time_with_zone/date_time.rb', line 21 def to_datetime Time.use_zone(@zone) { Time.zone.parse [@date, @time].join(" ") } end |