[ruby-core:93800] [Ruby master Feature#16005] A variation of Time.iso8601 that can parse yyyy-MM-dd HH:mm:ss
From:
akr@...
Date:
2019-07-16 02:17:54 UTC
List:
ruby-core #93800
Issue #16005 has been updated by akr (Akira Tanaka).
matsuda (Akira Matsuda) wrote:
> > I would be OK with modifying Time.iso8601 to make either T or space a valid date/time separator.
>
> In fact this was my first proposal. I firstly asked @akr about that exact modification on `Time.iso8601`, but he didn't like the idea because that behavior is against ISO 8601 specification.
I said its against XML Schema.
https://www.w3.org/TR/xmlschema-2/
Time[.#]iso8601 is alias of Time[.#]xmlschema.
ISO 8601 defines various representation of date and time.
For example, 1985102T1015Z is valid (10:15 of 102th day of 1985 in UTC).
So, practically, some profile (subset) is required.
XML Schema defines a such profile and it defines that [T] is mandatory.
ISO 8601 itself describes that [T] can be omitted by mutual agreement.
But as far as considering XML Schema as a mutual agreement, we cannot omit [T].
Apart from that, I extracted timestamp related syntax from the SQL 92 standard.
```
<timestamp literal> ::=
TIMESTAMP <timestamp string>
<timestamp string> ::=
<quote> <date value> <space> <time value> [ <time zone interval> ] <quote>
<date value> ::=
<years value> <minus sign> <months value> <minus sign> <days value>
<time value> ::=
<hours value> <colon> <minutes value> <colon> <seconds value>
<time zone interval> ::=
<sign> <hours value> <colon> <minutes value>
<years value> ::= <datetime value>
<months value> ::= <datetime value>
<days value> ::= <datetime value>
<hours value> ::= <datetime value>
<minutes value> ::= <datetime value>
<seconds value> ::=
<seconds integer value> [ <period> [ <seconds fraction> ] ]
<seconds integer value> ::= <unsigned integer>
<seconds fraction> ::= <unsigned integer>
<datetime value> ::= <unsigned integer>
<unsigned integer> ::= <digit>...
<sign> ::= <plus sign> | <minus sign>
<digit> ::=
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<space> ::= !! space character in character set in use
<quote> ::= '
<plus sign> ::= +
<minus sign> ::= -
<period> ::= .
<colon> ::= :
```
I feel it is difficult to consider ISO 8601 variant because
months value, days value, hours value, minutes value and
seconds integer value can be one digit (and 3 or more digits).
Also, I'm still not certain that what Time object to be generated
when time zone interval is not given.
----------------------------------------
Feature #16005: A variation of Time.iso8601 that can parse yyyy-MM-dd HH:mm:ss
https://bugs.ruby-lang.org/issues/16005#change-79666
* Author: matsuda (Akira Matsuda)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Let me propose a String to Time conversion method that can parse "yyyy-MM-dd HH:mm:ss" format, which is very much similar to `Time.iso8601`, but delimits the date part and the time part with a space character.
This format is defined as the "timestamp string" literal in SQL 92 standard: http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt (see P. 90)
and so this format is very widely used as the default datetime / timestamp literal for major existing RDBMS implementations.
Oracle
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Literals.html#GUID-8F4B3F82-8821-4071-84D6-FBBA21C05AC1
SQL Server
https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/date-time-and-timestamp-literals?view=sql-server-2017
PostgreSQL
https://www.postgresql.org/docs/11/datatype-datetime.html#id-1.5.7.13.19.7.2
MySQL
https://dev.mysql.com/doc/refman/8.0/en/datetime.html
SQLite3
https://www.sqlite.org/lang_datefunc.html
In order to handle this conversion in Ruby on Rails framework, we define our own String => Time conversion method
https://github.com/rails/rails/blob/b4c715fe/activemodel/lib/active_model/type/helpers/time_value.rb#L62-L76
and Time => String conversion for now,
https://github.com/rails/rails/blob/b4c715fe/activesupport/lib/active_support/core_ext/time/conversions.rb#L7-L59
and I think it's nicer if we had them in the language level with a faster implementation.
As for the method name, maybe we can name it `Time.sql92`, `Time.sql`, `Time.parse_sql92` or whatever, or maybe we can add an option to `Time.iso8601` if it could be regarded as a variation of `Time.iso8601`? (https://en.wikipedia.org/wiki/ISO_8601#cite_note-30)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>