forked from invertase/dart_firebase_admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update Timestamp Constructor with nanoseconds (invertase#27)
- Loading branch information
Showing
3 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/dart_firebase_admin/test/google_cloud_firestore/timestamp_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:dart_firebase_admin/firestore.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('Timestamp', () { | ||
test('constructor', () { | ||
final now = DateTime.now().toUtc(); | ||
final seconds = now.millisecondsSinceEpoch ~/ 1000; | ||
final nanoseconds = | ||
(now.microsecondsSinceEpoch - seconds * 1000 * 1000) * 1000; | ||
|
||
expect( | ||
Timestamp(seconds: seconds, nanoseconds: nanoseconds), | ||
Timestamp.fromDate(now), | ||
); | ||
}); | ||
|
||
test('fromDate constructor', () { | ||
final now = DateTime.now().toUtc(); | ||
final timestamp = Timestamp.fromDate(now); | ||
|
||
expect(timestamp.seconds, now.millisecondsSinceEpoch ~/ 1000); | ||
}); | ||
|
||
test('fromMillis constructor', () { | ||
final now = DateTime.now().toUtc(); | ||
final timestamp = Timestamp.fromMillis(now.millisecondsSinceEpoch); | ||
|
||
expect(timestamp.seconds, now.millisecondsSinceEpoch ~/ 1000); | ||
expect( | ||
timestamp.nanoseconds, | ||
(now.millisecondsSinceEpoch % 1000) * (1000 * 1000), | ||
); | ||
}); | ||
|
||
test('fromMicros constructor', () { | ||
final now = DateTime.now().toUtc(); | ||
final timestamp = Timestamp.fromMicros(now.microsecondsSinceEpoch); | ||
|
||
expect(timestamp.seconds, now.microsecondsSinceEpoch ~/ (1000 * 1000)); | ||
expect( | ||
timestamp.nanoseconds, | ||
(now.microsecondsSinceEpoch % (1000 * 1000)) * 1000, | ||
); | ||
}); | ||
}); | ||
} |