Skip to content

fix(cast-format): Throw exception when value cannot be found for specific pattern in string to datetime conversion #8501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TreeHunter9
Copy link
Contributor

  • Example: CAST('A.M. 8' as time format 'MI A.M. HH12') where value for MI pattern is missing;
  • Handle integer overflow when converting string to int by using std::from_chars;
  • Add tests for missing values and integer overflow;

Artyom Ivanov added 2 commits April 3, 2025 15:05
…ific pattern in string to datetime conversion

- Example: CAST('A.M. 8' as time format 'MI A.M. HH12') where value for MI pattern is missing;
- Handle integer overflow when converting string to int;
@dyemanov
Copy link
Member

dyemanov commented Apr 7, 2025

Looks like CvtTest.cpp fails on Alpine and Windows 2019, while works OK on other platforms. Could you please take a look? And please also resolve the conflicts.

@TreeHunter9
Copy link
Contributor Author

TreeHunter9 commented Apr 7, 2025

As I can see, all tests where we need to parse number are failing, but tests where we parse strings are fine. I guess the problem is std::from_chars, maybe I'm handling its result incorrectly somehow and it cause UB in some compilers, I'll look into it.

@dyemanov dyemanov merged commit 90e0f49 into FirebirdSQL:master Apr 11, 2025
23 of 24 checks passed
@pavel-zotov
Copy link

i have misunderstanding about these examples from src/common/tests/CvtTest.cpp

        testExceptionCvtStringToFormatDateTime("00:60", "TZR", cb);
	testExceptionCvtStringToFormatDateTime("15:00", "TZH:TZM", cb);
	testExceptionCvtStringToFormatDateTime("15:00", "TZR", cb);
	testExceptionCvtStringToFormatDateTime("-15:00", "TZH:TZM", cb);
	testExceptionCvtStringToFormatDateTime("-15:00", "TZR", cb);

What kind of datatype and which string of FORMAT must be used for them ?
I have tried these:

select cast('00:60' as time with time zone format 'TZR') from rdb$database
select cast('15:00' as time format 'TZH:TZM') from rdb$database

-- but got the same error messages in 6.0.0.726 (intermediate snapshot from "Actions") and 6.0.0.725:
Value for TZR pattern is out of range [0, 59]
and
Cannot use "TZH" format with current date type

@TreeHunter9
Copy link
Contributor Author

What kind of datatype and which string of FORMAT must be used for them ?

These tests only check that there will be an exception if the input time zone offset is out of range, except for the first one, it only checks bounds for minutes value. These formats can be used for any `... with time zone' types.

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

Successfully merging this pull request may close these issues.

3 participants