LibSQL: Add a helper to convert a SQL::Value to a UnixDateTime

Support for constructing a Value from a UnixDateTime was added in commit
effcd080ca.

That constructor just stores the value as the number of milliseconds
since epoch. There's no way for outside users to know this, so this adds
a helper to retrieve the value as a UnixDateTime and let SQL::Value be
the source of truth for how the value is encoded/decoded.
This commit is contained in:
Timothy Flynn 2024-01-09 20:45:04 -05:00 committed by Andreas Kling
commit cd0e07f6a4
Notes: sideshowbarker 2024-07-16 17:05:37 +09:00
3 changed files with 44 additions and 0 deletions

View file

@ -277,6 +277,15 @@ Optional<bool> Value::to_bool() const
});
}
Optional<UnixDateTime> Value::to_unix_date_time() const
{
auto time = to_int<i64>();
if (!time.has_value())
return {};
return UnixDateTime::from_milliseconds_since_epoch(*time);
}
Optional<Vector<Value>> Value::to_vector() const
{
if (is_null() || (type() != SQLType::Tuple))