Class: AIXM::Schedule::DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/aixm/schedule/date_time.rb

Overview

Datetimes suitable for schedules

This class combines AIXM::Schedule::Date and AIXM::Schedule::Time:

Examples:

datetime = AIXM.datetime('2022-04-20', '20:00')   # => 2022-04-20 20:00
datetime.date         # => 2022-04-20
datetime.date.class   # => AIXM::Schedule::Date
datetime.time         # => 20:00
datetime.time.class   # => AIXM::Schedule::Time

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, time) ⇒ DateTime

Parse the given representation of date and time.

Parameters:



32
33
34
35
36
# File 'lib/aixm/schedule/date_time.rb', line 32

def initialize(date, time)
  fail(ArgumentError, 'invalid date') unless date.instance_of? AIXM::Schedule::Date
  fail(ArgumentError, 'invalid time') unless time.instance_of? AIXM::Schedule::Time
  @date, @time = date, time
end

Instance Attribute Details

#dateAIXM::Schedule::Date (readonly)

Date part



21
22
23
# File 'lib/aixm/schedule/date_time.rb', line 21

def date
  @date
end

#timeAIXM::Schedule::Time (readonly)

Time part



26
27
28
# File 'lib/aixm/schedule/date_time.rb', line 26

def time
  @time
end

Instance Method Details

#hashObject

See Also:

  • Object#hash


50
51
52
# File 'lib/aixm/schedule/date_time.rb', line 50

def hash
   [@date.hash, @time.hash].hash
end

#inspectObject



45
46
47
# File 'lib/aixm/schedule/date_time.rb', line 45

def inspect
  %Q(#<#{self.class} #{to_s}>)
end

#to_sString

Human readable representation such as “2002-05-19 20:00”

Returns:

  • (String)


41
42
43
# File 'lib/aixm/schedule/date_time.rb', line 41

def to_s
  [@date.to_s, @time.to_s].join(' ')
end