Class: DateTimeWithZone::DateTime

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dateObject

Returns the value of attribute date.



25
26
27
# File 'lib/date_time_with_zone/date_time.rb', line 25

def date
  @date
end

#timeObject

Returns the value of attribute time.



25
26
27
# File 'lib/date_time_with_zone/date_time.rb', line 25

def time
  @time
end

#zoneObject

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_datetimeObject



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