Module: Pubid::Rendering::Date

Included in:
Base
Defined in:
lib/pubid/rendering/date.rb

Instance Method Summary collapse

Instance Method Details

#render_date(date, **options) ⇒ String

Render date with optional month/day

Parameters:

  • date (Components::Date)

    date component

  • options (Hash)

    rendering options

Returns:

  • (String)

    formatted date string



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pubid/rendering/date.rb', line 10

def render_date(date, **options)
  return "" unless date&.year

  result = ":#{date.year}"

  if date.month && options[:include_month]
    result += "-#{format('%02d', date.month)}"
  end

  if date.day && options[:include_day]
    result += "-#{format('%02d', date.day)}"
  end

  result
end