Skip to content

Read a number as YYYYMMDD or YYYYMMDDhhmmss in CAST to DATE and DATETIME to close #2853 - #2988

Open
mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2853-cast-number-date
Open

mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2853-cast-number-date

Conversation

@mateuscmtropical

Copy link
Copy Markdown
Contributor

Closes #2853

CAST(19961121194027 AS DATETIME) and CAST(20200102 AS DATE) threw TypeError: val.substr is not a function. CONVERT had a check for 8 digits in a row, but then called substr on the value, which a number does not have.

In src/59convert.js a number with 8 or 14 digits is now read as its text, so it takes the same path as '20200102'. That path also reads hhmmss when the text has it, as MySQL does for YYYYMMDDhhmmss. A number with another length (a timestamp in milliseconds, for example) now goes to new Date() instead of throwing.

The output keeps the formats alasql already uses for DATE and DATETIME. The two-digit year of DATE is #2804.

test/test2853.js covers 14 and 8 digit numbers, NULLIF around the number as in the MySQL test, CONVERT with style 112, and the text forms. The tests fail on develop and pass with the change. yarn test-only gives 2554 pass. The only failures are the 5 Test 418 cases that load data from the internet, and they fail the same way on develop in my environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CAST of a number to DATETIME or DATE throws a TypeError: CAST(19961121194027 AS DATETIME)

2 participants