Skip to content

Commit

Permalink
allow converting from DateTime2 to Datetimen in 'tds73'
Browse files Browse the repository at this point in the history
  • Loading branch information
Geo W committed Jun 2, 2023
1 parent 98943b2 commit 3be0444
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/tds/codec/column_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,20 @@ impl<'a> Encode<BytesMutWithTypeInfo<'a>> for ColumnData<'a> {
time.encode(&mut *dst)?;
}
#[cfg(feature = "tds73")]
(ColumnData::DateTime2(opt), Some(TypeInfo::VarLenSized(vlc)))
if vlc.r#type() == VarLenType::Datetimen =>
{
if let Some(dt2) = opt {
dst.put_u8(8);
let days = dt2.date().days() - 693595; // minus days gap between year 1 and year 1900;
let seconds_fragments = dt2.time().increments() * 100 * 300 / 1e9 as u64; // degrade second's precision
dst.put_u32_le(days as u32);
dst.put_u32_le(seconds_fragments as u32);
} else {
dst.put_u8(0);
}
}
#[cfg(feature = "tds73")]
(ColumnData::DateTime2(opt), Some(TypeInfo::VarLenSized(vlc)))
if vlc.r#type() == VarLenType::Datetime2 =>
{
Expand Down

0 comments on commit 3be0444

Please sign in to comment.