66
77use Cel \Runtime \Exception \TypeConversionException ;
88use Cel \Runtime \Function \FunctionInterface ;
9+ use Cel \Runtime \Value \FloatValue ;
10+ use Cel \Runtime \Value \IntegerValue ;
911use Cel \Runtime \Value \StringValue ;
1012use Cel \Runtime \Value \TimestampValue ;
1113use Cel \Runtime \Value \Value ;
1214use Cel \Runtime \Value \ValueKind ;
1315use Cel \Syntax \Member \CallExpression ;
1416use Override ;
17+ use Psl \DateTime ;
1518use Psl \DateTime \Exception \RuntimeException ;
1619use Psl \DateTime \FormatPattern ;
1720use Psl \DateTime \Timestamp ;
@@ -38,6 +41,23 @@ public function isIdempotent(): bool
3841 #[Override]
3942 public function getOverloads (): iterable
4043 {
44+ yield [ValueKind::Integer] => static function (CallExpression $ expr , array $ arguments ): TimestampValue {
45+ /** @var IntegerValue $seconds */
46+ $ seconds = $ arguments [0 ];
47+
48+ return new TimestampValue (Timestamp::fromParts ($ seconds ->value ));
49+ };
50+
51+ yield [ValueKind::Float] => static function (CallExpression $ expr , array $ arguments ): TimestampValue {
52+ /** @var FloatValue $seconds */
53+ $ seconds = $ arguments [0 ];
54+
55+ $ wholeSeconds = (int ) $ seconds ->value ;
56+ $ nanoseconds = (int ) (($ seconds ->value - $ wholeSeconds ) * DateTime \NANOSECONDS_PER_SECOND );
57+
58+ return new TimestampValue (Timestamp::fromParts ($ wholeSeconds , $ nanoseconds ));
59+ };
60+
4161 yield [ValueKind::String] =>
4262 /**
4363 * @param CallExpression $call The call expression representing the function call.
0 commit comments