Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/google_cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Updated `Transaction.delete` and `Transaction.update` type constraints to accept `DocumentReference<Object?>`. (thanks to @Levin-Me)
- Made `Timestamp` encodable by adding `toJson` method. (thanks to @OutdatedGuy)

## 0.5.2

Expand Down
14 changes: 14 additions & 0 deletions packages/google_cloud_firestore/lib/src/timestamp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,18 @@ final class Timestamp implements _Serializable {
String toString() {
return 'Timestamp(seconds=$seconds, nanoseconds=$nanoseconds)';
}

/// Converts this Timestamp to a JSON representation.
///
/// Returns a Map\<String, int\> containing the seconds and nanoseconds.
///
/// Example:
/// ```dart
/// final timestamp = Timestamp(seconds: 1234567890, nanoseconds: 123456789);
/// final json = timestamp.toJson();
/// print(json); // {'_seconds': 1234567890, '_nanoseconds': 123456789}
/// ```
Map<String, int> toJson() {
return {'_seconds': seconds, '_nanoseconds': nanoseconds};
}
Comment thread
demolaf marked this conversation as resolved.
}
6 changes: 6 additions & 0 deletions packages/google_cloud_firestore/test/timestamp_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,11 @@ void main() {
final timestamp = Timestamp.fromMillis(millis);
expect(timestamp.toMillis(), millis);
});

test('toJson() returns correct JSON representation', () {
final timestamp = Timestamp(seconds: 1234567890, nanoseconds: 123456789);
final json = timestamp.toJson();
expect(json, {'_seconds': 1234567890, '_nanoseconds': 123456789});
});
Comment thread
demolaf marked this conversation as resolved.
});
}
Loading