diff --git a/drift/test/database/expressions/datetime_expression_test.dart b/drift/test/database/expressions/datetime_expression_test.dart index 45a101d0..68cc01e0 100644 --- a/drift/test/database/expressions/datetime_expression_test.dart +++ b/drift/test/database/expressions/datetime_expression_test.dart @@ -72,10 +72,18 @@ void main() { if (useText) { expect( expr, - generatesWithOptions( - "datetime(datetime(CURRENT_TIMESTAMP, '259200.0 seconds'), " - "'-5.0 seconds')", - options: options, + anyOf( + generatesWithOptions( + "datetime(datetime(CURRENT_TIMESTAMP, '259200.0 seconds'), " + "'-5.0 seconds')", + options: options, + ), + // emits a whole number on the web which is fine too + generatesWithOptions( + "datetime(datetime(CURRENT_TIMESTAMP, '259200 seconds'), " + "'-5 seconds')", + options: options, + ), ), ); } else { diff --git a/drift/test/database/expressions/expressions_integration_test.dart b/drift/test/database/expressions/expressions_integration_test.dart index 7da7bc4d..7e6364bb 100644 --- a/drift/test/database/expressions/expressions_integration_test.dart +++ b/drift/test/database/expressions/expressions_integration_test.dart @@ -85,7 +85,8 @@ void _testWith(TodoDb Function() openDb, {bool dateTimeAsText = false}) { completion('2020-09-06')); expect(eval(expr.time), completion('23:55:00')); expect(eval(expr.datetime), completion('2020-09-03 23:55:00')); - expect(eval(expr.julianday), completion(2459096.496527778)); + expect( + eval(expr.julianday), completion(closeTo(2459096.496527778, 0.0001))); expect(eval(expr.unixepoch), completion(1599177300)); expect(eval(expr.strftime('%Y-%m-%d %H:%M:%S')), completion('2020-09-03 23:55:00')); @@ -143,8 +144,12 @@ void _testWith(TodoDb Function() openDb, {bool dateTimeAsText = false}) { eval(expr.modify(DateTimeModifier.weekday(DateTime.saturday))), completion(result(DateTime.utc(2022, 07, 09))), ); + }); + + if (!dateTimeAsText) { + test('modifiers utc/local', () { + final expr = Variable.withDateTime(DateTime.utc(2022, 07, 05)); - if (!dateTimeAsText) { // drift interprets date time values as timestamps, so going to UTC // means subtracting the UTC offset in SQL. Interpreting that timestamp // in dart will effectively add it back, so we have the same value bit @@ -157,8 +162,10 @@ void _testWith(TodoDb Function() openDb, {bool dateTimeAsText = false}) { eval(Variable.withDateTime(DateTime(2022, 07, 05)) .modify(const DateTimeModifier.localTime())), completion(DateTime.utc(2022, 07, 05).toLocal())); - } - }); + }, onPlatform: const { + 'browser': Skip('TODO: UTC offsets are unknown in WebAssembly module') + }); + } test('aggregates', () async { final firstTime = DateTime(2021, 5, 7); diff --git a/drift/test/database/types/datetime_test.dart b/drift/test/database/types/datetime_test.dart index 9ccbdaf8..4adf9e4f 100644 --- a/drift/test/database/types/datetime_test.dart +++ b/drift/test/database/types/datetime_test.dart @@ -84,9 +84,15 @@ void main() { generatesWithOptions("'2022-07-21T22:53:12.888999Z'", options: options), ); + }, onPlatform: const { + 'browser': Skip('Assumes DateTimes using int64 timestamps'), + }); + test('as text throws if UTC offset is not in minutes', () { // Writing date times with an UTC offset that isn't a whole minute // is not supported and should throw. + const options = DriftDatabaseOptions(storeDateTimeAsText: true); + expect(() { final context = stubContext(options: options); Variable(_MockDateTime(local, const Duration(seconds: 30)))