Skip to content

fix: Time zone data not set in ParseInstallation #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 16, 2023
6 changes: 6 additions & 0 deletions packages/dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [3.1.10](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.9...dart-3.1.10) (2023-01-16)

### Bug Fixes

* Time zone data not set in `ParseInstallation` ([#96](https://github.com/parse-community/Parse-SDK-Flutter/issues/96))

## [3.1.9](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.8...dart-3.1.9) (2022-12-25)

### Bug Fixes
Expand Down
2 changes: 2 additions & 0 deletions packages/dart/lib/parse_server_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:path/path.dart' as path;
import 'package:sembast/sembast.dart';
import 'package:sembast/sembast_io.dart';
import 'package:sembast_web/sembast_web.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:uuid/uuid.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:xxtea/xxtea.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/dart/lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of flutter_parse_sdk;

// Library
const String keySdkVersion = '3.1.9';
const String keySdkVersion = '3.1.10';
const String keyLibraryName = 'Flutter Parse SDK';

// End Points
Expand Down
19 changes: 19 additions & 0 deletions packages/dart/lib/src/objects/parse_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ParseInstallation extends ParseObject {
set<String?>(keyLocaleIdentifier, ParseCoreData().locale);

//Timezone
set<String>(keyTimeZone, _getNameLocalTimeZone());

//App info
set<String?>(keyAppName, ParseCoreData().appName);
Expand All @@ -93,6 +94,24 @@ class ParseInstallation extends ParseObject {
set<String>(keyParseVersion, keySdkVersion);
}

String _getNameLocalTimeZone() {
tz.initializeTimeZones();
var locations = tz.timeZoneDatabase.locations;

int milliseconds = DateTime.now().timeZoneOffset.inMilliseconds;
String name = "";

locations.forEach((key, value) {
for (var element in value.zones) {
if (element.offset == milliseconds) {
name = value.name;
break;
}
}
});
return name;
}

@override
Future<ParseResponse> create({bool allowCustomObjectId = false}) async {
final bool isCurrent = await ParseInstallation.isCurrent(this);
Expand Down
3 changes: 2 additions & 1 deletion packages/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk
description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
version: 3.1.9
version: 3.1.10
homepage: https://github.com/parse-community/Parse-SDK-Flutter

environment:
Expand All @@ -22,6 +22,7 @@ dependencies:
meta: ^1.7.0
path: ^1.8.1
mime_type: ^1.0.0
timezone: ^0.9.0

dev_dependencies:
lints: ^1.0.1
Expand Down
30 changes: 30 additions & 0 deletions packages/dart/test/parse_installation_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:parse_server_sdk/parse_server_sdk.dart';
import 'package:test/test.dart';

void main() {
test('should return true for exist TimeZone.', () async {
// arrange
await Parse().initialize(
'appId',
'https://example.com',
debug: true,
// to prevent automatic detection
fileDirectory: 'someDirectory',
// to prevent automatic detection
appName: 'appName',
// to prevent automatic detection
appPackageName: 'somePackageName',
// to prevent automatic detection
appVersion: 'someAppVersion',
);

// act
final ParseInstallation installation =
await ParseInstallation.currentInstallation();

dynamic actualHasTimeZoneResult = installation.containsKey(keyTimeZone);

// assert
expect(actualHasTimeZoneResult, true);
});
}