Conversation
| timestampDiff( | ||
| start: string | Expression, | ||
| unit: 'microsecond' | 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | ||
| ): FunctionExpression; | ||
| timestampDiff( | ||
| start: string | Expression, | ||
| unit: | ||
| | 'microsecond' | ||
| | 'millisecond' | ||
| | 'second' | ||
| | 'minute' | ||
| | 'hour' | ||
| | 'day' | ||
| | Expression | ||
| ): FunctionExpression { | ||
| return new FunctionExpression( | ||
| 'timestamp_diff', | ||
| [this, fieldOrExpression(start), valueToDefaultExpr(unit)], | ||
| ); | ||
| } |
There was a problem hiding this comment.
Can we move the union string union values into a type?
There was a problem hiding this comment.
Since existing timestampAdd and timestampSub expressions use the same unit value, will do refactoring in a separate PR after this one.
| /** | ||
| * @beta | ||
| * Creates an expression that extracts a specified part from this timestamp expression. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Extract the year from the 'createdAt' field. | ||
| * field('createdAt').timestampExtract('year') | ||
| * ``` | ||
| * | ||
| * @param part - The part to extract from the timestamp (e.g., "year", "month", "day"). | ||
| * @param timezone - The timezone to use for extraction. Valid values are from | ||
| * the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1." | ||
| * @returns A new `Expression` representing the extracted part as an integer. | ||
| */ | ||
| timestampExtract( | ||
| part: firestore.Pipelines.TimePart, | ||
| timezone?: string | Expression | ||
| ): FunctionExpression; |
There was a problem hiding this comment.
I think we should add documentation explaining how this expression behaves when timestamp is not passed.
There was a problem hiding this comment.
Add "Defaults to "UTC" if not specified." in the timezone parameter discription
| part: firestore.Pipelines.TimePart | Expression, | ||
| timezone?: string | Expression | ||
| ): FunctionExpression { | ||
| const internalPart = isString(part) ? part.toLowerCase() : part; |
There was a problem hiding this comment.
Can we remove this line, since TimePart should already be lower case?
There was a problem hiding this comment.
TimePart includes all the values from TimeGranularity and at this moment TimeGranularity still have value that's not lower case like isoWeek, which I plan to fix when refactoring the unit variables as mentioned above. We can remove it after I change all the values to lower case?
Add new timestamp expressions timestamp_diff and timestamp_extract and integration tests for the expressions
The expression timestamp_trunc was already ported in the repo with integration tests. Amend the example usage documentation for standalone methods.
Ported from firebase/firebase-js-sdk#9728