@@ -2550,4 +2550,49 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
2550
2550
XCTFail ( " No document retrieved for testSupportsMapMerge " )
2551
2551
}
2552
2552
}
2553
+
2554
+ func testSupportsTimestampConversions( ) async throws {
2555
+ let db = firestore ( )
2556
+ let randomCol = collectionRef ( ) // Unique collection for this test
2557
+
2558
+ // Add a dummy document to ensure the select stage has an input
2559
+ try await randomCol. document ( " dummyTimeDoc " ) . setData ( [ " field " : " value " ] )
2560
+
2561
+ let pipeline = db. pipeline ( )
2562
+ . collection ( randomCol. path)
2563
+ . limit ( 1 )
2564
+ . select (
2565
+ Constant ( 1_741_380_235 ) . unixSecondsToTimestamp ( ) . as ( " unixSecondsToTimestamp " ) ,
2566
+ Constant ( 1_741_380_235_123 ) . unixMillisToTimestamp ( ) . as ( " unixMillisToTimestamp " ) ,
2567
+ Constant ( 1_741_380_235_123_456 ) . unixMicrosToTimestamp ( ) . as ( " unixMicrosToTimestamp " ) ,
2568
+ Constant ( Timestamp ( seconds: 1_741_380_235 , nanoseconds: 123_456_789 ) )
2569
+ . timestampToUnixSeconds ( ) . as ( " timestampToUnixSeconds " ) ,
2570
+ Constant ( Timestamp ( seconds: 1_741_380_235 , nanoseconds: 123_456_789 ) )
2571
+ . timestampToUnixMillis ( ) . as ( " timestampToUnixMillis " ) ,
2572
+ Constant ( Timestamp ( seconds: 1_741_380_235 , nanoseconds: 123_456_789 ) )
2573
+ . timestampToUnixMicros ( ) . as ( " timestampToUnixMicros " )
2574
+ )
2575
+
2576
+ let snapshot = try await pipeline. execute ( )
2577
+ XCTAssertEqual (
2578
+ snapshot. results. count,
2579
+ 1 ,
2580
+ " Should retrieve one document for timestamp conversions "
2581
+ )
2582
+
2583
+ let expectedResults : [ String : Sendable ? ] = [
2584
+ " unixSecondsToTimestamp " : Timestamp ( seconds: 1_741_380_235 , nanoseconds: 0 ) ,
2585
+ " unixMillisToTimestamp " : Timestamp ( seconds: 1_741_380_235 , nanoseconds: 123_000_000 ) ,
2586
+ " unixMicrosToTimestamp " : Timestamp ( seconds: 1_741_380_235 , nanoseconds: 123_456_000 ) ,
2587
+ " timestampToUnixSeconds " : 1_741_380_235 ,
2588
+ " timestampToUnixMillis " : 1_741_380_235_123 ,
2589
+ " timestampToUnixMicros " : 1_741_380_235_123_456 ,
2590
+ ]
2591
+
2592
+ if let resultDoc = snapshot. results. first {
2593
+ TestHelper . compare ( pipelineResult: resultDoc, expected: expectedResults)
2594
+ } else {
2595
+ XCTFail ( " No document retrieved for testSupportsTimestampConversions " )
2596
+ }
2597
+ }
2553
2598
}
0 commit comments