Sha256: efa931c5c41628a09612b7a0814b3ec5847b7ba626954c84940ce531a1731a33

Contents?: true

Size: 416 Bytes

Versions: 4

Compression:

Stored size: 416 Bytes

Contents

module ICU
  class Util
    # Parse dates into yyyy-mm-dd format, preferring European format. Return nil on error.
    def self.parsedate(date)
      date = date.to_s
      return nil unless date.match(/[1-9]/)
      date.sub!(/^([1-9]|0[1-9]|[12][0-9]|3[01])([^\d])([1-9]|0[1-9]|1[0-2])([^\d])/, '\3\2\1\4')
      begin
        Date.parse(date, true).to_s
      rescue
        return nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sanichi-chess_icu-0.1.0 lib/util.rb
sanichi-chess_icu-0.2.0 lib/util.rb
sanichi-chess_icu-0.2.1 lib/util.rb
sanichi-chess_icu-0.2.4 lib/util.rb