File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2024 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import Foundation
16
+
17
+ /// An expression that represents a server-side timestamp.
18
+ ///
19
+ /// `CurrentTimestamp` is used to generate a timestamp on the server.
20
+ /// This is useful for recording current date and time.
21
+ ///
22
+ /// Example:
23
+ /// ```swift
24
+ /// CurrentTimestamp().as("createdAt")
25
+ /// ```
26
+ public class CurrentTimestamp : FunctionExpression , @unchecked Sendable {
27
+ public init ( ) {
28
+ super. init ( " current_timestamp " , [ ] )
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -3157,6 +3157,21 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
3157
3157
}
3158
3158
}
3159
3159
3160
+ func testCurrentTimestampWorks( ) async throws {
3161
+ let collRef = collectionRef ( withDocuments: [ " doc1 " : [ " foo " : 1 ] ] )
3162
+ let db = collRef. firestore
3163
+
3164
+ let pipeline = db. pipeline ( )
3165
+ . collection ( collRef. path)
3166
+ . select ( [
3167
+ CurrentTimestamp ( ) . as ( " timestamp " ) ,
3168
+ ] )
3169
+
3170
+ let snapshot = try await pipeline. execute ( )
3171
+
3172
+ XCTAssertEqual ( snapshot. results. count, 1 )
3173
+ }
3174
+
3160
3175
func testSupportsByteLength( ) async throws {
3161
3176
let db = firestore ( )
3162
3177
let randomCol = collectionRef ( )
You can’t perform that action at this time.
0 commit comments