mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 12:35:08 +00:00
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:
parent
1205d39fc3
commit
cd0e07f6a4
3 changed files with 44 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue