Class: Tomlrb::LocalDate

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tomlrb/local_date.rb

Instance Method Summary collapse

Constructor Details

#initialize(year, month, day) ⇒ LocalDate

Returns a new instance of LocalDate.

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/tomlrb/local_date.rb', line 11

def initialize(year, month, day)
  @time = Time.utc(year, month, day, 0, 0, 0)
  raise ArgumentError, "Invalid Local Date: #{year}-#{month}-#{day}" unless day.to_i == @time.day && month.to_i == @time.month && year.to_i == @time.year
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
# File 'lib/tomlrb/local_date.rb', line 27

def ==(other)
  other.is_a?(self.class) &&
    to_time == other.to_time
end

#inspectObject



32
33
34
# File 'lib/tomlrb/local_date.rb', line 32

def inspect
  "#<#{self.class}: #{self}>"
end

#to_sObject



23
24
25
# File 'lib/tomlrb/local_date.rb', line 23

def to_s
  @time.strftime('%F')
end

#to_time(offset = '-00:00') ⇒ Time

Returns 00:00:00 of the date.

Parameters:

Returns:

  • (Time)

    00:00:00 of the date



18
19
20
21
# File 'lib/tomlrb/local_date.rb', line 18

def to_time(offset = '-00:00')
  return @time if offset == '-00:00'
  Time.new(year, month, day, 0, 0, 0, offset)
end