Skip to content
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

Panic while reading datetime field with date < 1900 #316

Open
squareduck opened this issue Oct 11, 2023 · 1 comment
Open

Panic while reading datetime field with date < 1900 #316

squareduck opened this issue Oct 11, 2023 · 1 comment

Comments

@squareduck
Copy link

squareduck commented Oct 11, 2023

I have a database with DateTime field like this 1899-12-30 00:00:00.000.

Trying to read this field with time feature results in panic - attempting to multiply with overflow:

        // Here `self` is tiberius::Row
        let value = self.try_get::<time::PrimitiveDateTime, _>(name);

Results in:

thread '<unnamed>' panicked at 'attempt to multiply with overflow', /Users/squareduck/.config/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/tds/time/time.rs:15:31

In SQL Server docs it's said that DateTime supports dates from year 1753, and only for Date type the lower bound is 1900:
https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetime-transact-sql?view=sql-server-ver16

So to me it looks like the culprit is this starting year value:

from_days(dt.days as u64, 1900),

@janpio
Copy link
Member

janpio commented Nov 20, 2023

That is very possible. Do you have a suggestion on how to fix it and might be able to submit a PR with tests?

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

No branches or pull requests

2 participants