Skip some broken datetime tests on the web

This commit is contained in:
Simon Binder 2022-08-08 13:59:37 +02:00
parent 5063afb8a4
commit eea63cb5c9
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 29 additions and 8 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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)))