Commit 8b921bd

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-03-17 13:56:59
implement DateRange start and end timestamp getters
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent f0eba40
Changed files (2)
health_data_store
lib
src
test
health_data_store/lib/src/types/date_range.dart
@@ -24,4 +24,10 @@ class DateRange with _$DateRange {
   ///
   /// See [DateTime.difference] for more details.
   Duration get duration => end.difference(start);
+
+  /// Gets the [start] timestamp in seconds since epoch.
+  int get startStamp => start.millisecondsSinceEpoch ~/ 1000;
+
+  /// Gets the [end] timestamp in seconds since epoch.
+  int get endStamp => end.millisecondsSinceEpoch ~/ 1000;
 }
health_data_store/test/src/types/date_range_test.dart
@@ -15,4 +15,11 @@ void main() {
     final range = DateRange(start: timeA, end: timeB);
     expect(range.duration, equals(Duration(hours: -21, seconds: -42)));
   });
+  test('should determine start and end time in seconds since epoch', () {
+    final timeA = DateTime.fromMillisecondsSinceEpoch(0);
+    final timeB = timeA.add(Duration(seconds: 283497));
+    final range = DateRange(start: timeA, end: timeB);
+    expect(range.startStamp, 0);
+    expect(range.endStamp, 283497);
+  });
 }