mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Properly handle timezones
This should (hopefully 🤞) take care of problems saving entries with timezone
information.
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (C) wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wger Workout Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/helpers/date.dart';
|
||||
|
||||
void main() {
|
||||
group('getDateTimeFromDateAndTime', () {
|
||||
test('should correctly generate a DateTime', () {
|
||||
expect(
|
||||
getDateTimeFromDateAndTime('2025-05-16', '17:02'),
|
||||
DateTime(2025, 5, 16, 17, 2),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -57,13 +57,20 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('dateToIsoWithTimezone', () {
|
||||
group('Iso8601 and timezones', () {
|
||||
test('should format DateTime to a string with timezone', () {
|
||||
expect(
|
||||
dateToUtcIso8601(DateTime.parse('2025-05-16T18:15:00+02:00')),
|
||||
'2025-05-16T16:15:00.000Z',
|
||||
);
|
||||
});
|
||||
|
||||
test('should convert an iso8601 datetime to local', () {
|
||||
expect(
|
||||
utcIso8601ToLocalDate('2025-11-18T18:15:00+08:00'),
|
||||
DateTime.parse('2025-11-18T11:15:00.000'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('stringToTime', () {
|
||||
|
||||
@@ -23,13 +23,13 @@ void main() {
|
||||
group('fetchPost', () {
|
||||
test('Test that the weight entries are correctly converted to json', () {
|
||||
expect(
|
||||
WeightEntry(id: 1, weight: 80, date: DateTime(2020, 12, 31, 12, 34)).toJson(),
|
||||
{'id': 1, 'weight': '80', 'date': '2020-12-31T12:34:00.000'},
|
||||
WeightEntry(id: 1, weight: 80, date: DateTime.utc(2020, 12, 31, 12, 34)).toJson(),
|
||||
{'id': 1, 'weight': '80', 'date': '2020-12-31T12:34:00.000Z'},
|
||||
);
|
||||
|
||||
expect(
|
||||
WeightEntry(id: 2, weight: 70.2, date: DateTime(2020, 12, 01)).toJson(),
|
||||
{'id': 2, 'weight': '70.2', 'date': '2020-12-01T00:00:00.000'},
|
||||
WeightEntry(id: 2, weight: 70.2, date: DateTime.utc(2020, 12, 01)).toJson(),
|
||||
{'id': 2, 'weight': '70.2', 'date': '2020-12-01T00:00:00.000Z'},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -53,12 +53,11 @@ void main() {
|
||||
group('model', () {
|
||||
test('Test the individual values from the model', () {
|
||||
WeightEntry weightModel;
|
||||
//_weightModel = WeightEntry();
|
||||
weightModel = WeightEntry(id: 1, weight: 80, date: DateTime(2020, 10, 01));
|
||||
weightModel = WeightEntry(id: 1, weight: 80, date: DateTime.utc(2020, 10, 01));
|
||||
|
||||
expect(weightModel.id, 1);
|
||||
expect(weightModel.weight, 80);
|
||||
expect(weightModel.date, DateTime(2020, 10, 01));
|
||||
expect(weightModel.date, DateTime.utc(2020, 10, 01));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,14 +72,14 @@ void main() {
|
||||
when(mockBaseProvider.makeUrl(any, query: anyNamed('query'))).thenReturn(uri);
|
||||
when(
|
||||
mockBaseProvider.post(
|
||||
{'id': null, 'weight': '80', 'date': '2021-01-01T00:00:00.000'},
|
||||
{'id': null, 'weight': '80', 'date': '2021-01-01T00:00:00.000Z'},
|
||||
uri,
|
||||
),
|
||||
).thenAnswer((_) => Future.value({'id': 25, 'date': '2021-01-01', 'weight': '80'}));
|
||||
|
||||
// Act
|
||||
final BodyWeightProvider provider = BodyWeightProvider(mockBaseProvider);
|
||||
final WeightEntry weightEntry = WeightEntry(date: DateTime(2021, 1, 1), weight: 80);
|
||||
final WeightEntry weightEntry = WeightEntry(date: DateTime.utc(2021, 1, 1), weight: 80);
|
||||
final WeightEntry weightEntryNew = await provider.addEntry(weightEntry);
|
||||
|
||||
// Assert
|
||||
|
||||
Reference in New Issue
Block a user