Project

General

Profile

Actions

Feature #18033

closed

Time.new to parse a string

Added by nobu (Nobuyoshi Nakada) over 3 years ago. Updated about 1 month ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:104552]

Description

Make Time.new parse Time#inspect and ISO-8601 like strings.

  • Time.iso8601 and Time.parse need an extension library, date.

  • Time.iso8601 can't parse Time#inspect string.

  • Time.parse often results in unintentional/surprising results.

  • Time.new also about 1.9 times faster than Time.iso8601.

    $ ./ruby -rtime -rbenchmark -e '
    n = 1000
    s = Time.now.iso8601
    Benchmark.bm(12) do |x|
      x.report("Time.iso8601") {n.times{Time.iso8601(s)}}
      x.report("Time.parse") {n.times{Time.parse(s)}}
      x.report("Time.new") {n.times{Time.new(s)}}
    end'
                       user     system      total        real
    Time.iso8601   0.006919   0.000185   0.007104 (  0.007091)
    Time.parse     0.018338   0.000207   0.018545 (  0.018590)
    Time.new       0.003671   0.000069   0.003740 (  0.003741)
    

https://github.com/ruby/ruby/pull/4825


Related issues 6 (2 open4 closed)

Related to Ruby master - Feature #16005: A variation of Time.iso8601 that can parse yyyy-MM-dd HH:mm:ssOpenActions
Related to Ruby master - Feature #18331: Kernel.#TimeOpenActions
Related to Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thisClosedActions
Related to Ruby master - Bug #20797: UTC offset seconds part is not checkedClosedActions
Related to Ruby master - Bug #17504: Allow UTC offset without colons per ISO-8601ClosedActions
Related to Ruby master - Bug #19296: Time.new's argument check is incompleteClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0