Skip to content

Instantly share code, notes, and snippets.

@gouf
Created Aug 16, 2019
Embed
What would you like to do?
Paiza レベルアップ問題集: 「日付のフォーマット Ruby編」 - https://paiza.jp/works/mondai/dateset/ruby/date_format
class DateFormat
DATE_ORDER = %r{[0-9]{4}/[0-9]{2}/[0-9]{2}}.freeze
MONTH = [*(1..12).map { |n| n.to_s.rjust(2, '0') }].freeze
DAY = [*(1..31).map { |n| n.to_s.rjust(2, '0') }].freeze
class << self
def validate(date_string)
return 'No' unless date_string.match?(DATE_ORDER)
_year, month, day = date_string.split('/')
return 'No' unless MONTH.include?(month)
return 'No' unless DAY.include?(day)
'Yes'
end
end
end
puts DateFormat.validate(gets.chomp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment